Skip to content

Commit ed2458f

Browse files
committed
Tests for the restapi.
- Legacy-Id: 8745
1 parent 770b36d commit ed2458f

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

ietf/utils/tests_restapi.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from __future__ import print_function
2+
3+
import debug
4+
debug.debug = True
5+
6+
from tastypie.test import ResourceTestCase
7+
from ietf.utils.test_data import make_test_data
8+
9+
10+
11+
12+
class RestApi(ResourceTestCase):
13+
def list_recursively(self, resource, format):
14+
"""
15+
Recurse down all the app trees, retrieving all the data available. This ensures
16+
that all the data represented in our test fixtures can be retrieved without raising
17+
any exceptions.
18+
"""
19+
# print(' fetching %s' % resource)
20+
r = self.api_client.get(resource, format=format)
21+
if format == 'json':
22+
self.assertValidJSONResponse(r)
23+
elif format == 'xml':
24+
self.assertValidXMLResponse(r)
25+
else:
26+
raise Exception("Unknown format found when testing the RestApi: %s" % (format, ))
27+
data = self.deserialize(r)
28+
for name in data:
29+
if 'list_endpoint' in data[name]:
30+
resource = data[name]['list_endpoint']
31+
self.list_recursively(resource, format)
32+
33+
def test_json_api_explore(self):
34+
make_test_data()
35+
self.list_recursively('/api/', format='json')
36+
37+
def test_xml_api_explore(self):
38+
self.assertValidXMLResponse(self.api_client.get('/api/doc/', format='xml'))
39+
40+
def test_json_doc_document(self):
41+
"""
42+
Retrieve the test-data doc_document instances, and verify that some of the expected
43+
test-data documents are included. There's assumption here that we don't have more
44+
than 100 documents in the test-data (the current count is 10)
45+
"""
46+
make_test_data()
47+
r = self.api_client.get('/api/doc/document/', format='json', limit=100)
48+
doclist = self.deserialize(r)["objects"]
49+
docs = dict( (doc["name"], doc) for doc in doclist )
50+
for name in (
51+
"charter-ietf-mars",
52+
"charter-ietf-ames",
53+
"draft-ietf-mars-test",
54+
"conflict-review-imaginary-irtf-submission",
55+
"status-change-imaginary-mid-review",
56+
"draft-was-never-issued",
57+
):
58+
self.assertIn(name, docs)
59+
60+
def test_json_doc_relationships(self):
61+
"""
62+
Follow all the relations given in the test documents, this testing that representation
63+
of relationships give URLs which are handled without raising exceptions.
64+
"""
65+
make_test_data()
66+
r = self.api_client.get('/api/doc/document/', format='json')
67+
doclist = self.deserialize(r)["objects"]
68+
for doc in doclist:
69+
for key in doc:
70+
value = doc[key]
71+
if isinstance(value, basestring) and value.startswith('/api/'):
72+
self.api_client.get(value, format='json')
73+

0 commit comments

Comments
 (0)