kopia lustrzana https://gitlab.com/marnanel/chapeau
Test for KepiView producing an OrderedCollection if there are multiple items.
URL that lists all users changed to "/users" for simplicity.2019-08-17
rodzic
ad3670549d
commit
40dd00697a
|
@ -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()),
|
||||
|
|
|
@ -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',
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue