-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2170 from uktrade/uat
Prod Release
- Loading branch information
Showing
11 changed files
with
349 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from rest_framework import serializers | ||
|
||
from api.staticdata.control_list_entries.models import ControlListEntry | ||
|
||
|
||
class ControlListEntriesListSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = ControlListEntry | ||
fields = ("rating", "text") |
48 changes: 48 additions & 0 deletions
48
api/staticdata/exporter/control_list_entries/tests/test_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from rest_framework import status | ||
from rest_framework.reverse import reverse | ||
|
||
from api.staticdata.control_list_entries.models import ControlListEntry | ||
from api.staticdata.control_list_entries.factories import ControlListEntriesFactory | ||
from test_helpers.clients import DataTestClient | ||
|
||
|
||
class ControlListEntriesListTests(DataTestClient): | ||
def setUp(self): | ||
self.url = reverse("exporter_staticdata:control_list_entries:control_list_entries") | ||
super().setUp() | ||
|
||
def test_list_view_success(self): | ||
response = self.client.get(self.url, **self.exporter_headers) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
self.assertTrue(len(response.json()) > 0) | ||
|
||
for cle in response.json(): | ||
self.assertEqual(list(cle.keys()), ["rating", "text"]) | ||
|
||
def test_list_view_failure_bad_headers(self): | ||
response = self.client.get(self.url, **self.gov_headers) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
|
||
def test_list_view_success_exact_response(self): | ||
# Set up empty CLE db table for this test only | ||
ControlListEntry.objects.all().delete() | ||
|
||
cle_1 = ControlListEntriesFactory(rating="ABC123", controlled=True) | ||
cle_2 = ControlListEntriesFactory(rating="1Z101", controlled=True) | ||
cle_3 = ControlListEntriesFactory(rating="ZXYW", controlled=True) | ||
|
||
response = self.client.get(self.url, **self.exporter_headers) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
self.assertEqual( | ||
response.json(), | ||
[ | ||
{"rating": cle_1.rating, "text": cle_1.text}, | ||
{"rating": cle_2.rating, "text": cle_2.text}, | ||
{"rating": cle_3.rating, "text": cle_3.text}, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
|
||
from api.staticdata.exporter.control_list_entries import views | ||
|
||
app_name = "control_list_entries" | ||
|
||
urlpatterns = [ | ||
path("", views.ControlListEntriesList.as_view(), name="control_list_entries"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework import generics | ||
|
||
from api.core.authentication import ExporterAuthentication | ||
from api.staticdata.control_list_entries.models import ControlListEntry | ||
from api.staticdata.exporter.control_list_entries.serializers import ControlListEntriesListSerializer | ||
|
||
|
||
class ControlListEntriesList(generics.ListAPIView): | ||
authentication_classes = (ExporterAuthentication,) | ||
pagination_class = None | ||
serializer_class = ControlListEntriesListSerializer | ||
queryset = ControlListEntry.objects.filter(controlled=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path, include | ||
|
||
app_name = "exporter_staticdata" | ||
|
||
urlpatterns = [ | ||
path("control-list-entries/", include("api.staticdata.exporter.control_list_entries.urls")), | ||
] |
Oops, something went wrong.