Initial /avilable API view and tests

This commit is contained in:
Neil Martinsen-Burrell 2022-10-27 13:15:22 -05:00
parent 5c105f1861
commit 01553a4d91
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
6 changed files with 58 additions and 0 deletions

View 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)