Created
March 26, 2020 06:32
-
-
Save Olegblow/535d5bfd46810abaa9d949cb0213297b to your computer and use it in GitHub Desktop.
code pytest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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