Test for KepiView producing an OrderedCollection if there are multiple items.

URL that lists all users changed to "/users" for simplicity.
2019-08-17
Marnanel Thurman 2019-05-14 23:01:18 +01:00
rodzic ad3670549d
commit 40dd00697a
2 zmienionych plików z 61 dodań i 4 usunięć

Wyświetl plik

@ -6,7 +6,7 @@ urlpatterns = [
path('obj/<id>', ActivityObjectView.as_view(),
{ 'f_type': 'Activity',
}),
path('thing-users', ThingUserCollection.as_view()),
path('users', ThingUserCollection.as_view()),
path('users/<name>', ThingUserView.as_view()),
path('users/<name>/followers', ThingUserFollowersView.as_view()),
path('users/<name>/following', ThingUserFollowingView.as_view()),

Wyświetl plik

@ -6,7 +6,19 @@ import json
logger = logging.getLogger(name='django_kepi')
class TestSingleKepiView(TestCase):
def _response_to_dict(response):
result = json.loads(response.content.decode('utf-8'))
# @context is often huge, and is irrelevant for testing here
if '@context' in result:
del result['@context']
logger.info('Response: %s', result)
return result
class TestKepiView(TestCase):
def test_single_kepi_view(self):
@ -18,8 +30,7 @@ class TestSingleKepiView(TestCase):
c = Client()
response = c.get('/users/alice')
logger.info('Response: %s', response.content.decode('utf-8'))
result = json.loads(response.content.decode('utf-8'))
result = _response_to_dict(response)
self.assertDictEqual(
result,
@ -29,3 +40,49 @@ class TestSingleKepiView(TestCase):
'id': 'https://altair.example.com/users/alice',
},
)
def test_multiple_kepi_view(self):
alice = ThingUser(
name = 'alice',
favourite_colour = 'magenta',
)
alice.save()
bob = ThingUser(
name = 'bob',
favourite_colour = 'cyan',
)
bob.save()
c = Client()
response = c.get('/users')
result = _response_to_dict(response)
self.assertDictEqual(
result,
{
"first": "http://testserver/users?page=1",
"id": "http://testserver/users",
"totalItems": 2,
"type": "OrderedCollection"
}
)
response = c.get('/users?page=1')
result = _response_to_dict(response)
self.assertDictEqual(
result,
{
'id': 'http://testserver/users?page=1',
'orderedItems': [
{'favourite_colour': 'magenta', 'id': 'https://altair.example.com/users/alice', 'name': 'alice'},
{'favourite_colour': 'cyan', 'id': 'https://altair.example.com/users/bob', 'name': 'bob'}
],
'partOf': 'http://testserver/users',
'totalItems': 2,
'type': 'OrderedCollectionPage',
}
)