-
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.
Browse files
Browse the repository at this point in the history
[LTD-5399] Add caseworker-specific CLEs endpoint
- Loading branch information
Showing
13 changed files
with
121 additions
and
49 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
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions
9
api/staticdata/caseworker/control_list_entries/serializers.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,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", "parent") |
Empty file.
67 changes: 67 additions & 0 deletions
67
api/staticdata/caseworker/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,67 @@ | ||
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("caseworker_staticdata:control_list_entries:control_list_entries") | ||
super().setUp() | ||
ControlListEntry.objects.all().delete() | ||
self.parent_cle = ControlListEntriesFactory( | ||
rating="ML1", | ||
selectable_for_assessment=False, | ||
text="some ML1 text", | ||
) | ||
self.child_cle = ControlListEntriesFactory( | ||
rating="ML1a", | ||
parent=self.parent_cle, | ||
selectable_for_assessment=True, | ||
text="some ML1a text", | ||
) | ||
|
||
def test_GET_success(self): | ||
response = self.client.get(self.url, **self.gov_headers) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
self.assertEqual( | ||
response.json(), | ||
[ | ||
{ | ||
"rating": "ML1a", | ||
"text": "some ML1a text", | ||
"parent": str(self.parent_cle.id), | ||
} | ||
], | ||
) | ||
|
||
def test_GET_exporter_forbidden(self): | ||
response = self.client.get(self.url, **self.exporter_headers) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
|
||
def test_GET_include_non_selectable_for_assessment_param(self): | ||
url = self.url + "?include_non_selectable_for_assessment=True" | ||
response = self.client.get(url, **self.gov_headers) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
self.assertEqual( | ||
response.json(), | ||
[ | ||
{ | ||
"rating": "ML1", | ||
"text": "some ML1 text", | ||
"parent": None, | ||
}, | ||
{ | ||
"rating": "ML1a", | ||
"text": "some ML1a text", | ||
"parent": str(self.parent_cle.id), | ||
}, | ||
], | ||
) |
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.caseworker.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,18 @@ | ||
from rest_framework import generics | ||
|
||
from api.core.authentication import GovAuthentication | ||
from api.staticdata.control_list_entries.models import ControlListEntry | ||
from api.staticdata.caseworker.control_list_entries.serializers import ControlListEntriesListSerializer | ||
|
||
|
||
class ControlListEntriesList(generics.ListAPIView): | ||
authentication_classes = (GovAuthentication,) | ||
pagination_class = None | ||
serializer_class = ControlListEntriesListSerializer | ||
|
||
def get_queryset(self): | ||
include_unselectable = self.request.GET.get("include_non_selectable_for_assessment", False) | ||
if include_unselectable: | ||
return ControlListEntry.objects.filter(controlled=True) | ||
|
||
return ControlListEntry.objects.filter(controlled=True, selectable_for_assessment=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 = "caseworker_staticdata" | ||
|
||
urlpatterns = [ | ||
path("control-list-entries/", include("api.staticdata.caseworker.control_list_entries.urls")), | ||
] |
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