mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-21 20:09:23 +02:00
Initial /avilable API view and tests
This commit is contained in:
parent
5c105f1861
commit
01553a4d91
6 changed files with 58 additions and 0 deletions
39
src/api/tests/test_available.py
Normal file
39
src/api/tests/test_available.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
"""Test the available domain API."""
|
||||
|
||||
import json
|
||||
|
||||
from django.test import client, TestCase, RequestFactory
|
||||
|
||||
from ..views import available
|
||||
|
||||
class AvailableViewTest(TestCase):
|
||||
|
||||
"""Test that the view function works as expected."""
|
||||
|
||||
def setUp(self):
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_view_function(self):
|
||||
request = self.factory.get("available/test.gov")
|
||||
response = available(request, domain="test.gov")
|
||||
# has the right text in it
|
||||
self.assertContains(response, "available")
|
||||
# can be parsed as JSON
|
||||
response_object = json.loads(response.content)
|
||||
self.assertIn("available", response_object)
|
||||
|
||||
|
||||
class AvailableAPITest(TestCase):
|
||||
|
||||
"""Test that the API can be called as expected."""
|
||||
|
||||
def test_available_get(self):
|
||||
response = self.client.get("/available/nonsense")
|
||||
self.assertContains(response, "available")
|
||||
response_object = json.loads(response.content)
|
||||
self.assertIn("available", response_object)
|
||||
|
||||
def test_available_post(self):
|
||||
"""Cannot post to the /available/ API endpoint."""
|
||||
response = self.client.post("/available/nonsense")
|
||||
self.assertEqual(response.status_code, 405)
|
Loading…
Add table
Add a link
Reference in a new issue