2019-05-05 01:43:14 +00:00
|
|
|
from django.test import TestCase, Client
|
2019-05-27 20:18:28 +00:00
|
|
|
from . import *
|
2019-05-05 01:43:14 +00:00
|
|
|
import logging
|
2019-05-14 21:48:18 +00:00
|
|
|
import json
|
2019-05-05 01:43:14 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(name='django_kepi')
|
|
|
|
|
2019-05-14 22:01:18 +00:00
|
|
|
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):
|
2019-05-05 01:43:14 +00:00
|
|
|
|
2019-05-14 21:48:18 +00:00
|
|
|
def test_single_kepi_view(self):
|
2019-05-05 01:43:14 +00:00
|
|
|
|
2019-05-27 20:18:28 +00:00
|
|
|
alice = create_person('alice')
|
2019-05-05 01:43:14 +00:00
|
|
|
|
|
|
|
c = Client()
|
2019-05-14 21:48:18 +00:00
|
|
|
response = c.get('/users/alice')
|
2019-05-14 22:01:18 +00:00
|
|
|
result = _response_to_dict(response)
|
2019-05-14 21:48:18 +00:00
|
|
|
|
|
|
|
self.assertDictEqual(
|
|
|
|
result,
|
|
|
|
{
|
|
|
|
'name': 'alice',
|
|
|
|
'id': 'https://altair.example.com/users/alice',
|
2019-05-21 23:34:30 +00:00
|
|
|
'type': 'Person',
|
2019-05-14 21:48:18 +00:00
|
|
|
},
|
|
|
|
)
|
2019-05-14 22:01:18 +00:00
|
|
|
|
|
|
|
def test_multiple_kepi_view(self):
|
|
|
|
|
2019-05-27 20:18:28 +00:00
|
|
|
alice = create_person('alice')
|
|
|
|
bob = create_person('bob')
|
2019-05-14 22:01:18 +00:00
|
|
|
|
|
|
|
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': [
|
2019-05-21 23:34:30 +00:00
|
|
|
{ 'id': 'https://altair.example.com/users/alice',
|
|
|
|
'name': 'alice',
|
|
|
|
'type': 'Person',
|
|
|
|
},
|
|
|
|
{ 'id': 'https://altair.example.com/users/bob',
|
|
|
|
'name': 'bob',
|
|
|
|
'type': 'Person',
|
|
|
|
}
|
2019-05-14 22:01:18 +00:00
|
|
|
],
|
|
|
|
'partOf': 'http://testserver/users',
|
|
|
|
'totalItems': 2,
|
|
|
|
'type': 'OrderedCollectionPage',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|