Skip to content

Commit

Permalink
Merge pull request #836 from uktrade/LTD-1313-open-application-endpoint
Browse files Browse the repository at this point in the history
Add endpoint for open applications
  • Loading branch information
wkeeling authored Oct 12, 2021
2 parents 4ea99ba + 7884a68 commit 64db05b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 16 deletions.
9 changes: 8 additions & 1 deletion api/data_workspace/application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework.pagination import LimitOffsetPagination

from api.applications import models
from api.applications.serializers import standard_application, good, party, denial
from api.applications.serializers import open_application, standard_application, good, party, denial
from api.core.authentication import DataWorkspaceOnlyAuthentication


Expand Down Expand Up @@ -39,3 +39,10 @@ class DenialMatchOnApplicationListView(viewsets.ReadOnlyModelViewSet):
serializer_class = denial.DenialMatchOnApplicationViewSerializer
pagination_class = LimitOffsetPagination
queryset = models.DenialMatchOnApplication.objects.all().order_by("id")


class OpenApplicationListView(viewsets.ReadOnlyModelViewSet):
authentication_classes = (DataWorkspaceOnlyAuthentication,)
serializer_class = open_application.OpenApplicationViewSerializer
pagination_class = LimitOffsetPagination
queryset = models.OpenApplication.objects.all()
88 changes: 73 additions & 15 deletions api/data_workspace/tests/test_application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from rest_framework import status
from urllib import parse

from api.applications.enums import (
ApplicationExportType,
ApplicationExportLicenceOfficialType,
)
from api.applications.enums import ApplicationExportType, ApplicationExportLicenceOfficialType, GoodsTypeCategory
from test_helpers.clients import DataTestClient
from api.applications.models import GoodOnApplication, GoodOnApplicationControlListEntry
from api.cases.enums import CaseTypeReferenceEnum
Expand All @@ -22,6 +19,7 @@ def setUp(self):
super().setUp()
test_host = "http://testserver"
self.standard_applications = parse.urljoin(test_host, reverse("data_workspace:dw-standard-applications-list"))
self.open_applications = parse.urljoin(test_host, reverse("data_workspace:dw-open-applications-list"))
self.good_on_applications = parse.urljoin(test_host, reverse("data_workspace:dw-good-on-applications-list"))
self.good_on_applications_clc_entries = parse.urljoin(
test_host, reverse("data_workspace:dw-good-on-applications-control-list-entries-list")
Expand Down Expand Up @@ -126,21 +124,81 @@ def test_dw_good_on_application_control_list_entry_views(self):
response = self.client.options(self.good_on_applications_clc_entries)
self.assertEqual(response.status_code, status.HTTP_200_OK)
actual_keys = response.json()["actions"]["GET"].keys()
expected_keys = (
"id",
"goodonapplication",
"controllistentry",
)
expected_keys = ("id", "goodonapplication", "controllistentry")
self.assertEqual(tuple(actual_keys), expected_keys)

def test_dw_denial_on_application_views(self):
response = self.client.options(self.denial_on_applications)
self.assertEqual(response.status_code, status.HTTP_200_OK)
actual_keys = response.json()["actions"]["GET"].keys()
expected_keys = {
"id",
"denial",
"application",
"category",
}
expected_keys = {"id", "denial", "application", "category"}
self.assertEqual(expected_keys, actual_keys)

def test_dw_open_application_views(self):
data = {
"name": "Test",
"application_type": CaseTypeReferenceEnum.OIEL,
"export_type": ApplicationExportType.TEMPORARY,
"goodstype_category": GoodsTypeCategory.MILITARY,
"contains_firearm_goods": True,
}

response = self.client.post(reverse("applications:applications"), data, **self.exporter_headers)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

response = self.client.options(self.open_applications)
self.assertEqual(response.status_code, status.HTTP_200_OK)
actual_keys = response.json()["actions"]["GET"].keys()
expected_keys = (
"id",
"name",
"organisation",
"case_type",
"export_type",
"created_at",
"updated_at",
"submitted_at",
"submitted_by",
"status",
"case",
"reference_code",
"is_major_editable",
"goods_locations",
"case_officer",
"agreed_to_foi",
"foi_reason",
"sla_days",
"sla_remaining_days",
"sla_updated_at",
"last_closed_at",
"end_user",
"ultimate_end_users",
"third_parties",
"consignee",
"inactive_parties",
"activity",
"usage",
"goods_types",
"additional_documents",
"is_military_end_use_controls",
"military_end_use_controls_ref",
"is_informed_wmd",
"informed_wmd_ref",
"is_suspected_wmd",
"suspected_wmd_ref",
"intended_end_use",
"licence",
"is_shipped_waybill_or_lading",
"non_waybill_or_lading_route_details",
"temp_export_details",
"is_temp_direct_control",
"temp_direct_control_details",
"proposed_return_date",
"trade_control_activity",
"trade_control_product_categories",
"goodstype_category",
"contains_firearm_goods",
"sanction_matches",
)
for key in expected_keys:
self.assertTrue(key in actual_keys)
1 change: 1 addition & 0 deletions api/data_workspace/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
router_v1.register(
"standard-applications", application_views.StandardApplicationListView, basename="dw-standard-applications"
)
router_v1.register("open-applications", application_views.OpenApplicationListView, basename="dw-open-applications")
router_v1.register(
"good-on-applications", application_views.GoodOnApplicationListView, basename="dw-good-on-applications"
)
Expand Down

0 comments on commit 64db05b

Please sign in to comment.