Как опубликовать запись с помощью pytest-django?
Я хочу написать тесты для проекта, используя библиотеку pytest-django.
У меня есть модель "Context" с полями "name"(Charfield) и "description" (Charfield). Я хочу создать тестовую запись через панель администратора Django, но по какой-то причине не могу (
class TestViewContext:
def test_post_view_get(self, admin_client):
name = 'Sometext'
description = 'description'
data={'name': name, 'description': description}
response = admin_client.post(
'/admin/book/context/add/',
data=data
)
post = Context.objects.filter(name=name, description=description).first()
assert post is not None, 'Check new post'
Ответ:
self = <book.tests.test_forms.TestViewContext object at 0x7f2934dfb460>, admin_client = <django.test.client.Client object at 0x7f2934c65fd0>
def test_post_view_get(self, admin_client):
name = 'Sometext'
description = 'description'
data={'name': name, 'description': description}
response = admin_client.post(
'/admin/book/context/add/',
data=data
)
post = Context.objects.filter(name=name, description=description).first()
> assert post is not None, 'Check new post'
E AssertionError: Check new post
E assert None is not None