mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-08 20:23:34 +02:00
API is only available to logged-in users
This commit is contained in:
parent
01553a4d91
commit
7e02661416
2 changed files with 13 additions and 2 deletions
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.test import client, TestCase, RequestFactory
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase, RequestFactory
|
||||||
|
|
||||||
from ..views import available
|
from ..views import available
|
||||||
|
|
||||||
|
@ -11,10 +12,12 @@ class AvailableViewTest(TestCase):
|
||||||
"""Test that the view function works as expected."""
|
"""Test that the view function works as expected."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.user = get_user_model().objects.create(username="username")
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
|
|
||||||
def test_view_function(self):
|
def test_view_function(self):
|
||||||
request = self.factory.get("available/test.gov")
|
request = self.factory.get("/available/test.gov")
|
||||||
|
request.user = self.user
|
||||||
response = available(request, domain="test.gov")
|
response = available(request, domain="test.gov")
|
||||||
# has the right text in it
|
# has the right text in it
|
||||||
self.assertContains(response, "available")
|
self.assertContains(response, "available")
|
||||||
|
@ -27,7 +30,11 @@ class AvailableAPITest(TestCase):
|
||||||
|
|
||||||
"""Test that the API can be called as expected."""
|
"""Test that the API can be called as expected."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.user = get_user_model().objects.create(username="username")
|
||||||
|
|
||||||
def test_available_get(self):
|
def test_available_get(self):
|
||||||
|
self.client.force_login(self.user)
|
||||||
response = self.client.get("/available/nonsense")
|
response = self.client.get("/available/nonsense")
|
||||||
self.assertContains(response, "available")
|
self.assertContains(response, "available")
|
||||||
response_object = json.loads(response.content)
|
response_object = json.loads(response.content)
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
"""Internal API views"""
|
"""Internal API views"""
|
||||||
|
|
||||||
|
|
||||||
from django.views.decorators.http import require_http_methods
|
from django.views.decorators.http import require_http_methods
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
@require_http_methods(["GET"])
|
@require_http_methods(["GET"])
|
||||||
|
@login_required
|
||||||
def available(request, domain=""):
|
def available(request, domain=""):
|
||||||
|
|
||||||
"""Is a given domain available or not.
|
"""Is a given domain available or not.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue