From 750093c1da26894e61e16eb488d1f8da0ade4049 Mon Sep 17 00:00:00 2001 From: Arun Siluvery Date: Fri, 2 Feb 2024 11:33:29 +0000 Subject: [PATCH] Remove unsupported HmrcQuery type related code We don't support this yet. The current implementation may not be relevant if we need to support it and can be added based on the requirement at that time. --- api/applications/apps.py | 3 - api/applications/helpers.py | 11 - .../libraries/get_applications.py | 4 - api/applications/serializers/hmrc_query.py | 87 -------- api/applications/signals.py | 15 -- .../tests/test_application_status.py | 13 -- .../tests/test_copy_application.py | 42 ---- .../tests/test_create_application.py | 30 --- .../tests/test_delete_application.py | 4 - .../tests/test_goods_type_on_application.py | 102 --------- api/applications/tests/test_hmrc_query.py | 205 ------------------ .../tests/test_view_application.py | 58 ----- api/applications/views/applications.py | 49 ++--- api/cases/tests/test_case_search.py | 12 +- api/cases/tests/test_reference_code.py | 6 - api/cases/tests/test_sla.py | 61 ------ api/cases/views/search/service.py | 18 +- api/cases/views/search/views.py | 1 - api/core/decorators.py | 9 +- api/core/tests/test_decorators.py | 26 --- api/flags/views.py | 4 +- api/letter_templates/context_generator.py | 27 --- .../tests/test_context_generation.py | 17 -- api/workflow/tests/test_flagging_rules.py | 43 +--- test_helpers/clients.py | 47 +--- 25 files changed, 27 insertions(+), 867 deletions(-) delete mode 100644 api/applications/serializers/hmrc_query.py delete mode 100644 api/applications/signals.py delete mode 100644 api/applications/tests/test_hmrc_query.py diff --git a/api/applications/apps.py b/api/applications/apps.py index abdca780ce..b98b484f36 100644 --- a/api/applications/apps.py +++ b/api/applications/apps.py @@ -3,6 +3,3 @@ class ApplicationsConfig(AppConfig): name = "api.applications" - - def ready(self): - import api.applications.signals # noqa diff --git a/api/applications/helpers.py b/api/applications/helpers.py index 7ca64ca44e..0321688637 100644 --- a/api/applications/helpers.py +++ b/api/applications/helpers.py @@ -29,11 +29,6 @@ GiftingClearanceViewSerializer, GiftingClearanceUpdateSerializer, ) -from api.applications.serializers.hmrc_query import ( - HmrcQueryCreateSerializer, - HmrcQueryViewSerializer, - HmrcQueryUpdateSerializer, -) from api.applications.serializers.open_application import ( OpenApplicationCreateSerializer, OpenApplicationUpdateSerializer, @@ -61,8 +56,6 @@ def get_application_view_serializer(application: BaseApplication): return StandardApplicationViewSerializer elif application.case_type.sub_type == CaseTypeSubTypeEnum.OPEN: return OpenApplicationViewSerializer - elif application.case_type.sub_type == CaseTypeSubTypeEnum.HMRC: - return HmrcQueryViewSerializer elif application.case_type.sub_type == CaseTypeSubTypeEnum.EXHIBITION: return ExhibitionClearanceViewSerializer elif application.case_type.sub_type == CaseTypeSubTypeEnum.GIFTING: @@ -85,8 +78,6 @@ def get_application_create_serializer(case_type): return StandardApplicationCreateSerializer elif sub_type == CaseTypeSubTypeEnum.OPEN: return OpenApplicationCreateSerializer - elif sub_type == CaseTypeSubTypeEnum.HMRC: - return HmrcQueryCreateSerializer elif sub_type == CaseTypeSubTypeEnum.EXHIBITION: return ExhibitionClearanceCreateSerializer elif sub_type == CaseTypeSubTypeEnum.GIFTING: @@ -102,8 +93,6 @@ def get_application_update_serializer(application: BaseApplication): return StandardApplicationUpdateSerializer elif application.case_type.sub_type == CaseTypeSubTypeEnum.OPEN: return OpenApplicationUpdateSerializer - elif application.case_type.sub_type == CaseTypeSubTypeEnum.HMRC: - return HmrcQueryUpdateSerializer elif application.case_type.sub_type == CaseTypeSubTypeEnum.EXHIBITION: return ExhibitionClearanceUpdateSerializer elif application.case_type.sub_type == CaseTypeSubTypeEnum.GIFTING: diff --git a/api/applications/libraries/get_applications.py b/api/applications/libraries/get_applications.py index b179dbdd0a..e5bb40d503 100644 --- a/api/applications/libraries/get_applications.py +++ b/api/applications/libraries/get_applications.py @@ -4,7 +4,6 @@ GiftingClearanceApplication, OpenApplication, StandardApplication, - HmrcQuery, ExhibitionClearanceApplication, ) from api.cases.enums import CaseTypeSubTypeEnum @@ -77,8 +76,6 @@ def get_application(pk, organisation_id=None): return obj elif application_type == CaseTypeSubTypeEnum.OPEN: return OpenApplication.objects.get(pk=pk, **kwargs) - elif application_type == CaseTypeSubTypeEnum.HMRC: - return HmrcQuery.objects.get(pk=pk) elif application_type == CaseTypeSubTypeEnum.EXHIBITION: return ExhibitionClearanceApplication.objects.get(pk=pk) elif application_type == CaseTypeSubTypeEnum.GIFTING: @@ -90,7 +87,6 @@ def get_application(pk, organisation_id=None): except ( StandardApplication.DoesNotExist, OpenApplication.DoesNotExist, - HmrcQuery.DoesNotExist, ): raise NotFoundError({"application": "Application not found - " + str(pk)}) diff --git a/api/applications/serializers/hmrc_query.py b/api/applications/serializers/hmrc_query.py deleted file mode 100644 index 0b437c0996..0000000000 --- a/api/applications/serializers/hmrc_query.py +++ /dev/null @@ -1,87 +0,0 @@ -from rest_framework import exceptions -from rest_framework import serializers -from rest_framework.relations import PrimaryKeyRelatedField - -from api.applications.mixins.serializers import PartiesSerializerMixin -from api.applications.models import HmrcQuery, ApplicationDocument -from api.applications.serializers.document import ApplicationDocumentSerializer -from api.applications.serializers.generic_application import GenericApplicationViewSerializer -from api.cases.models import CaseType -from api.goodstype.models import GoodsType -from api.goodstype.serializers import GoodsTypeViewSerializer -from lite_content.lite_api import strings -from api.organisations.enums import OrganisationType -from api.organisations.models import Organisation -from api.organisations.serializers import TinyOrganisationViewSerializer -from api.staticdata.statuses.enums import CaseStatusEnum -from api.staticdata.statuses.libraries.get_case_status import get_case_status_by_status - - -class HmrcQueryViewSerializer(PartiesSerializerMixin, GenericApplicationViewSerializer): - goods_types = serializers.SerializerMethodField() - hmrc_organisation = TinyOrganisationViewSerializer() - supporting_documentation = serializers.SerializerMethodField() - - class Meta: - model = HmrcQuery - fields = ( - GenericApplicationViewSerializer.Meta.fields - + PartiesSerializerMixin.Meta.fields - + ( - "goods_types", - "hmrc_organisation", - "reasoning", - "supporting_documentation", - "have_goods_departed", - ) - ) - - def get_goods_types(self, instance): - goods_types = GoodsType.objects.filter(application=instance) - return GoodsTypeViewSerializer(goods_types, many=True).data - - def get_supporting_documentation(self, application): - documents = ApplicationDocument.objects.filter(application=application) - return ApplicationDocumentSerializer(documents, many=True).data - - -class HmrcQueryCreateSerializer(serializers.ModelSerializer): - organisation = PrimaryKeyRelatedField(queryset=Organisation.objects.all()) - hmrc_organisation = PrimaryKeyRelatedField(queryset=Organisation.objects.all()) - case_type = PrimaryKeyRelatedField( - queryset=CaseType.objects.all(), - error_messages={"required": strings.Applications.Generic.NO_LICENCE_TYPE}, - ) - - def __init__(self, case_type_id, **kwargs): - super().__init__(**kwargs) - - if self.context.type != OrganisationType.HMRC: - raise exceptions.PermissionDenied("User does not belong to an HMRC organisation") - - self.initial_data["case_type"] = case_type_id - self.initial_data["hmrc_organisation"] = self.context.id - self.initial_data["status"] = get_case_status_by_status(CaseStatusEnum.DRAFT).id - - class Meta: - model = HmrcQuery - fields = ( - "name", - "reasoning", - "case_type", - "organisation", - "hmrc_organisation", - "status", - ) - - -class HmrcQueryUpdateSerializer(serializers.ModelSerializer): - reasoning = serializers.CharField(max_length=1000, allow_null=True, allow_blank=True) - - class Meta: - model = HmrcQuery - fields = ( - "reasoning", - "status", - "have_goods_departed", - ) diff --git a/api/applications/signals.py b/api/applications/signals.py deleted file mode 100644 index 20b34e8294..0000000000 --- a/api/applications/signals.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.db.models.signals import post_save -from django.dispatch import receiver - -from api.applications.models import HmrcQuery - - -@receiver(post_save, sender=HmrcQuery) -def hmrc_query_save(instance: HmrcQuery, **kwargs): - """ - Every time a HMRC Query is saved, run these automations - """ - # If the goods are set to already departed, clear all existing sites and locations - if instance.have_goods_departed: - instance.application_sites.all().delete() - instance.external_application_sites.all().delete() diff --git a/api/applications/tests/test_application_status.py b/api/applications/tests/test_application_status.py index d1d8ecd189..e433c2671f 100644 --- a/api/applications/tests/test_application_status.py +++ b/api/applications/tests/test_application_status.py @@ -353,19 +353,6 @@ def test_case_routing_automation(self): ["Licensing Unit Pre-circulation Cases to Review", "new queue"], ) - def test_gov_user_set_hmrc_status_closed_success(self): - self.hmrc_query = self.create_hmrc_query(self.organisation) - self.submit_application(self.hmrc_query) - - data = {"status": CaseStatusEnum.CLOSED} - url = reverse("applications:manage_status", kwargs={"pk": self.hmrc_query.id}) - response = self.client.put(url, data=data, **self.gov_headers) - - self.hmrc_query.refresh_from_db() - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(self.hmrc_query.status, get_case_status_by_status(CaseStatusEnum.CLOSED)) - @parameterized.expand( [ ( diff --git a/api/applications/tests/test_copy_application.py b/api/applications/tests/test_copy_application.py index 884b2fbb31..6785248a35 100644 --- a/api/applications/tests/test_copy_application.py +++ b/api/applications/tests/test_copy_application.py @@ -7,7 +7,6 @@ from api.applications.models import ( StandardApplication, OpenApplication, - HmrcQuery, GoodOnApplication, CountryOnApplication, SiteOnApplication, @@ -406,47 +405,6 @@ def test_copy_submitted_F680_application_successful(self): self._validate_F680_application() - def test_copy_draft_hmrc_enquiry_successful(self): - """ - Ensure we can copy an hmrc enquiry that is a draft - """ - self.original_application = self.create_hmrc_query(self.organisation) - - self.url = reverse_lazy("applications:copy", kwargs={"pk": self.original_application.id}) - - self.data = {"name": "New application"} - - self.response = self.client.post(self.url, self.data, **self.exporter_headers) - self.response_data = self.response.json()["data"] - - self.assertEqual(self.response.status_code, status.HTTP_201_CREATED) - self.assertNotEqual(self.response_data, self.original_application.id) - - self.copied_application = HmrcQuery.objects.get(id=self.response_data) - - self._validate_hmrc_enquiry() - - def test_copy_submitted_hmrc_enquiry_successful(self): - """ - Ensure we can copy an hmrc enquiry that is submitted ongoing or otherwise - """ - self.original_application = self.create_hmrc_query(self.organisation) - self.submit_application(self.original_application) - - self.url = reverse_lazy("applications:copy", kwargs={"pk": self.original_application.id}) - - self.data = {"name": "New application"} - - self.response = self.client.post(self.url, self.data, **self.exporter_headers) - self.response_data = self.response.json()["data"] - - self.assertEqual(self.response.status_code, status.HTTP_201_CREATED) - self.assertNotEqual(self.response_data, self.original_application.id) - - self.copied_application = HmrcQuery.objects.get(id=self.response_data) - - self._validate_hmrc_enquiry() - def _validate_standard_application(self): self._validate_reset_data() self._validate_end_use_details() diff --git a/api/applications/tests/test_create_application.py b/api/applications/tests/test_create_application.py index 51c3a33ea9..3a27230ba4 100644 --- a/api/applications/tests/test_create_application.py +++ b/api/applications/tests/test_create_application.py @@ -10,7 +10,6 @@ from api.applications.models import ( StandardApplication, OpenApplication, - HmrcQuery, BaseApplication, ExhibitionClearanceApplication, GiftingClearanceApplication, @@ -135,35 +134,6 @@ def test_create_draft_open_application_successful(self): self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(OpenApplication.objects.count(), 1) - def test_create_draft_hmrc_query_successful(self): - """ - Ensure we can create a new HMRC query draft object - """ - data = { - "name": "Test", - "application_type": CaseTypeReferenceEnum.CRE, - "organisation": self.organisation.id, - } - - response = self.client.post(self.url, data, **self.hmrc_exporter_headers) - - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - self.assertEqual(HmrcQuery.objects.count(), 1) - - def test_create_draft_hmrc_query_failure(self): - """ - Ensure that a normal exporter cannot create an HMRC query - """ - data = { - "application_type": CaseTypeReferenceEnum.CRE, - "organisation": self.organisation.id, - } - - response = self.client.post(self.url, data, **self.exporter_headers) - - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(HmrcQuery.objects.count(), 0) - @parameterized.expand( [ [{}], diff --git a/api/applications/tests/test_delete_application.py b/api/applications/tests/test_delete_application.py index 63f95b34a1..4eb6a1979b 100644 --- a/api/applications/tests/test_delete_application.py +++ b/api/applications/tests/test_delete_application.py @@ -13,7 +13,6 @@ def setUp(self): super().setUp() self.applications = { CaseTypeSubTypeEnum.STANDARD: self.create_draft_standard_application(self.organisation), - CaseTypeSubTypeEnum.HMRC: self.create_hmrc_query(self.organisation), CaseTypeSubTypeEnum.EXHIBITION: self.create_mod_clearance_application( self.organisation, case_type=CaseTypeEnum.EXHIBITION ), @@ -30,7 +29,6 @@ def setUp(self): [ (CaseTypeSubTypeEnum.STANDARD, "EXPORTER"), (CaseTypeSubTypeEnum.EXHIBITION, "EXPORTER"), - (CaseTypeSubTypeEnum.HMRC, "HMRC"), (CaseTypeSubTypeEnum.GIFTING, "EXPORTER"), (CaseTypeSubTypeEnum.F680, "EXPORTER"), ] @@ -57,7 +55,6 @@ def test_delete_draft_application_as_valid_user_success(self, application_type, (CaseTypeSubTypeEnum.EXHIBITION, "GOV"), (CaseTypeSubTypeEnum.GIFTING, "GOV"), (CaseTypeSubTypeEnum.F680, "GOV"), - (CaseTypeSubTypeEnum.HMRC, "EXPORTER"), ] ) def test_delete_draft_application_as_invalid_user_failure(self, application_type, user): @@ -78,7 +75,6 @@ def test_delete_draft_application_as_invalid_user_failure(self, application_type [ (CaseTypeSubTypeEnum.STANDARD, "EXPORTER"), (CaseTypeSubTypeEnum.EXHIBITION, "EXPORTER"), - (CaseTypeSubTypeEnum.HMRC, "HMRC"), (CaseTypeSubTypeEnum.GIFTING, "EXPORTER"), (CaseTypeSubTypeEnum.F680, "EXPORTER"), ] diff --git a/api/applications/tests/test_goods_type_on_application.py b/api/applications/tests/test_goods_type_on_application.py index 8c89e7ef30..3adcecbec0 100644 --- a/api/applications/tests/test_goods_type_on_application.py +++ b/api/applications/tests/test_goods_type_on_application.py @@ -1,12 +1,8 @@ -from unittest import mock - from rest_framework import status from rest_framework.reverse import reverse -from api.goodstype.document.models import GoodsTypeDocument from api.goodstype.models import GoodsType from api.staticdata.control_list_entries.helpers import get_control_list_entry -from api.staticdata.control_list_entries.models import ControlListEntry from test_helpers.clients import DataTestClient @@ -24,15 +20,6 @@ def setUp(self): "control_list_entries": ["ML1a"], "is_good_incorporated": True, } - - self.hmrc_query = self.create_hmrc_query(self.organisation) - self.document_url = reverse( - "applications:goods_type_document", - kwargs={ - "pk": self.hmrc_query.id, - "goods_type_pk": GoodsType.objects.get(application=self.hmrc_query).id, - }, - ) self.new_document_data = { "name": "document_name.pdf", "s3_key": "s3_keykey.pdf", @@ -108,92 +95,3 @@ def test_remove_goodstype_from_open_application_as_exporter_user_success(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(GoodsType.objects.all().count(), initial_goods_types_count - 1) - - @mock.patch("api.documents.libraries.s3_operations.get_object") - @mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses") - def test_post_goods_type_document_success(self, mock_virus_scan, mock_s3_operations_get_object): - """ - Given a draft HMRC query has been created - And the draft contains a goods type - And the goods type does not have a document attached - When a document is submitted - Then a 201 CREATED is returned - """ - mock_s3_operations_get_object.return_value = self.new_document_data - mock_virus_scan.return_value = False - GoodsTypeDocument.objects.get(goods_type__application=self.hmrc_query).delete() - count = GoodsTypeDocument.objects.count() - - response = self.client.post(self.document_url, data=self.new_document_data, **self.hmrc_exporter_headers) - - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - self.assertEqual(count + 1, GoodsTypeDocument.objects.count()) - - @mock.patch("api.documents.libraries.s3_operations.get_object") - @mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses") - def test_get_goods_type_document_success(self, mock_virus_scan, mock_s3_operations_get_object): - """ - Given a draft HMRC query has been created - And the draft contains a goods type - And the goods type has a document attached - When the document is retrieved - Then the data in the document is the same as the data in the attached goods party document - """ - mock_s3_operations_get_object.return_value = self.new_document_data - mock_virus_scan.return_value = False - response = self.client.get(self.document_url, **self.hmrc_exporter_headers) - response_data = response.json()["document"] - - self.assertEqual(response_data["name"], self.new_document_data["name"]) - self.assertEqual(response_data["s3_key"], self.new_document_data["s3_key"]) - self.assertEqual(response_data["size"], self.new_document_data["size"]) - - @mock.patch("api.documents.libraries.s3_operations.get_object") - @mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses") - @mock.patch("api.documents.models.Document.delete_s3") - def test_delete_goods_type_document_success( - self, delete_s3_function, mock_virus_scan, mock_s3_operations_get_object - ): - """ - Given a draft HMRC query has been created - And the draft contains a goods type - And the goods type has a document attached - When there is an attempt to delete the document - Then 204 NO CONTENT is returned - """ - mock_s3_operations_get_object.return_value = self.new_document_data - mock_virus_scan.return_value = False - response = self.client.delete(self.document_url, **self.hmrc_exporter_headers) - - self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) - delete_s3_function.assert_called_once() - - @mock.patch("api.documents.libraries.s3_operations.get_object") - @mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses") - @mock.patch("api.documents.models.Document.delete_s3") - def test_delete_goods_type_success(self, delete_s3_function, mock_virus_scan, mock_s3_operations_get_object): - """ - Given a draft HMRC query has been created - And the draft contains a goods type - And the goods type has a document attached - When there is an attempt to delete goods type - Then 200 OK is returned - """ - mock_s3_operations_get_object.return_value = self.new_document_data - mock_virus_scan.return_value = False - url = reverse( - "applications:application_goodstype", - kwargs={ - "pk": self.hmrc_query.id, - "goodstype_pk": GoodsType.objects.get(application=self.hmrc_query).id, - }, - ) - goods_type_count = GoodsType.objects.count() - goods_type_doc_count = GoodsTypeDocument.objects.count() - - response = self.client.delete(url, **self.hmrc_exporter_headers) - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(goods_type_count - 1, GoodsType.objects.count()) - self.assertEqual(goods_type_doc_count - 1, GoodsTypeDocument.objects.count()) - delete_s3_function.assert_called_once() diff --git a/api/applications/tests/test_hmrc_query.py b/api/applications/tests/test_hmrc_query.py deleted file mode 100644 index 006489d530..0000000000 --- a/api/applications/tests/test_hmrc_query.py +++ /dev/null @@ -1,205 +0,0 @@ -from unittest import mock - -from django.urls import reverse -from rest_framework import status -from uuid import UUID - -from api.applications.models import SiteOnApplication, ExternalLocationOnApplication -from api.cases.enums import CaseTypeSubTypeEnum, CaseDocumentState -from api.cases.models import Case, CaseDocument -from api.core.constants import AutoGeneratedDocuments -from api.flags.enums import SystemFlags -from api.goodstype.models import GoodsType -from lite_content.lite_api import strings -from api.parties.models import PartyDocument -from api.staticdata.statuses.enums import CaseStatusEnum -from test_helpers.clients import DataTestClient - - -class HmrcQueryTests(DataTestClient): - def setUp(self): - super().setUp() - self.hmrc_query = self.create_hmrc_query(self.organisation) - self.url = reverse("applications:application_submit", kwargs={"pk": self.hmrc_query.id}) - - @mock.patch("api.documents.libraries.s3_operations.upload_bytes_file") - @mock.patch("api.cases.generated_documents.helpers.html_to_pdf") - def test_submit_hmrc_query_success(self, upload_bytes_file_func, html_to_pdf_func): - upload_bytes_file_func.return_value = None - html_to_pdf_func.return_value = None - - data = {"submit_hmrc": True} - response = self.client.put(self.url, data=data, **self.hmrc_exporter_headers) - - self.assertEqual(response.status_code, status.HTTP_200_OK) - case = Case.objects.get() - self.assertEqual(case.id, self.hmrc_query.id) - self.assertIsNotNone(case.submitted_at) - self.assertEqual(case.status.status, CaseStatusEnum.SUBMITTED) - self.assertEqual(case.case_type.sub_type, CaseTypeSubTypeEnum.HMRC) - self.assertTrue(UUID(SystemFlags.ENFORCEMENT_CHECK_REQUIRED) in case.flags.values_list("id", flat=True)) - self.assertEqual(case.submitted_by, self.hmrc_exporter_user) - # Asserting that the 'Application Form' has been autogenerated on submission of the application - html_to_pdf_func.assert_called_once() - upload_bytes_file_func.assert_called_once() - self.assertEqual( - CaseDocument.objects.filter( - name__contains=AutoGeneratedDocuments.APPLICATION_FORM, - type=CaseDocumentState.AUTO_GENERATED, - safe=True, - case=case, - visible_to_exporter=False, - ).count(), - 1, - ) - - def test_submit_hmrc_query_with_goods_departed_success(self): - SiteOnApplication.objects.get(application=self.hmrc_query).delete() - self.hmrc_query.have_goods_departed = True - self.hmrc_query.save() - - response = self.client.put(self.url, **self.hmrc_exporter_headers) - response_data = response.json()["application"] - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response_data["have_goods_departed"], True) - - def test_submit_hmrc_query_with_invalid_id_failure(self): - draft_id = "90D6C724-0339-425A-99D2-9D2B8E864EC7" - url = "applications/" + draft_id + "/submit/" - - response = self.client.put(url, **self.hmrc_exporter_headers) - - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - - def test_submit_hmrc_query_without_end_user_failure(self): - self.hmrc_query.end_user.delete() - - url = reverse("applications:application_submit", kwargs={"pk": self.hmrc_query.id}) - - response = self.client.put(url, **self.hmrc_exporter_headers) - - self.assertContains( - response, - text=strings.Applications.Standard.NO_END_USER_SET, - status_code=status.HTTP_400_BAD_REQUEST, - ) - - def test_submit_hmrc_query_without_end_user_document_failure(self): - PartyDocument.objects.filter(party=self.hmrc_query.end_user.party).delete() - url = reverse("applications:application_submit", kwargs={"pk": self.hmrc_query.id}) - - response = self.client.put(url, **self.hmrc_exporter_headers) - - self.assertContains( - response, - text=strings.Applications.Standard.NO_END_USER_DOCUMENT_SET, - status_code=status.HTTP_400_BAD_REQUEST, - ) - - def test_submit_hmrc_query_without_goods_type_failure(self): - GoodsType.objects.filter(application=self.hmrc_query).delete() - - response = self.client.put(self.url, **self.hmrc_exporter_headers) - - self.assertContains( - response, - text=strings.Applications.Open.NO_GOODS_SET, - status_code=status.HTTP_400_BAD_REQUEST, - ) - - def test_status_code_post_with_untested_document_failure(self): - draft = self.create_hmrc_query(self.organisation, safe_document=None) - url = reverse("applications:application_submit", kwargs={"pk": draft.id}) - - response = self.client.put(url, **self.hmrc_exporter_headers) - - self.assertContains( - response, - text=strings.Applications.Standard.END_USER_DOCUMENT_PROCESSING, - status_code=status.HTTP_400_BAD_REQUEST, - ) - - def test_status_code_post_with_infected_document_failure(self): - draft = self.create_hmrc_query(self.organisation, safe_document=False) - url = reverse("applications:application_submit", kwargs={"pk": draft.id}) - - response = self.client.put(url, **self.hmrc_exporter_headers) - - self.assertContains( - response, - text=strings.Applications.Standard.END_USER_DOCUMENT_INFECTED, - status_code=status.HTTP_400_BAD_REQUEST, - ) - - def test_setting_have_goods_departed_success(self): - """ - Ensure that when setting have_goods_departed to True - that it deletes all existing sites and locations on that application - """ - data = {"have_goods_departed": True} - - response = self.client.put( - reverse("applications:application", kwargs={"pk": self.hmrc_query.id}), data, **self.hmrc_exporter_headers - ) - self.hmrc_query.refresh_from_db() - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertTrue(self.hmrc_query.have_goods_departed) - self.assertEqual(SiteOnApplication.objects.filter(application=self.hmrc_query).count(), 0) - self.assertEqual(ExternalLocationOnApplication.objects.filter(application=self.hmrc_query).count(), 0) - - def test_setting_have_goods_departed_to_false_success(self): - """ - Ensure that when setting have_goods_departed to False that it doesn't - delete all existing sites and locations on that application - """ - data = {"have_goods_departed": False} - - response = self.client.put( - reverse("applications:application", kwargs={"pk": self.hmrc_query.id}), data, **self.hmrc_exporter_headers - ) - self.hmrc_query.refresh_from_db() - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertFalse(self.hmrc_query.have_goods_departed) - self.assertEqual(SiteOnApplication.objects.filter(application=self.hmrc_query).count(), 1) - - def test_setting_sites_when_goods_departed_is_set_to_true_failure(self): - """ - Ensure that it is not possible to add sites to the application - when have_goods_departed is set to True - """ - SiteOnApplication.objects.get(application=self.hmrc_query).delete() - self.hmrc_query.have_goods_departed = True - self.hmrc_query.save() - - data = {"sites": [self.hmrc_organisation.primary_site.id]} - - response = self.client.post( - reverse("applications:application_sites", kwargs={"pk": self.hmrc_query.id}), - data, - **self.hmrc_exporter_headers, - ) - - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - - def test_setting_locations_when_goods_departed_is_set_to_true_failure(self): - """ - Ensure that it is not possible to add external locations - to the application when have_goods_departed is set to True - """ - SiteOnApplication.objects.get(application=self.hmrc_query).delete() - self.hmrc_query.have_goods_departed = True - self.hmrc_query.save() - external_location = self.create_external_location("storage facility", self.hmrc_organisation) - - data = {"external_locations": [external_location.id]} - - response = self.client.post( - reverse("applications:application_external_locations", kwargs={"pk": self.hmrc_query.id}), - data, - **self.hmrc_exporter_headers, - ) - - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) diff --git a/api/applications/tests/test_view_application.py b/api/applications/tests/test_view_application.py index 07da3b8feb..4bdcc64976 100644 --- a/api/applications/tests/test_view_application.py +++ b/api/applications/tests/test_view_application.py @@ -69,32 +69,6 @@ def test_ensure_user_cannot_see_applications_they_only_have_partial_access_to_(s self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_data), 0) - def test_cant_view_draft_hmrc_query_list_as_exporter_success(self): - self.create_hmrc_query(organisation=self.organisation) - - response = self.client.get(self.url, **self.exporter_headers) - - result_count = response.json()["count"] - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(result_count, 0) - - def test_view_hmrc_query_list_as_hmrc_exporter_success(self): - """ - Ensure we can get a list of HMRC queries. - """ - hmrc_query = self.create_hmrc_query(organisation=self.organisation) - - response = self.client.get(self.url, **self.hmrc_exporter_headers) - response_data = response.json()["results"] - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(len(response_data), 1) - self.assertEqual(response_data[0]["name"], hmrc_query.name) - self.assertEqual(response_data[0]["case_type"]["sub_type"]["key"], hmrc_query.case_type.sub_type) - self.assertIsNotNone(response_data[0]["updated_at"]) - self.assertEqual(response_data[0]["status"]["key"], CaseStatusEnum.DRAFT) - def test_view_draft_standard_application_as_exporter_success(self): standard_application = self.create_draft_standard_application(self.organisation) @@ -280,38 +254,6 @@ def test_view_draft_open_application_as_exporter_success(self): 1, ) - def test_view_draft_hmrc_query_as_hmrc_exporter_success(self): - hmrc_query = self.create_hmrc_query(self.organisation) - - url = reverse("applications:application", kwargs={"pk": hmrc_query.id}) - - response = self.client.get(url, **self.hmrc_exporter_headers) - - retrieved_application = response.json() - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(retrieved_application["name"], hmrc_query.name) - self.assertEqual( - retrieved_application["case_type"]["reference"]["key"], - hmrc_query.case_type.reference, - ) - self.assertIsNotNone(retrieved_application["created_at"]) - self.assertIsNotNone(retrieved_application["updated_at"]) - self.assertIsNone(retrieved_application["submitted_at"]) - self.assertEqual(retrieved_application["status"]["key"], CaseStatusEnum.DRAFT) - self.assertEqual(retrieved_application["organisation"]["id"], str(hmrc_query.organisation.id)) - self.assertEqual( - retrieved_application["hmrc_organisation"]["id"], - str(hmrc_query.hmrc_organisation.id), - ) - self.assertIsNotNone(GoodsType.objects.get(application__id=hmrc_query.id)) - self.assertEqual(retrieved_application["end_user"]["id"], str(hmrc_query.end_user.party.id)) - self.assertEqual(retrieved_application["consignee"]["id"], str(hmrc_query.consignee.party.id)) - self.assertEqual( - retrieved_application["third_parties"][0]["id"], - str(hmrc_query.third_parties.get().party.id), - ) - def test_view_nonexisting_draft_failure(self): invalid_id = UUID("90D6C724-0339-425A-99D2-9D2B8E864EC6") diff --git a/api/applications/views/applications.py b/api/applications/views/applications.py index 27d3c62982..e22d667103 100644 --- a/api/applications/views/applications.py +++ b/api/applications/views/applications.py @@ -47,7 +47,6 @@ from api.applications.libraries.licence import get_default_duration from api.applications.models import ( BaseApplication, - HmrcQuery, SiteOnApplication, GoodOnApplication, CountryOnApplication, @@ -96,7 +95,6 @@ from api.licences.models import Licence from api.licences.serializers.create_licence import LicenceCreateSerializer from lite_content.lite_api import strings -from api.organisations.enums import OrganisationType from api.organisations.libraries.get_organisation import get_request_user_organisation, get_request_user_organisation_id from api.organisations.models import Site from api.staticdata.f680_clearance_types.enums import F680ClearanceTypeEnum @@ -127,28 +125,18 @@ def get_queryset(self): organisation = get_request_user_organisation(self.request) - if organisation.type == OrganisationType.HMRC: - if submitted is None: - applications = HmrcQuery.objects.filter(hmrc_organisation=organisation) - elif submitted: - applications = HmrcQuery.objects.submitted(hmrc_organisation=organisation) - else: - applications = HmrcQuery.objects.drafts(hmrc_organisation=organisation) + if submitted is None: + applications = BaseApplication.objects.filter(organisation=organisation) + elif submitted: + applications = BaseApplication.objects.submitted(organisation) else: - if submitted is None: - applications = BaseApplication.objects.filter(organisation=organisation) - elif submitted: - applications = BaseApplication.objects.submitted(organisation) - else: - applications = BaseApplication.objects.drafts(organisation) + applications = BaseApplication.objects.drafts(organisation) - users_sites = Site.objects.get_by_user_and_organisation(self.request.user.exporteruser, organisation) - disallowed_applications = SiteOnApplication.objects.exclude(site__id__in=users_sites).values_list( - "application", flat=True - ) - applications = applications.exclude(id__in=disallowed_applications).exclude( - case_type_id=CaseTypeEnum.HMRC.id - ) + users_sites = Site.objects.get_by_user_and_organisation(self.request.user.exporteruser, organisation) + disallowed_applications = SiteOnApplication.objects.exclude(site__id__in=users_sites).values_list( + "application", flat=True + ) + applications = applications.exclude(id__in=disallowed_applications) return applications.prefetch_related("status", "case_type").select_subclasses() @@ -207,7 +195,6 @@ def get_queryset(self): class ApplicationExisting(APIView): """ This view returns boolean values depending on the type of organisation: - HMRC - Whether the organisation has existing submitted queries Standard - Whether the organisation has any drafts/applications """ @@ -215,16 +202,12 @@ class ApplicationExisting(APIView): def get(self, request): organisation = get_request_user_organisation(request) - if organisation.type == "hmrc": - has_queries = HmrcQuery.objects.submitted(hmrc_organisation=organisation).exists() - return JsonResponse(data={"queries": has_queries}) - else: - has_applications = BaseApplication.objects.filter(organisation=organisation).exists() - return JsonResponse( - data={ - "applications": has_applications, - } - ) + has_applications = BaseApplication.objects.filter(organisation=organisation).exists() + return JsonResponse( + data={ + "applications": has_applications, + } + ) class ApplicationDetail(RetrieveUpdateDestroyAPIView): diff --git a/api/cases/tests/test_case_search.py b/api/cases/tests/test_case_search.py index 5a967a7fa5..cead0bc838 100644 --- a/api/cases/tests/test_case_search.py +++ b/api/cases/tests/test_case_search.py @@ -2,7 +2,6 @@ from django.urls import reverse from django import utils as django_utils -from api.staticdata.statuses.factories import CaseStatusFactory from parameterized import parameterized from rest_framework import status @@ -21,7 +20,6 @@ from api.flags.models import Flag from api.goods.tests.factories import GoodFactory from api.picklists.enums import PicklistType -from api.cases.tests.factories import CaseSIELFactory, FinalAdviceFactory from api.queues.constants import ( UPDATED_CASES_QUEUE_ID, SYSTEM_QUEUES, @@ -33,7 +31,7 @@ from api.staticdata.regimes.models import RegimeEntry from api.staticdata.report_summaries.tests.factories import ReportSummaryPrefixFactory, ReportSummarySubjectFactory from api.staticdata.statuses.libraries.get_case_status import get_case_status_by_status -from api.staticdata.statuses.models import CaseStatus, CaseSubStatus +from api.staticdata.statuses.models import CaseSubStatus from api.users.tests.factories import GovUserFactory from test_helpers.clients import DataTestClient from api.users.enums import UserStatuses @@ -929,13 +927,9 @@ def test_work_queue_returns_cases_in_expected_order(self): """Test that a work queue returns cases in expected order (hmrc queries with goods not departed first).""" clc_query_1 = self.create_clc_query("Example CLC Query", self.organisation) standard_app = self.create_standard_application_case(self.organisation, "Example Application") - hmrc_query_1 = self.submit_application(self.create_hmrc_query(self.organisation)) clc_query_2 = self.create_clc_query("Example CLC Query 2", self.organisation) - hmrc_query_2 = self.submit_application(self.create_hmrc_query(self.organisation, have_goods_departed=True)) - queue = QueueFactory( - team=self.gov_user.team, cases=[clc_query_1, standard_app, hmrc_query_1, clc_query_2, hmrc_query_2] - ) + queue = QueueFactory(team=self.gov_user.team, cases=[clc_query_1, standard_app, clc_query_2]) url = reverse("cases:search") + "?queue_id=" + str(queue.id) response = self.client.get(url, **self.gov_headers) @@ -944,11 +938,9 @@ def test_work_queue_returns_cases_in_expected_order(self): actual_case_order_ids = [case["id"] for case in response.json()["results"]["cases"]] expected_case_order_ids = [ - str(hmrc_query_1.id), str(clc_query_1.id), str(standard_app.id), str(clc_query_2.id), - str(hmrc_query_2.id), ] self.assertEqual(actual_case_order_ids, expected_case_order_ids) diff --git a/api/cases/tests/test_reference_code.py b/api/cases/tests/test_reference_code.py index 79bb17c015..415af9fbbd 100644 --- a/api/cases/tests/test_reference_code.py +++ b/api/cases/tests/test_reference_code.py @@ -75,12 +75,6 @@ def test_gifting_clearance_reference_code(self): expected_reference = build_expected_reference(CaseTypeEnum.GIFTING.reference) self.assertEqual(gifting_clearance.reference_code, expected_reference) - def test_hmrc_query_reference_code(self): - hmrc_query = self.create_hmrc_query(self.organisation) - hmrc_query = self.submit_application(hmrc_query) - expected_reference = build_expected_reference(CaseTypeEnum.HMRC.reference) - self.assertEqual(hmrc_query.reference_code, expected_reference) - def test_end_user_advisory_reference_code(self): end_user_advisory_query = self.create_end_user_advisory_case("", "", self.organisation) expected_reference = build_expected_reference(CaseTypeEnum.EUA.reference) diff --git a/api/cases/tests/test_sla.py b/api/cases/tests/test_sla.py index 6bf772be84..0832758383 100644 --- a/api/cases/tests/test_sla.py +++ b/api/cases/tests/test_sla.py @@ -3,11 +3,9 @@ from unittest.mock import patch from django.conf import settings -from django.urls import reverse from django.utils import timezone from parameterized import parameterized from pytz import timezone as tz -from rest_framework import status from api.cases.enums import CaseTypeEnum, CaseTypeSubTypeEnum from api.cases.models import Case, CaseQueue, EcjuQuery @@ -17,7 +15,6 @@ OPEN_APPLICATION_TARGET_DAYS, MOD_CLEARANCE_TARGET_DAYS, SLA_UPDATE_CUTOFF_TIME, - HMRC_QUERY_TARGET_DAYS, ) from api.cases.models import CaseAssignmentSLA, CaseQueue, DepartmentSLA from api.staticdata.statuses.enums import CaseStatusEnum @@ -47,7 +44,6 @@ def setUp(self): self.case_types = { CaseTypeSubTypeEnum.STANDARD: self.create_draft_standard_application(self.organisation), CaseTypeSubTypeEnum.OPEN: self.create_draft_open_application(self.organisation), - CaseTypeSubTypeEnum.HMRC: self.create_hmrc_query(self.organisation), CaseTypeSubTypeEnum.EXHIBITION: self.create_mod_clearance_application( self.organisation, CaseTypeEnum.EXHIBITION ), @@ -102,28 +98,6 @@ def test_sla_update_open_application( self.assertEqual(case.sla_days, 1) self.assertEqual(case.sla_remaining_days, target - 1) - @mock.patch("api.cases.celery_tasks.is_weekend") - @mock.patch("api.cases.celery_tasks.is_bank_holiday") - def test_sla_update_hmrc_query( - self, - mock_is_weekend, - mock_is_bank_holiday, - application_type=CaseTypeSubTypeEnum.HMRC, - target=HMRC_QUERY_TARGET_DAYS, - ): - mock_is_weekend.return_value = False - mock_is_bank_holiday.return_value = False - application = self.case_types[application_type] - case = self.submit_application(application) - _set_submitted_at(case, HOUR_BEFORE_CUTOFF) - - results = run_update_cases_sla_task() - case.refresh_from_db() - - self.assertEqual(results, 1) - self.assertEqual(case.sla_days, 1) - self.assertEqual(case.sla_remaining_days, target - 1) - @mock.patch("api.cases.celery_tasks.is_weekend") @mock.patch("api.cases.celery_tasks.is_bank_holiday") def test_sla_update_exhibition_mod( @@ -530,41 +504,6 @@ def test_bank_holiday_weekend_ignored(self, weekend_func, bank_holiday_func): self.assertEqual(result, 0) -class SlaHmrcCaseTests(DataTestClient): - def setUp(self): - super().setUp() - self.hmrc_query = self.create_hmrc_query(self.organisation) - self.submit_application(self.hmrc_query) - self.url = reverse("cases:search") - - def test_sla_hours_appears_on_hmrc_queries_when_goods_not_yet_left_country(self): - response = self.client.get(self.url, **self.gov_headers) - - self.assertEqual(response.status_code, status.HTTP_200_OK) - response_data = response.json()["results"]["cases"] - self.assertIn("sla_hours_since_raised", response_data[0]) - - def test_sla_hours_does_not_appear_on_hmrc_queries_when_goods_have_left_country(self): - self.hmrc_query.have_goods_departed = True - self.hmrc_query.save() - - response = self.client.get(self.url, **self.gov_headers) - - self.assertEqual(response.status_code, status.HTTP_200_OK) - response_data = response.json()["results"]["cases"] - self.assertNotIn("sla_hours_since_raised", response_data[0]) - - def test_sla_hours_does_not_appear_on_other_cases(self): - self.hmrc_query.delete() - self.create_standard_application_case(self.organisation) - - response = self.client.get(self.url, **self.gov_headers) - - self.assertEqual(response.status_code, status.HTTP_200_OK) - response_data = response.json()["results"]["cases"] - self.assertNotIn("sla_hours_since_raised", response_data[0]) - - class TerminalCaseSlaTests(DataTestClient): @mock.patch("api.cases.celery_tasks.is_weekend") @mock.patch("api.cases.celery_tasks.is_bank_holiday") diff --git a/api/cases/views/search/service.py b/api/cases/views/search/service.py index c857f16bda..aa66d47198 100644 --- a/api/cases/views/search/service.py +++ b/api/cases/views/search/service.py @@ -9,13 +9,13 @@ from api.audit_trail.service import serialize_case_activity from api.staticdata.countries.serializers import CountrySerializer -from api.applications.models import HmrcQuery, PartyOnApplication, GoodOnApplication, DenialMatchOnApplication +from api.applications.models import PartyOnApplication, GoodOnApplication, DenialMatchOnApplication from api.audit_trail.models import Audit -from api.cases.enums import CaseTypeEnum, CaseTypeSubTypeEnum, AdviceType +from api.cases.enums import CaseTypeEnum, AdviceType from api.cases import serializers as cases_serializers from api.applications.serializers.advice import AdviceSearchViewSerializer from api.cases.models import Case, EcjuQuery, Advice -from api.common.dates import working_days_in_range, number_of_days_since, working_hours_in_range +from api.common.dates import working_days_in_range, number_of_days_since from api.flags.serializers import CaseListFlagSerializer from api.organisations.models import Organisation from api.staticdata.statuses.enums import CaseStatusEnum @@ -182,18 +182,6 @@ def populate_is_recently_updated(cases: List[Dict]): ) -def get_hmrc_sla_hours(cases: List[Dict]): - hmrc_cases = [case["id"] for case in cases if case["case_type"]["sub_type"]["key"] == CaseTypeSubTypeEnum.HMRC] - hmrc_cases_goods_not_left_country = [ - str(id) - for id in HmrcQuery.objects.filter(id__in=hmrc_cases, have_goods_departed=False).values_list("id", flat=True) - ] - - for case in cases: - if case["id"] in hmrc_cases_goods_not_left_country: - case["sla_hours_since_raised"] = working_hours_in_range(case["submitted_at"], timezone.now()) - - def populate_destinations(case_map): poas = PartyOnApplication.objects.select_related("party", "party__country").filter( application__in=list(case_map.keys()), deleted_at=None diff --git a/api/cases/views/search/views.py b/api/cases/views/search/views.py index 08731b6d52..f36b383503 100644 --- a/api/cases/views/search/views.py +++ b/api/cases/views/search/views.py @@ -73,7 +73,6 @@ def get(self, request, *args, **kwargs): service.populate_other_flags(cases) service.populate_organisation(cases) service.populate_is_recently_updated(cases) - service.get_hmrc_sla_hours(cases) service.populate_activity_updates(case_map) service.populate_destinations(case_map) service.populate_good_details(case_map) diff --git a/api/core/decorators.py b/api/core/decorators.py index 1301889ca2..473fcabe72 100644 --- a/api/core/decorators.py +++ b/api/core/decorators.py @@ -7,7 +7,7 @@ from api.applications.enums import GoodsTypeCategory from api.applications.libraries.get_applications import get_application -from api.applications.models import BaseApplication, HmrcQuery +from api.applications.models import BaseApplication from api.cases.enums import CaseTypeSubTypeEnum from lite_content.lite_api import strings from api.organisations.libraries.get_organisation import get_request_user_organisation_id @@ -137,17 +137,12 @@ def inner(request, *args, **kwargs): ) if user.type == UserType.EXPORTER: - pk = _get_application_id(request, kwargs) organisation_id = get_request_user_organisation_id(request.request) required_application_details = _get_application(request, kwargs).values( "case_type__sub_type", "organisation_id" )[0] - if required_application_details["case_type__sub_type"] == CaseTypeSubTypeEnum.HMRC: - has_access = HmrcQuery.objects.filter(pk=pk, hmrc_organisation=organisation_id).exists() - else: - has_access = required_application_details["organisation_id"] == organisation_id - + has_access = required_application_details["organisation_id"] == organisation_id if not has_access: return JsonResponse( data={ diff --git a/api/core/tests/test_decorators.py b/api/core/tests/test_decorators.py index 074757c1f1..dbd099adea 100644 --- a/api/core/tests/test_decorators.py +++ b/api/core/tests/test_decorators.py @@ -118,17 +118,6 @@ def a_view(request, *args, **kwargs): resp = a_view(request=request, pk=application.pk) self.assertEqual(resp.status_code, status.HTTP_200_OK) - def test_authorised_to_view_application_hmrc_organisation_success(self): - application = self.create_hmrc_query(self.organisation) - request = _FakeRequest(self.exporter_user, application.hmrc_organisation) - - @authorised_to_view_application(ExporterUser) - def a_view(request, *args, **kwargs): - return HttpResponse() - - resp = a_view(request=request, pk=application.pk) - self.assertEqual(resp.status_code, status.HTTP_200_OK) - def test_authorised_to_view_application_wrong_user_type_failure(self): application = self.create_standard_application_case(self.organisation) request = _FakeRequest(self.exporter_user, self.organisation) @@ -156,18 +145,3 @@ def a_view(request, *args, **kwargs): "You can only perform this operation on an application that has been opened within your organisation" in resp.content.decode("utf-8") ) - - def test_authorised_to_view_application_wrong_hmrc_organisation_failure(self): - application = self.create_hmrc_query(self.organisation) - request = _FakeRequest(self.exporter_user, self.organisation) - - @authorised_to_view_application(ExporterUser) - def a_view(request, *args, **kwargs): - return HttpResponse() - - resp = a_view(request=request, pk=application.pk) - self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN) - self.assertTrue( - "You can only perform this operation on an application that has been opened within your organisation" - in resp.content.decode("utf-8") - ) diff --git a/api/flags/views.py b/api/flags/views.py index d2da3a9ff9..b94b16498c 100644 --- a/api/flags/views.py +++ b/api/flags/views.py @@ -7,7 +7,7 @@ from rest_framework.parsers import JSONParser from rest_framework.views import APIView -from api.applications.models import GoodOnApplication, CountryOnApplication, StandardApplication, HmrcQuery +from api.applications.models import GoodOnApplication, CountryOnApplication, StandardApplication from api.audit_trail import service as audit_trail_service from api.audit_trail.enums import AuditType @@ -302,8 +302,6 @@ def _get_case_for_destination(party): if not qs: qs = EndUserAdvisoryQuery.objects.filter(Q(end_user=party)) - if not qs: - qs = HmrcQuery.objects.filter(parties__party=party) if qs.exists(): return qs.first().get_case() diff --git a/api/letter_templates/context_generator.py b/api/letter_templates/context_generator.py index 200d372cd7..dcb4bc7ad4 100644 --- a/api/letter_templates/context_generator.py +++ b/api/letter_templates/context_generator.py @@ -32,7 +32,6 @@ OpenApplication, ExhibitionClearanceApplication, F680ClearanceApplication, - HmrcQuery, CountryOnApplication, GoodOnApplication, ) @@ -489,29 +488,6 @@ def to_representation(self, obj): return serialized -class HmrcQuerySerializer(serializers.ModelSerializer): - class Meta: - model = HmrcQuery - fields = ["query_reason", "have_goods_departed"] - - query_reason = serializers.CharField(source="reasoning") - have_goods_departed = FriendlyBooleanField() - - -class FlattenedHmrcQuerySerializer(serializers.ModelSerializer): - class Meta: - model = Case - fields = ["baseapplication"] - - baseapplication = BaseApplicationSerializer() - - def to_representation(self, obj): - ret = super().to_representation(obj) - hmrc_query = HmrcQuery.objects.get(id=obj.pk) - hmrc_query_data = HmrcQuerySerializer(hmrc_query).data - serialized = {**ret["baseapplication"], **hmrc_query_data} - return serialized - class EndUserAdvisoryQuerySerializer(serializers.ModelSerializer): class Meta: @@ -857,7 +833,6 @@ def to_representation(self, obj): class AdviceSerializer(serializers.ModelSerializer): - denial_reasons = DenialReasonSerializer(read_only=True, many=True) class Meta: @@ -950,7 +925,6 @@ def get_document_context(case, addressee=None): SERIALIZER_MAPPING = { CaseTypeSubTypeEnum.STANDARD: FlattenedStandardApplicationSerializer, CaseTypeSubTypeEnum.OPEN: FlattenedOpenApplicationSerializer, - CaseTypeSubTypeEnum.HMRC: FlattenedHmrcQuerySerializer, CaseTypeSubTypeEnum.EXHIBITION: FlattenedExhibitionClearanceApplicationSerializer, CaseTypeSubTypeEnum.F680: FlattenedF680ClearanceApplicationSerializer, CaseTypeSubTypeEnum.GIFTING: BaseApplicationSerializer, @@ -999,7 +973,6 @@ def format_quantity(quantity, unit): def _get_good_on_application_context_with_advice(good_on_application, advice): - good_context = GoodOnApplicationSerializer(good_on_application).data if advice: diff --git a/api/letter_templates/tests/test_context_generation.py b/api/letter_templates/tests/test_context_generation.py index 139697de73..2d702aa6db 100644 --- a/api/letter_templates/tests/test_context_generation.py +++ b/api/letter_templates/tests/test_context_generation.py @@ -15,7 +15,6 @@ from api.applications.models import ExternalLocationOnApplication, CountryOnApplication, GoodOnApplication from api.applications.tests.factories import GoodOnApplicationFactory from api.cases.enums import AdviceLevel, AdviceType, CaseTypeEnum -from api.cases.models import Advice from api.letter_templates.context_generator import EcjuQuerySerializer from api.cases.tests.factories import GoodCountryDecisionFactory, FinalAdviceFactory from api.compliance.enums import ComplianceVisitTypes, ComplianceRiskValues @@ -31,7 +30,6 @@ MilitaryUse, Component, ItemCategory, - FirearmGoodType, GoodControlled, GoodPvGraded, ) @@ -322,10 +320,6 @@ def _assert_destination_details(self, context, destination): self.assertEqual(context["contract_types"], destination.contract_types) self.assertEqual(context["other_contract_type"], destination.other_contract_type_text) - def _assert_hmrc_query_details(self, context, case): - self.assertEqual(context["query_reason"], case.reasoning) - self.assertEqual(context["have_goods_departed"], friendly_boolean(case.have_goods_departed)) - def _assert_exhibition_clearance_details(self, context, case): self.assertEqual(context["exhibition_title"], case.title) self.assertEqual(context["first_exhibition_date"], case.first_exhibition_date.strftime(DATE_FORMAT)) @@ -886,17 +880,6 @@ def test_generate_context_with_open_application_details(self): self._assert_open_application_details(context["details"], case) self._assert_destination_details(context["destinations"][0], destination) - def test_generate_context_with_hmrc_query_details(self): - case = self.create_hmrc_query(self.organisation) - - context = get_document_context(case) - render_to_string(template_name="letter_templates/case_context_test.html", context=context) - - self.assertEqual(context["case_reference"], case.reference_code) - self.assertEqual(context["case_officer_name"], case.get_case_officer_name()) - self._assert_case_type_details(context["case_type"], case) - self._assert_hmrc_query_details(context["details"], case) - def test_generate_context_with_exhibition_clearance_details(self): case = self.create_mod_clearance_application(self.organisation, case_type=CaseTypeEnum.EXHIBITION) case.reason_for_clearance = "abc" diff --git a/api/workflow/tests/test_flagging_rules.py b/api/workflow/tests/test_flagging_rules.py index 4cd0d9282f..7a85455eec 100644 --- a/api/workflow/tests/test_flagging_rules.py +++ b/api/workflow/tests/test_flagging_rules.py @@ -2,23 +2,16 @@ from django.urls import reverse_lazy from parameterized import parameterized -from rest_framework import status from api.applications.models import GoodOnApplication, PartyOnApplication, CountryOnApplication from api.applications.tests.factories import PartyOnApplicationFactory from api.cases.enums import CaseTypeEnum -from api.core import constants from api.flags.enums import FlagLevels, FlagStatuses from api.flags.models import Flag, FlaggingRule from api.goods.enums import GoodStatus from api.goods.tests.factories import GoodFactory from api.goodstype.models import GoodsType -from api.staticdata.control_list_entries.models import ControlListEntry -from api.staticdata.control_list_entries.helpers import ( - get_clc_child_nodes, - get_clc_parent_nodes, - get_control_list_entry, -) +from api.staticdata.control_list_entries.helpers import get_control_list_entry from api.staticdata.statuses.enums import CaseStatusEnum from api.staticdata.statuses.libraries.get_case_status import get_case_status_by_status from api.teams.models import Team @@ -31,7 +24,6 @@ get_active_legacy_flagging_rules_for_level, apply_flagging_rule_to_all_open_cases, ) -from api.users.models import Role class FlaggingRulesAutomation(DataTestClient): @@ -460,39 +452,6 @@ def test_standard_application(self): self.assertIn(good_flag, good.flags.all()) self.assertIn(destination_flag, party.flags.all()) - def test_hmrc_application(self): - application = self.create_hmrc_query(self.organisation) - - case_flag = self.create_flag("case flag", FlagLevels.CASE, self.team) - self.create_flagging_rule( - FlagLevels.CASE, self.team, flag=case_flag, matching_values=[application.case_type.reference] - ) - - goods_type = GoodsType.objects.filter(application_id=application.id).first() - good_flag = self.create_flag("good flag", FlagLevels.GOOD, self.team) - - goods_type.control_list_entries.set([get_control_list_entry("ML1a")]) - self.create_flagging_rule( - FlagLevels.GOOD, self.team, flag=good_flag, matching_values=[goods_type.control_list_entries.first().rating] - ) - - party = PartyOnApplication.objects.filter(application_id=application.id).first().party - destination_flag = self.create_flag("dest flag", FlagLevels.DESTINATION, self.team) - self.create_flagging_rule( - FlagLevels.DESTINATION, self.team, flag=destination_flag, matching_values=[party.country_id] - ) - - self.submit_application(application) - apply_flagging_rules_to_case(application) - - application.refresh_from_db() - goods_type.refresh_from_db() - party.refresh_from_db() - - self.assertIn(case_flag, application.flags.all()) - self.assertIn(good_flag, goods_type.flags.all()) - self.assertIn(destination_flag, party.flags.all()) - def test_F680_application(self): application = self.create_mod_clearance_application(self.organisation, CaseTypeEnum.F680) diff --git a/test_helpers/clients.py b/test_helpers/clients.py index a21a62ceaf..c8cfd95896 100644 --- a/test_helpers/clients.py +++ b/test_helpers/clients.py @@ -24,7 +24,6 @@ CountryOnApplication, StandardApplication, OpenApplication, - HmrcQuery, ApplicationDocument, ExhibitionClearanceApplication, GiftingClearanceApplication, @@ -41,7 +40,6 @@ Case, CaseDocument, CaseAssignment, - GoodCountryDecision, EcjuQuery, CaseType, Advice, @@ -56,12 +54,10 @@ from api.flags.tests.factories import FlagFactory from api.addresses.tests.factories import AddressFactoryGB from api.goods.enums import ( - GoodControlled, GoodPvGraded, PvGrading, ItemCategory, MilitaryUse, - Component, FirearmGoodType, ) from api.goods.models import Good, GoodDocument, PvGradingDetails, FirearmGoodDetails @@ -73,7 +69,7 @@ from api.letter_templates.models import LetterTemplate from api.licences.enums import LicenceStatus from api.licences.helpers import get_licence_reference_code -from api.licences.models import GoodOnLicence, Licence +from api.licences.models import Licence from api.organisations.enums import OrganisationType from api.organisations.models import Organisation, ExternalLocation from api.organisations.tests.factories import OrganisationFactory, SiteFactory @@ -100,7 +96,7 @@ from api.teams.models import Team from api.users.tests.factories import GovUserFactory from test_helpers import colours -from api.users.enums import UserStatuses, SystemUser, UserType +from api.users.enums import SystemUser, UserType from api.users.libraries.user_to_token import user_to_token from api.users.models import ExporterUser, UserOrganisationRelationship, BaseUser, GovUser, Role from api.workflow.flagging_rules_automation import apply_flagging_rules_to_case @@ -953,45 +949,6 @@ def create_open_application_case(self, organisation: Organisation, reference_nam return self.submit_application(draft, self.exporter_user) - def create_hmrc_query( - self, organisation: Organisation, reference_name="HMRC Query", safe_document=True, have_goods_departed=False - ): - application = HmrcQuery( - name=reference_name, - case_type_id=CaseTypeEnum.HMRC.id, - activity="Trade", - usage="Trade", - organisation=organisation, - hmrc_organisation=self.hmrc_organisation, - reasoning="I Am Easy to Find", - status=get_case_status_by_status(CaseStatusEnum.DRAFT), - have_goods_departed=have_goods_departed, - submitted_by=self.hmrc_exporter_user, - ) - application.save() - - end_user = self.create_party("End User", organisation, PartyType.END_USER, application) - consignee = self.create_party("Consignee", organisation, PartyType.CONSIGNEE, application) - third_party = self.create_party("Third party", organisation, PartyType.THIRD_PARTY, application) - - self.assertEqual(end_user, application.end_user.party) - self.assertEqual(consignee, application.consignee.party) - self.assertEqual(third_party, application.third_parties.get().party) - - goods_type = GoodsTypeFactory(application=application) - - # Set the application party documents - self.create_document_for_party(application.end_user.party, safe=safe_document) - self.create_document_for_party(application.consignee.party, safe=safe_document) - self.create_document_for_party(application.third_parties.first().party, safe=safe_document) - - self.create_document_for_goods_type(goods_type) - - # Add a site to the application - SiteOnApplication(site=organisation.primary_site, application=application).save() - - return application - def create_standard_application_case( self, organisation: Organisation,