diff options
author | 2018-08-16 22:44:24 +0200 | |
---|---|---|
committer | 2018-08-16 22:44:24 +0200 | |
commit | a804d855e649a8148cd215bbbe3a47f9d7e9164a (patch) | |
tree | 79cd0fdc83b2d9231d8f5f3030011ea3952febb9 /api/tests/test_documentation_links.py | |
parent | Make test user superuser. (diff) |
Add support for `create` & `destroy`.
Diffstat (limited to 'api/tests/test_documentation_links.py')
-rw-r--r-- | api/tests/test_documentation_links.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/api/tests/test_documentation_links.py b/api/tests/test_documentation_links.py index c3ffe5bb..e560a2fd 100644 --- a/api/tests/test_documentation_links.py +++ b/api/tests/test_documentation_links.py @@ -21,6 +21,19 @@ class UnauthedDocumentationLinkAPITests(APISubdomainTestCase): self.assertEqual(response.status_code, 401) + def test_create_returns_401(self): + url = reverse('bot:documentationlink-list', host='api') + response = self.client.post(url, data={'hi': 'there'}) + + self.assertEqual(response.status_code, 401) + + def test_delete_returns_401(self): + url = reverse('bot:documentationlink-detail', args=('whatever',), host='api') + response = self.client.delete(url) + + self.assertEqual(response.status_code, 401) + + class EmptyDatabaseDocumentationLinkAPITests(APISubdomainTestCase): def test_detail_lookup_returns_404(self): url = reverse('bot:documentationlink-detail', args=('whatever',), host='api') @@ -35,6 +48,12 @@ class EmptyDatabaseDocumentationLinkAPITests(APISubdomainTestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), []) + def test_delete_returns_404(self): + url = reverse('bot:documentationlink-detail', args=('whatever',), host='api') + response = self.client.delete(url) + + self.assertEqual(response.status_code, 404) + class DetailLookupDocumentationLinkAPITests(APISubdomainTestCase): @classmethod @@ -70,3 +89,73 @@ class DetailLookupDocumentationLinkAPITests(APISubdomainTestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), [self.doc_json]) + + def test_create_invalid_body_returns_400(self): + url = reverse('bot:documentationlink-list', host='api') + response = self.client.post(url, data={'i': 'am', 'totally': 'valid'}) + + self.assertEqual(response.status_code, 400) + + def test_create_invalid_url_returns_400(self): + body = { + 'package': 'example', + 'base_url': 'https://example.com', + 'inventory_url': 'totally an url' + } + + url = reverse('bot:documentationlink-list', host='api') + response = self.client.post(url, data=body) + + self.assertEqual(response.status_code, 400) + + +class DocumentationLinkCreationTests(APISubdomainTestCase): + def setUp(self): + super().setUp() + + self.body = { + 'package': 'example', + 'base_url': 'https://example.com', + 'inventory_url': 'https://docs.example.com' + } + + url = reverse('bot:documentationlink-list', host='api') + response = self.client.post(url, data=self.body) + + self.assertEqual(response.status_code, 201) + + def test_package_in_full_list(self): + url = reverse('bot:documentationlink-list', host='api') + response = self.client.get(url) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json(), [self.body]) + + def test_detail_lookup_works_with_package(self): + url = reverse('bot:documentationlink-detail', args=(self.body['package'],), host='api') + response = self.client.get(url) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json(), self.body) + + +class DocumentationLinkDeletionTests(APISubdomainTestCase): + @classmethod + def setUpTestData(cls): + cls.doc_link = DocumentationLink.objects.create( + package='example', + base_url='https://example.com', + inventory_url='https://docs.example.com' + ) + + def test_unknown_package_returns_404(self): + url = reverse('bot:documentationlink-detail', args=('whatever',), host='api') + response = self.client.delete(url) + + self.assertEqual(response.status_code, 404) + + def test_delete_known_package_returns_204(self): + url = reverse('bot:documentationlink-detail', args=(self.doc_link.package,), host='api') + response = self.client.delete(url) + + self.assertEqual(response.status_code, 204) |