Skip to content

Commit

Permalink
Tests: actually use new fixture names
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrisan committed Jul 30, 2019
1 parent ef486c0 commit bdccfaf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
12 changes: 6 additions & 6 deletions tests/unit/views/test_api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ 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'
}
expected_args = {
'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

Expand All @@ -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',
Expand All @@ -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

Expand All @@ -79,15 +79,15 @@ 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',
}
expected_data = {
'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

Expand Down
48 changes: 23 additions & 25 deletions tests/unit/views/test_model_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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'
Expand All @@ -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()
Expand All @@ -98,37 +96,37 @@ 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

item = Item.select().where(Item.name == item_name).get()

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()
Expand All @@ -137,55 +135,55 @@ 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

updated_item = Item.select().where(Item.name == item_updated_name).get()

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

0 comments on commit bdccfaf

Please sign in to comment.