From bdccfaf74d22dad041e79510570c11d1ee582405 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Tue, 30 Jul 2019 17:32:11 +0300 Subject: [PATCH] Tests: actually use new fixture names --- tests/unit/views/test_api_view.py | 12 ++++---- tests/unit/views/test_model_view.py | 48 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/tests/unit/views/test_api_view.py b/tests/unit/views/test_api_view.py index 3245b67..cc549fc 100644 --- a/tests/unit/views/test_api_view.py +++ b/tests/unit/views/test_api_view.py @@ -39,7 +39,7 @@ async def http_client(http_client_maker): routes=[('/items', ItemsView)]) -async def test_get(api_views_http_client): +async def test_get(http_client): sent_args = { 'count': '222' } @@ -47,7 +47,7 @@ async def test_get(api_views_http_client): 'count': 222 } - response = await api_views_http_client.get('/items', params=sent_args) + response = await http_client.get('/items', params=sent_args) assert response.status == 200 @@ -57,7 +57,7 @@ async def test_get(api_views_http_client): assert expected_args == query -async def test_post_body(api_views_http_client): +async def test_post_body(http_client): sent_data = { 'name': 'Risus Fusce', 'info': 'Egestas Lorem Sit Fringilla', @@ -69,7 +69,7 @@ async def test_post_body(api_views_http_client): 'count': 22, } - response = await api_views_http_client.post('/items', json=sent_data) + response = await http_client.post('/items', json=sent_data) assert response.status == 200 @@ -79,7 +79,7 @@ async def test_post_body(api_views_http_client): assert expected_data == body -async def test_post_query(api_views_http_client): +async def test_post_query(http_client): sent_data = { 'count': '22', } @@ -87,7 +87,7 @@ async def test_post_query(api_views_http_client): 'count': 22, } - response = await api_views_http_client.post('/items', params=sent_data) + response = await http_client.post('/items', params=sent_data) assert response.status == 200 diff --git a/tests/unit/views/test_model_view.py b/tests/unit/views/test_model_view.py index 0c5aefb..67b6668 100644 --- a/tests/unit/views/test_model_view.py +++ b/tests/unit/views/test_model_view.py @@ -7,8 +7,6 @@ from colibris import persist from colibris.views.generic import ListCreateModelView, RetrieveUpdateDestroyModelView -from ..fixtures import database_maker, http_client_maker - class Item(persist.Model): name = persist.CharField() @@ -54,20 +52,20 @@ async def http_client(http_client_maker): class TestList: - async def test_get_items(self, database, model_view_http_client): - response = await model_view_http_client.get('/items') + async def test_get_items(self, database, http_client): + response = await http_client.get('/items') assert response.status == 200 data = await response.json() assert isinstance(data, list) - async def test_get_pagination_default_page_and_size(self, database, model_view_http_client): + async def test_get_pagination_default_page_and_size(self, database, http_client): item__name = 'Ligula Egestas Fermentum' item_info = 'Ridiculus Fermentum Quam Porta' Item.create(name=item__name, info=item_info) - response = await model_view_http_client.get('/paginated-items') + response = await http_client.get('/paginated-items') assert response.status == 200 data = await response.json() @@ -78,7 +76,7 @@ async def test_get_pagination_default_page_and_size(self, database, model_view_h assert 'page' in data assert 'page_size' in data - async def test_get_pagination_different_page(self, database, model_view_http_client): + async def test_get_pagination_different_page(self, database, http_client): item_info = 'Ridiculus Fermentum Quam Porta' first_item_name = 'Ligula Egestas Fermentum' second_item_name = 'Euismod Ipsum Vulputate' @@ -88,7 +86,7 @@ async def test_get_pagination_different_page(self, database, model_view_http_cli Item.create(name=second_item_name, info=item_info) Item.create(name=third_item_name, info=item_info) - response = await model_view_http_client.get('/paginated-items', params={'page_size': 1, 'page': 1}) + response = await http_client.get('/paginated-items', params={'page_size': 1, 'page': 1}) assert response.status == 200 data = await response.json() @@ -98,28 +96,28 @@ async def test_get_pagination_different_page(self, database, model_view_http_cli assert data['page_size'] == 1 assert data['results'][0]['name'] == third_item_name - response = await model_view_http_client.get('/paginated-items', params={'page_size': 1, 'page': 2}) + response = await http_client.get('/paginated-items', params={'page_size': 1, 'page': 2}) assert response.status == 200 data = await response.json() assert data['results'][0]['name'] == second_item_name - response = await model_view_http_client.get('/paginated-items', params={'page_size': 1, 'page': 3}) + response = await http_client.get('/paginated-items', params={'page_size': 1, 'page': 3}) assert response.status == 200 data = await response.json() assert data['results'][0]['name'] == first_item_name - response = await model_view_http_client.get('/paginated-items', params={'page_size': 1, 'page': 4}) + response = await http_client.get('/paginated-items', params={'page_size': 1, 'page': 4}) assert response.status == 200 data = await response.json() assert data['results'] == [] class TestCreate: - async def test_create_item(self, database, model_view_http_client): + async def test_create_item(self, database, http_client): item_name = 'Commodo Nibh' item_info = 'Cras Lorem Purus Etiam Venenatis' - response = await model_view_http_client.post('/items', json={'name': item_name, 'info': item_info}) + response = await http_client.post('/items', json={'name': item_name, 'info': item_info}) assert response.status == 201 @@ -127,8 +125,8 @@ async def test_create_item(self, database, model_view_http_client): assert item.name == item_name - async def test_create_item_validation(self, database, model_view_http_client): - response = await model_view_http_client.post('/items') + async def test_create_item_validation(self, database, http_client): + response = await http_client.post('/items') assert response.status == 400 data = await response.json() @@ -137,14 +135,14 @@ async def test_create_item_validation(self, database, model_view_http_client): class TestUpdate: - async def test_update_item(self, database, model_view_http_client): + async def test_update_item(self, database, http_client): item_initial_name = 'Ligula Egestas Fermentum' item_updated_name = 'Cursus Inceptos' item_info = 'Ridiculus Fermentum Quam Porta' item = Item.create(name=item_initial_name, info=item_info) - response = await model_view_http_client.patch('/items/{}'.format(item.id), json={'name': item_updated_name}) + response = await http_client.patch('/items/{}'.format(item.id), json={'name': item_updated_name}) assert response.status == 200 @@ -152,40 +150,40 @@ async def test_update_item(self, database, model_view_http_client): assert item.id == updated_item.id - async def test_update_item_validation(self, database, model_view_http_client): + async def test_update_item_validation(self, database, http_client): item_initial_name = 'Nibh Lorem Amet Aenean' item_info = 'Ridiculus Fermentum Quam Porta' item = Item.create(name=item_initial_name, info=item_info) - response = await model_view_http_client.patch('/items/{}'.format(item.id), json={'name': None}) + response = await http_client.patch('/items/{}'.format(item.id), json={'name': None}) assert response.status == 400 data = await response.json() assert 'name' in data['details'] - async def test_update_item_not_found(self, database, model_view_http_client): - response = await model_view_http_client.patch('/items/11011', json={'name': 'Egestas Fringilla'}) + async def test_update_item_not_found(self, database, http_client): + response = await http_client.patch('/items/11011', json={'name': 'Egestas Fringilla'}) assert response.status == 404 class TestDestroy: - async def test_delete_item(self, database, model_view_http_client): + async def test_delete_item(self, database, http_client): item_name = 'Sit Lorem' item_info = 'Ridiculus Fermentum Quam Porta' item = Item.create(name=item_name, info=item_info) - response = await model_view_http_client.delete('/items/{}'.format(item.id)) + response = await http_client.delete('/items/{}'.format(item.id)) assert response.status == 204 items = Item.select().where(Item.name == item_name) assert items.count() == 0 - async def test_delete_item_not_found(self, database, model_view_http_client): - response = await model_view_http_client.delete('/items/111111') + async def test_delete_item_not_found(self, database, http_client): + response = await http_client.delete('/items/111111') assert response.status == 404