Форум сайта python.su
Здравствуйте! Помогите пожалуйста с тестированием модели.
В БД есть один объект, тестирую я его следующим образом:
tests.py:
from django.test import TestCase
from django.db.models import get_model
from django.test.client import Client
from django.core.urlresolvers import reverse
Info = get_model('contact_info', 'my_info')
class My_InfoModelTests(TestCase):
def test_str(self):
""" Info model tests """
info = Info(name='Oleg', last_name='Petrov')
self.assertEqual(str(info), 'Oleg Petrov')
def test_correct_template_render(self):
""" Test that correct template rendered """
client = Client()
response = client.get(reverse('contact_info.views.my_info_view'))
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<!DOCTYPE html>')
self.assertTemplateUsed(response, 'contact_info/myview.html')
self.assertEqual(response['Content-Type'],'text/html; charset=utf-8')
def test_empty_My_info(self):
if len(Info.objects.all()) == 0:
print "There is no one object to test"
Офлайн
Info.objects.all().count()
Офлайн
FishHook
Info.objects.all().count()
Info.objects.count()
megolomanпроверять вашу бизнес логику
что проверять
Отредактировано ilnur (Дек. 24, 2015 12:55:32)
Офлайн