Add tests for documentation code snippets

We check for Python and JS code (they have the same syntax
for the action list), and shell code snippets, ensuring that
the action is correct for the nested routes.
This commit is contained in:
Aleksey Zhukov 2017-05-23 17:18:13 +03:00
parent dca59af6f0
commit 3960328a29
No known key found for this signature in database
GPG Key ID: E1C3A2857EFC7C66

View File

@ -41,3 +41,15 @@ class TestRecursiveUrlViewSets(TestCase):
re.search(header_re.format(level=3, path=subpath, title=method), self.content),
'unable to find documentation section for {}'.format(subpath)
)
action_code = 'action = [{}, "retrieve_alt", "{}"]'.format(
", ".join('"{}"'.format(r) for r in route),
method
)
self.assertTrue(
action_code in self.content.replace('"', '"'),
'unable to find code snippet for {}'.format(subpath)
)
self.assertTrue(
'$ coreapi action {} retrieve_alt {}'.format(' '.join(route), method) in self.content,
'unable to find shell code snippet for {}'.format(subpath)
)