Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
code pytest
@pytest.mark.django_db
def test_call_create_object():
"""Тест celery задачи."""
task = call_create_object.delay()
task.get()
assert task.state == "SUCCESS"
@pytest.fixture(scope='module')
def factory():
return RequestFactory()
@pytest.mark.django_db
@pytest.mark.parametrize(
'parameters', (
('url1', View1),
('url2', View2List),
('url3', View2List),
)
)
def test_list_views(parameters, factory):
"""Тест GET запросов по урлам."""
url, view = parameters
path = reverse_lazy(url)
request = factory.get(url)
request.user = AnonymousUser()
response = Main.as_view()(request)
assert resolve(path).func.view_class == view
assert resolve(path).view_name == url
assert response.status_code == HTTPStatus.OK
@pytest.mark.django_db
class TestModels:
def test_artists(self):
artist = Artist.objects.create(
full_name='актер',
nickname='nickname1',
gender=1,
birthday='1998-10-10',
about='about about about test'
)
assert artist.full_name == 'актер'
assert artist.gender == 1
assert artist.birthday == '1998-10-10'
assert 'about test' in artist.about
assert str(artist) == artist.full_name
def test_movie(self):
movie = Movie.objects.create(
name='тест кино',
relise='2020-01-11',
about='о тестлвом кино',
)
assert movie.about == 'о тестлвом кино'
assert movie.name == 'тест кино'
assert movie.relise == '2020-01-11'
assert str(movie) == movie.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.