Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sekharpanja committed Feb 21, 2022
1 parent 03da167 commit 72a893a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 13 deletions.
1 change: 1 addition & 0 deletions api/applications/creators.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _validate_siel_locations(application, errors):

return errors


def _get_document_errors(documents, processing_error, virus_error):
document_statuses = documents.values_list("safe", flat=True)

Expand Down
2 changes: 1 addition & 1 deletion api/applications/serializers/temporary_export_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validate(self, data):
data, "temp_export_details", strings.Generic.TemporaryExportDetails.Error.TEMPORARY_EXPORT_DETAILS
)
is_temp_direct_control_value = validate_field(
data, "is_temp_direct_control", strings.Generic.TemporaryExportDetails.Error.PRODUCTS_UNDER_DIRECT_CONTROL
data, "is_temp_direct_control", strings.Generic.TemporaryExportDetails.Error.PRODUCTS_UNDER_DIRECT_CONTROL, required=True
)

# Only validate temp_direct_control_details if its parent is_temp_direct_control is False
Expand Down
23 changes: 21 additions & 2 deletions api/applications/tests/test_create_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ def test_create_draft_standard_individual_export_application_successful(self):
self.assertEqual(response_data["id"], str(standard_application.id))
self.assertEqual(StandardApplication.objects.count(), 1)

def test_create_draft_standard_individual_export_application_empty_export_type_successful(self):
"""
Ensure we can create a new standard individual export application draft without the export_type field populated
"""
data = {
"name": "Test",
"application_type": CaseTypeReferenceEnum.SIEL,
"have_you_been_informed": ApplicationExportLicenceOfficialType.YES,
"reference_number_on_information_form": "123",
}

response = self.client.post(self.url, data, **self.exporter_headers)
response_data = response.json()
standard_application = StandardApplication.objects.get()

self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(response_data["id"], str(standard_application.id))
self.assertEqual(StandardApplication.objects.count(), 1)

def test_create_draft_exhibition_clearance_application_successful(self):
"""
Ensure we can create a new Exhibition Clearance draft object
Expand All @@ -63,7 +82,7 @@ def test_create_draft_exhibition_clearance_application_successful(self):

def test_create_draft_gifting_clearance_application_successful(self):
"""
Ensure we can create a new Exhibition Clearance draft object
Ensure we can create a new Gifting Clearance draft object
"""
self.assertEqual(GiftingClearanceApplication.objects.count(), 0)

Expand All @@ -82,7 +101,7 @@ def test_create_draft_gifting_clearance_application_successful(self):

def test_create_draft_f680_clearance_application_successful(self):
"""
Ensure we can create a new Exhibition Clearance draft object
Ensure we can create a new F680 Clearance draft object
"""
self.assertEqual(F680ClearanceApplication.objects.count(), 0)

Expand Down
41 changes: 41 additions & 0 deletions api/applications/tests/test_edit_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,47 @@ def test_edit_unsubmitted_application_name_success(self):
# Unsubmitted (draft) applications should not create audit entries when edited
self.assertEqual(Audit.objects.count(), 0)

def test_edit_unsubmitted_application_export_type_success(self):
""" Test edit the application export_type of an unsubmitted application. An unsubmitted application
has the 'draft' status.
"""
application = self.create_draft_standard_application(self.organisation)
# export_type is set to permanent in create_draft_standard_application
self.assertEqual(application.export_type, "permanent")

url = reverse("applications:application", kwargs={"pk": application.id})
updated_at = application.updated_at

response = self.client.put(url, {"export_type": "temporary"}, **self.exporter_headers)

application.refresh_from_db()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(application.export_type, "temporary")
self.assertGreater(application.updated_at, updated_at)
# Unsubmitted (draft) applications should not create audit entries when edited
self.assertEqual(Audit.objects.count(), 0)

def test_edit_unsubmitted_application_locations_success(self):
application = self.create_draft_standard_application(self.organisation)

url = reverse("applications:application", kwargs={"pk": application.id})
updated_at = application.updated_at

data = {
"goods_starting_point": "GB",
"goods_recipients": "via_consignee",
}

response = self.client.put(url, data, **self.exporter_headers)

application.refresh_from_db()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(application.goods_starting_point, "GB")
self.assertEqual(application.goods_recipients, "via_consignee")
self.assertGreater(application.updated_at, updated_at)
# Unsubmitted (draft) applications should not create audit entries when edited
self.assertEqual(Audit.objects.count(), 0)

@parameterized.expand(get_case_statuses(read_only=False))
def test_edit_application_name_in_editable_status_success(self, editable_status):
old_name = "Old Name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_perform_action_on_non_temporary_export_type_standard_applications_failu
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.json()["errors"],
["{'get_temp_export_details_update_serializer does not support this export type: permanent'}"],
{"temp_export_details": ["Cannot update temporary export details for a permanent export type"]},
)

def test_perform_action_on_non_open_or_standard_applications_failure(self):
Expand Down
30 changes: 27 additions & 3 deletions api/applications/tests/test_standard_application_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from uuid import UUID

from api.applications.enums import ApplicationExportType
from api.applications.models import SiteOnApplication, GoodOnApplication, PartyOnApplication
from api.applications.models import SiteOnApplication, GoodOnApplication, PartyOnApplication, StandardApplication
from api.audit_trail.enums import AuditType
from api.audit_trail.models import Audit
from api.cases.enums import CaseTypeEnum, CaseDocumentState
Expand Down Expand Up @@ -60,12 +60,34 @@ def test_submit_standard_application_with_invalid_id_failure(self):

self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_submit_standard_application_without_site_or_external_location_failure(self):
SiteOnApplication.objects.get(application=self.draft).delete()
def test_submit_standard_application_old_location_info_success(self):
SiteOnApplication(site=self.organisation.primary_site, application=self.draft).save()
url = reverse("applications:application_submit", kwargs={"pk": self.draft.id})

response = self.client.put(url, **self.exporter_headers)

self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_submit_standard_application_with_new_location_info_success(self):
url = reverse("applications:application_submit", kwargs={"pk": self.draft.id})
SiteOnApplication.objects.filter(application_id=self.draft.id).delete()
self.draft.goods_recipients = StandardApplication.DIRECT_TO_END_USER
self.draft.goods_starting_point = StandardApplication.GB

response = self.client.put(url, **self.exporter_headers)

self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_submit_standard_application_with_no_new_or_old_location_info_failure(self):
url = reverse("applications:application_submit", kwargs={"pk": self.draft.id})
SiteOnApplication.objects.filter(application_id=self.draft.id).delete()
self.draft.export_type = ""
self.draft.goods_recipients = ""
self.draft.goods_starting_point = ""
self.draft.is_shipped_waybill_or_lading = None
self.draft.save()

response = self.client.put(url, **self.exporter_headers)
self.assertContains(
response,
text=strings.Applications.Generic.NO_LOCATION_SET,
Expand Down Expand Up @@ -100,6 +122,8 @@ def test_submit_standard_application_without_end_user_document_failure(self):

def test_submit_standard_application_without_consignee_failure(self):
self.draft.delete_party(self.draft.consignee)
self.draft.goods_recipients = StandardApplication.DIRECT_TO_END_USER
self.draft.save()

url = reverse("applications:application_submit", kwargs={"pk": self.draft.id})

Expand Down
6 changes: 0 additions & 6 deletions api/applications/views/goods.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,7 @@ def post(self, request, pk):
data["firearm_details"]["firearms_act_section"] = "firearms_act_section5"

serializer = GoodOnApplicationCreateSerializer(data=data)
print('*****************')
print('ApplicationGoodsOnApplication post serializer')
print('*****************')
if serializer.is_valid():
print('*****************')
print('ApplicationGoodsOnApplication post serializer.is_valid()')
print('*****************')
serializer.save()

audit_trail_service.create(
Expand Down

0 comments on commit 72a893a

Please sign in to comment.