Skip to content
Snippets Groups Projects
Commit 1e8425e5 authored by Mark Skipper's avatar Mark Skipper
Browse files

Switch rest_api tests to pytest tests

parent 9491edee
No related branches found
No related tags found
No related merge requests found
from __future__ import unicode_literals, absolute_import
from django.test import TestCase
import pytest
from rest_framework.test import APIRequestFactory
from data_layer.tests.factories import ItemFactory
......@@ -8,24 +9,24 @@ from data_layer.tests.factories import ItemFactory
from rest_api.views import ItemList
class ItemViewTests(TestCase):
def get(self, view_class, url):
view = view_class.as_view()
request = APIRequestFactory().get(url)
return view(request)
def get(view_class, url):
view = view_class.as_view()
request = APIRequestFactory().get(url)
return view(request)
def test_get_items_returns_empty_if_no_items(self):
response = self.get(ItemList, '/items/')
self.assertEqual(response.data, [])
@pytest.mark.django_db
def test_get_items_returns_empty_if_no_items():
response = get(ItemList, '/items/')
assert response.data == []
def test_get_items_returns_all_items(self):
item = ItemFactory()
@pytest.mark.django_db
def test_get_items_returns_all_items():
item = ItemFactory()
payload = self.get(ItemList, '/items/').data
payload = get(ItemList, '/items/').data
self.assertEqual(len(payload), 1)
self.assertEqual(payload[0]['body'], item.body)
# I don't much care for this test.
# It's testing too much of the stack, and its messy because the payload
# isn't the same kind data strcture even as ItemSerializer(item).data
assert len(payload) == 1
assert payload[0]['body'] == item.body
# I don't much care for this test.
# It's testing too much of the stack, and its messy because the payload
# isn't the same kind data strcture even as ItemSerializer(item).data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment