class PostModelTest(TestCase):
@classmethod
def setUpTestData(cls):
user = User.objects.create_user(username='testuser', password='testpassword')
Post.objects.create(title='Test Post', slug='test-post', author=user, body='This is a test post',
publish=timezone.now(), status='published')
def test_title_max_length(self):
post = Post.objects.get(id=1)
max_length = post._meta.get_field('title').max_length
self.assertEqual(max_length, 250)
class CommentModelTest(TestCase):
@classmethod
def setUpTestData(cls):
user = User.objects.create_user(username='testuser', password='testpassword')
post = Post.objects.create(title='Test Post', slug='test-post', author=user, body='This is a test post',
publish=timezone.now(), status='published')
Comment.objects.create(
post=post,
name='John Doe',
email='johndoe@example.com',
body='Test comment',
created=timezone.now(),
updated=timezone.now(),
active=True
)
def test_comment_str_representation(self):
comment = Comment.objects.get(id=1)
expected_str = 'Comment by John Doe on Test Post'
self.assertEqual(str(comment), expected_str)
Ошибка raise self.model.DoesNotExist(
blog.models.Post.DoesNotExist: Post matching query does not exist.
Выполняю в Docker