def setUp(self):
        super().setUp()

        self.report_summary = self.create_picklist_item(
            "Report Summary", self.team, PicklistType.REPORT_SUMMARY,
            PickListStatus.ACTIVE)

        self.good_1 = GoodFactory(
            organisation=self.organisation,
            flags=[FlagFactory(level=FlagLevels.GOOD, team=self.team)])
        self.good_2 = GoodFactory(organisation=self.organisation)

        role = Role(name="review_goods")
        role.permissions.set([constants.GovPermissions.REVIEW_GOODS.name])
        role.save()
        self.gov_user.role = role
        self.gov_user.save()

        self.application = self.create_draft_standard_application(
            organisation=self.organisation)
        self.good_on_application_1 = GoodOnApplication.objects.create(
            good=self.good_1,
            application=self.application,
            quantity=10,
            unit=Units.NAR,
            value=500)
        self.good_on_application_2 = GoodOnApplication.objects.create(
            good=self.good_2,
            application=self.application,
            quantity=10,
            unit=Units.NAR,
            value=500)
        self.case = self.submit_application(self.application)
        self.url = reverse_lazy("goods:control_list_entries",
                                kwargs={"case_pk": self.case.id})
    def test_filter_by_goods_related_description(self):
        application_1 = StandardApplicationFactory()
        good_1 = GoodFactory(
            organisation=application_1.organisation,
            description="Desc 1",
            comment="Comment 1",
            report_summary="Report Summary 1",
        )
        GoodOnApplicationFactory(application=application_1, good=good_1)
        application_2 = StandardApplicationFactory()
        good_2 = GoodFactory(organisation=application_2.organisation,
                             description="afdaf",
                             comment="asdfsadf",
                             report_summary="asdfdsf")
        GoodOnApplicationFactory(application=application_2, good=good_2)

        application_3 = StandardApplicationFactory()
        goods_type = GoodsTypeFactory(application=application_3)

        qs_1 = Case.objects.search(
            goods_related_description=good_1.description)
        qs_2 = Case.objects.search(goods_related_description=good_1.comment)
        qs_3 = Case.objects.search(
            goods_related_description=good_1.report_summary)
        qs_4 = Case.objects.search(
            goods_related_description=goods_type.description)

        self.assertEqual(qs_1.count(), 1)
        self.assertEqual(qs_2.count(), 1)
        self.assertEqual(qs_3.count(), 1)
        self.assertEqual(qs_4.count(), 1)
        self.assertEqual(qs_1.first().pk, application_1.pk)
        self.assertEqual(qs_2.first().pk, application_1.pk)
        self.assertEqual(qs_3.first().pk, application_1.pk)
        self.assertEqual(qs_4.first().pk, application_3.pk)
    def test_submit_standard_application_adds_system_case_flags_success(self, upload_bytes_file_func, html_to_pdf_func):
        upload_bytes_file_func.return_value = None
        html_to_pdf_func.return_value = None
        firearm_details = FirearmFactory()
        firearm_good = GoodFactory(
            description="a good",
            organisation=self.organisation,
            item_category=ItemCategory.GROUP2_FIREARMS,
            firearm_details=firearm_details,
        )
        draft = self.create_draft_standard_application(organisation=self.organisation, good=firearm_good)
        draft.is_military_end_use_controls = True
        draft.is_informed_wmd = True
        draft.save()
        data = {"submit_declaration": True, "agreed_to_declaration": True, "agreed_to_foi": True, "foi_reason": ""}
        url = reverse("applications:application_submit", kwargs={"pk": draft.id})

        response = self.client.put(url, data=data, **self.exporter_headers)
        self.draft.refresh_from_db()
        case_flags = [str(flag_id) for flag_id in draft.flags.values_list("id", flat=True)]

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn(SystemFlags.MILITARY_END_USE_ID, case_flags)
        self.assertIn(SystemFlags.WMD_END_USE_ID, case_flags)
        self.assertIn(SystemFlags.FIREARMS_ID, case_flags)
        html_to_pdf_func.assert_called_once()
        upload_bytes_file_func.assert_called_once()
Example #4
0
    def create_standard_application_with_incorporated_good(
        self,
        organisation: Organisation,
        reference_name="Standard Draft",
        safe_document=True,
    ):

        application = self.create_draft_standard_application(
            organisation, reference_name, safe_document)

        GoodOnApplication(
            good=GoodFactory(
                is_good_controlled=True,
                organisation=self.organisation,
            ),
            application=application,
            quantity=17,
            value=18,
            is_good_incorporated=True,
        ).save()

        self.ultimate_end_user = self.create_party("Ultimate End User",
                                                   organisation,
                                                   PartyType.ULTIMATE_END_USER,
                                                   application)
        self.create_document_for_party(
            application.ultimate_end_users.first().party, safe=safe_document)

        return application
    def test_filter_by_flags(self):
        flag_1 = FlagFactory(name="Name_1",
                             level="Destination",
                             team=self.gov_user.team,
                             priority=9)
        flag_2 = FlagFactory(name="Name_2",
                             level="Destination",
                             team=self.gov_user.team,
                             priority=10)
        flag_3 = FlagFactory(name="Name_3",
                             level="good",
                             team=self.gov_user.team,
                             priority=1)
        application_1 = StandardApplicationFactory()
        application_1.flags.add(flag_1)
        application_2 = StandardApplicationFactory()
        application_2.flags.add(flag_2)
        application_3 = StandardApplicationFactory()
        application_3.flags.add(flag_2)
        application_4 = StandardApplicationFactory()
        GoodOnApplicationFactory(
            good=GoodFactory(organisation=application_4.organisation,
                             flags=[flag_3]),
            application=application_4,
        )

        qs_1 = Case.objects.search(flags=[flag_1.id])
        qs_2 = Case.objects.search(flags=[flag_2.id])
        qs_3 = Case.objects.search(flags=[flag_3.id])

        self.assertEqual(qs_1.count(), 1)
        self.assertEqual(qs_2.count(), 2)
        self.assertEqual(qs_3.count(), 1)
        self.assertEqual(qs_3.first().pk, application_4.pk)
    def test_filter_by_finalised_date_range(self):
        day_1 = timezone.datetime(day=10, month=10, year=2020)
        day_2 = timezone.datetime(day=11, month=10, year=2020)
        day_3 = timezone.datetime(day=12, month=10, year=2020)
        day_4 = timezone.datetime(day=13, month=10, year=2020)
        day_5 = timezone.datetime(day=14, month=10, year=2020)

        application_1 = StandardApplicationFactory()
        application_1.status = get_case_status_by_status(
            CaseStatusEnum.FINALISED)
        application_1.save()
        good = GoodFactory(organisation=application_1.organisation)
        FinalAdviceFactory(user=self.gov_user,
                           team=self.team,
                           case=application_1,
                           good=good,
                           type=AdviceType.APPROVE,
                           created_at=day_2)

        application_2 = StandardApplicationFactory()
        application_2.status = get_case_status_by_status(
            CaseStatusEnum.FINALISED)
        application_2.save()
        good = GoodFactory(organisation=application_2.organisation)
        FinalAdviceFactory(user=self.gov_user,
                           team=self.team,
                           case=application_2,
                           good=good,
                           type=AdviceType.APPROVE,
                           created_at=day_4)

        qs_1 = Case.objects.search(finalised_from=day_1, finalised_to=day_3)
        qs_2 = Case.objects.search(finalised_from=day_3, finalised_to=day_5)
        qs_3 = Case.objects.search(finalised_from=day_1)
        qs_4 = Case.objects.search(finalised_to=day_5)
        qs_5 = Case.objects.search(finalised_to=day_1)
        qs_6 = Case.objects.search(finalised_from=day_5)

        self.assertEqual(qs_1.count(), 1)
        self.assertEqual(qs_2.count(), 1)
        self.assertEqual(qs_3.count(), 2)
        self.assertEqual(qs_4.count(), 2)
        self.assertEqual(qs_5.count(), 0)
        self.assertEqual(qs_6.count(), 0)
        self.assertEqual(qs_1.first().pk, application_1.pk)
        self.assertEqual(qs_2.first().pk, application_2.pk)
Example #7
0
    def test_view_good__query_filter_by_control_list_entry(
            self, control_list_entry, count):
        org = self.organisation

        GoodFactory(organisation=org,
                    is_good_controlled=True,
                    control_list_entries=["ML1a"])
        GoodFactory(organisation=org,
                    is_good_controlled=True,
                    control_list_entries=["ML1a"])

        url = reverse(
            "goods:goods") + "?control_list_entry=" + control_list_entry

        response = self.client.get(url, **self.exporter_headers)
        response_data = response.json()["results"]

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response_data), count)
Example #8
0
    def test_view_good__query_filter_by_part_number_and_combinations(self):
        GoodFactory(
            description="car1",
            part_number="cl500",
            organisation=self.organisation,
        )

        GoodFactory(
            description="Car2",
            part_number="CL300",
            organisation=self.organisation,
        )

        GoodFactory(
            description="car3",
            part_number="ML500",
            organisation=self.organisation,
        )

        GoodFactory(
            description="Truck",
            part_number="CL1000",
            organisation=self.organisation,
        )

        url = reverse("goods:goods") + "?part_number=cl"
        response = self.client.get(url, **self.exporter_headers)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_data = response.json()["results"]
        self.assertEqual(len(response_data), 3)

        url = reverse("goods:goods") + "?part_number=100"
        response = self.client.get(url, **self.exporter_headers)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_data = response.json()["results"]
        self.assertEqual(len(response_data), 1)
        self.assertEqual(response_data[0]["description"], "Truck")

        url = reverse("goods:goods") + "?part_number=cl&description=car"
        response = self.client.get(url, **self.exporter_headers)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_data = response.json()["results"]
        self.assertEqual(len(response_data), 2)
Example #9
0
    def test_get_licence_gov_view(self):
        application = StandardApplicationFactory()
        licence = LicenceFactory(
            case=application, start_date=timezone.now().date(), status=LicenceStatus.ISSUED, duration=100,
        )
        self.url = reverse("cases:licences", kwargs={"pk": application.id})

        good = GoodFactory(organisation=application.organisation)
        good_advice = FinalAdviceFactory(
            user=self.gov_user, team=self.team, case=application, good=good, type=AdviceType.APPROVE
        )
        good_on_application = GoodOnApplicationFactory(
            application=application, good=good, quantity=100.0, value=1500, unit=Units.KGM
        )
        good_on_licence = GoodOnLicenceFactory(
            good=good_on_application,
            quantity=good_on_application.quantity,
            usage=20.0,
            value=good_on_application.value,
            licence=licence,
        )

        response = self.client.get(self.url, **self.gov_headers)
        response_data = response.json()["licence"]

        self.assertEqual(response_data["id"], str(licence.id))
        self.assertEqual(response_data["start_date"], licence.start_date.strftime("%Y-%m-%d"))
        self.assertEqual(response_data["duration"], licence.duration)
        self.assertEqual(response_data["goods_on_licence"][0]["good_on_application_id"], str(good_on_application.id))
        self.assertEqual(response_data["goods_on_licence"][0]["usage"], good_on_licence.usage)
        self.assertEqual(response_data["goods_on_licence"][0]["description"], good.description)
        self.assertEqual(response_data["goods_on_licence"][0]["units"]["key"], good_on_application.unit)
        self.assertEqual(response_data["goods_on_licence"][0]["applied_for_quantity"], good_on_application.quantity)
        self.assertEqual(response_data["goods_on_licence"][0]["applied_for_value"], good_on_application.value)
        self.assertEqual(response_data["goods_on_licence"][0]["licenced_quantity"], good_on_licence.quantity)
        self.assertEqual(response_data["goods_on_licence"][0]["licenced_value"], good_on_licence.value)
        self.assertEqual(
            response_data["goods_on_licence"][0]["applied_for_value_per_item"],
            good_on_application.value / good_on_application.quantity,
        )
        self.assertEqual(
            response_data["goods_on_licence"][0]["licenced_value_per_item"],
            good_on_licence.value / good_on_licence.quantity,
        )
        self.assertEqual(
            len(response_data["goods_on_licence"][0]["control_list_entries"]), good.control_list_entries.count()
        )
        self.assertEqual(response_data["goods_on_licence"][0]["advice"]["type"]["key"], good_advice.type)
        self.assertEqual(response_data["goods_on_licence"][0]["advice"]["text"], good_advice.text)
        self.assertEqual(response_data["goods_on_licence"][0]["advice"]["proviso"], good_advice.proviso)
    def test_filter_by_final_advice(self):
        application = StandardApplicationFactory()
        good = GoodFactory(organisation=application.organisation)
        FinalAdviceFactory(user=self.gov_user,
                           team=self.team,
                           case=application,
                           good=good,
                           type=AdviceType.APPROVE)

        qs_1 = Case.objects.search(final_advice_type=AdviceType.CONFLICTING)
        qs_2 = Case.objects.search(final_advice_type=AdviceType.APPROVE)

        self.assertEqual(qs_1.count(), 0)
        self.assertEqual(qs_2.count(), 1)
        self.assertEqual(qs_2.first().pk, application.pk)
Example #11
0
    def test_when_removing_a_clc_control_list_entry_from_many_then_new_control_list_entries_is_returned(self):
        good = GoodFactory(
            organisation=self.organisation, is_good_controlled=True, control_list_entries=["ML1a", "ML1b"]
        )
        url = reverse("goods:good", kwargs={"pk": str(good.id)})

        request_data = {"is_good_controlled": True, "control_list_entries": ["ML1b"]}

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

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(
            response.json()["good"]["control_list_entries"],
            [{"rating": "ML1b", "text": get_control_list_entry("ML1b").text}],
        )
    def test_filter_by_good_control_list_entry(self):
        application_1 = StandardApplicationFactory()
        good = GoodFactory(
            organisation=application_1.organisation,
            is_good_controlled=True,
            control_list_entries=["ML1a"],
        )
        GoodOnApplicationFactory(application=application_1, good=good)

        application_2 = OpenApplicationFactory()
        GoodsTypeFactory(application=application_2,
                         is_good_controlled=True,
                         control_list_entries=["ML2a"])

        qs_1 = Case.objects.search(control_list_entry="")
        qs_2 = Case.objects.search(control_list_entry="ML1b")
        qs_3 = Case.objects.search(control_list_entry="ML1a")
        qs_4 = Case.objects.search(control_list_entry="ML2a")

        self.assertEqual(qs_1.count(), 2)
        self.assertEqual(qs_2.count(), 0)
        self.assertEqual(qs_3.count(), 1)
        self.assertEqual(qs_4.count(), 1)
Example #13
0
 def setUp(self):
     super().setUp()
     self.application = StandardApplicationFactory()
     self.licence = LicenceFactory(
         case=self.application,
         start_date=timezone.now().date(),
         status=LicenceStatus.REVOKED,
         duration=100,
         reference_code="reference",
     )
     self.good = GoodFactory(organisation=self.application.organisation)
     self.good_on_application = GoodOnApplicationFactory(
         application=self.application,
         good=self.good,
         quantity=100.0,
         value=Decimal("1000.00"))
     self.good_on_licence = GoodOnLicenceFactory(
         good=self.good_on_application,
         quantity=self.good_on_application.quantity,
         usage=20.0,
         value=20,
         licence=self.licence,
     )
class GoodsVerifiedTestsStandardApplication(DataTestClient):
    def setUp(self):
        super().setUp()

        self.report_summary = self.create_picklist_item(
            "Report Summary", self.team, PicklistType.REPORT_SUMMARY,
            PickListStatus.ACTIVE)

        self.good_1 = GoodFactory(
            organisation=self.organisation,
            flags=[FlagFactory(level=FlagLevels.GOOD, team=self.team)])
        self.good_2 = GoodFactory(organisation=self.organisation)

        role = Role(name="review_goods")
        role.permissions.set([constants.GovPermissions.REVIEW_GOODS.name])
        role.save()
        self.gov_user.role = role
        self.gov_user.save()

        self.application = self.create_draft_standard_application(
            organisation=self.organisation)
        self.good_on_application_1 = GoodOnApplication.objects.create(
            good=self.good_1,
            application=self.application,
            quantity=10,
            unit=Units.NAR,
            value=500)
        self.good_on_application_2 = GoodOnApplication.objects.create(
            good=self.good_2,
            application=self.application,
            quantity=10,
            unit=Units.NAR,
            value=500)
        self.case = self.submit_application(self.application)
        self.url = reverse_lazy("goods:control_list_entries",
                                kwargs={"case_pk": self.case.id})

    def test_verify_multiple_goods(self):
        """
        Post multiple goods to the endpoint, and check that the control code is updated for both
        """

        data = {
            "objects": [self.good_1.pk, self.good_2.pk],
            "comment": "I Am Easy to Find",
            "report_summary": self.report_summary.pk,
            "control_list_entries": ["ML1a"],
            "is_good_controlled": True,
        }

        response = self.client.post(self.url, data, **self.gov_headers)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        verified_good_1 = Good.objects.get(pk=self.good_1.pk)
        verified_good_2 = Good.objects.get(pk=self.good_2.pk)

        self.assertEqual(verified_good_1.control_list_entries.get().rating,
                         "ML1a")
        self.assertEqual(verified_good_2.control_list_entries.get().rating,
                         "ML1a")

    def test_verify_multiple_goods_NLR(self):
        """
        Post multiple goods to the endpoint, and check that the control code is not set if good is not controlled
        """
        data = {
            "objects": [self.good_1.pk, self.good_2.pk],
            "comment": "I Am Easy to Find",
            "report_summary": self.report_summary.pk,
            "control_list_entries": ["ML1a"],
            "is_good_controlled": False,
        }

        response = self.client.post(self.url, data, **self.gov_headers)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        self.good_1.refresh_from_db()
        self.good_2.refresh_from_db()
        self.assertEqual(self.good_1.control_list_entries.count(), 1)
        self.assertEqual(self.good_2.control_list_entries.count(), 1)

    def test_invalid_good_pk(self):
        # given one of the good pk is invalid
        data = {
            "objects": [self.team.pk, self.good_1.pk],
            "comment": "I Am Easy to Find",
            "report_summary": self.report_summary.pk,
            "is_good_controlled": False,
            "control_list_entries": ["ML1b"],
        }

        # when I review the goods
        response = self.client.post(self.url, data, **self.gov_headers)
        self.assertEquals(response.status_code, 200)

        # then the valid good is updated
        verified_good = Good.objects.get(pk=self.good_1.pk)
        self.assertEqual(verified_good.control_list_entries.count(), 1)

    @parameterized.expand([
        (
            # legacy where frontend doesn't send is_precedent
            {
                "comment": "I Am Easy to Find",
                "is_good_controlled": False,
                "control_list_entries": [],
            },
            False,
        ),
        (
            # precedent = False
            {
                "comment": "I Am Easy to Find",
                "is_good_controlled": False,
                "control_list_entries": [],
                "is_precedent": False,
            },
            False,
        ),
        (
            # precedent = True
            {
                "comment": "I Am Easy to Find",
                "is_good_controlled": False,
                "control_list_entries": [],
                "is_precedent": True,
            },
            True,
        ),
    ])
    def test_is_precedent_is_set(self, input, expected_is_precedent):
        defaults = {
            "objects": [self.good_1.pk],
            "report_summary": self.report_summary.pk,
        }
        data = {**defaults, **input}

        # when I review the goods
        response = self.client.post(self.url, data, **self.gov_headers)
        self.assertEquals(response.status_code, 200)

        # then the good_on_application is updated
        verified_good_on_application = GoodOnApplication.objects.get(
            pk=self.good_on_application_1.pk)
        self.assertEqual(verified_good_on_application.is_precedent,
                         expected_is_precedent)

    def test_standard_invalid_control_list_entries(self):
        """
        Post multiple goods to the endpoint, and that a bad request is returned, and that flags is not updated
        """
        data = {
            "objects": [self.good_1.pk, self.good_2.pk],
            "comment": "I Am Easy to Find",
            "report_summary": self.report_summary.pk,
            "is_good_controlled": True,
            "control_list_entries": ["invalid"],
        }

        response = self.client.post(self.url, data, **self.gov_headers)
        self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST)

        # since it has an invalid control code, flags should not be removed
        verified_good = Good.objects.get(pk=self.good_1.pk)
        self.assertTrue(is_not_verified_flag_set_on_good(verified_good))

    def test_standard_controlled_good_empty_control_list_entries(self):
        """
        Post multiple goods, with an blank control_list_entries and is controlled, for a 400 response, and no update of goods
        """
        data = {
            "objects": [self.good_1.pk, self.good_2.pk],
            "comment": "I Am Easy to Find",
            "report_summary": self.report_summary.pk,
            "is_good_controlled": True,
            "control_list_entries": [],
        }

        response = self.client.post(self.url, data, **self.gov_headers)
        self.assertEquals(response.status_code, 200)

    def test_user_cannot_review_good_without_permissions(self):
        """
        Tests that the right level of permissions are required by a gov user to review a good.
        """
        # create a second user to adopt the super user role as it will
        # overwritten otherwise if we try and remove the role from the first
        valid_user = GovUserFactory(
            baseuser_ptr__email="*****@*****.**",
            baseuser_ptr__first_name="John",
            baseuser_ptr__last_name="Smith",
            team=self.team,
            role=self.super_user_role,
        )
        valid_user.save()

        self.gov_user.role = self.default_role
        self.gov_user.save()

        response = self.client.post(self.url, **self.gov_headers)

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

    @parameterized.expand(CaseStatusEnum.terminal_statuses())
    def test_cannot_set_control_list_entries_when_application_in_terminal_state(
            self, terminal_status):
        self.application.status = get_case_status_by_status(terminal_status)
        self.application.save()

        data = {
            "objects": self.good_1.pk,
            "comment": "I Am Easy to Find",
            "report_summary": self.report_summary.pk,
            "control_list_entries": "ML1a",
            "is_good_controlled": "yes",
        }

        response = self.client.post(self.url, data, **self.gov_headers)
        self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #15
0
    def create_mod_clearance_application(
        self,
        organisation,
        case_type,
        reference_name="MOD Clearance Draft",
        safe_document=True,
        additional_information=True,
    ):
        if case_type == CaseTypeEnum.F680:
            model = F680ClearanceApplication
        elif case_type == CaseTypeEnum.GIFTING:
            model = GiftingClearanceApplication
        elif case_type == CaseTypeEnum.EXHIBITION:
            model = ExhibitionClearanceApplication
        else:
            raise BaseException(
                "Invalid case type when creating test MOD Clearance application"
            )

        application = model.objects.create(
            name=reference_name,
            activity="Trade",
            usage="Trade",
            organisation=organisation,
            case_type_id=case_type.id,
            status=get_case_status_by_status(CaseStatusEnum.DRAFT),
            clearance_level=PvGrading.UK_UNCLASSIFIED
            if case_type == CaseTypeEnum.F680 else None,
            submitted_by=self.exporter_user,
        )

        if case_type == CaseTypeEnum.EXHIBITION:
            application.title = "title"
            application.required_by_date = "2021-07-20"
            application.first_exhibition_date = "2022-08-19"
            application.save()
            # must be refreshed to return data in same format as database call
            application.refresh_from_db()
        elif case_type == CaseTypeEnum.F680:
            application.types.add(F680ClearanceType.objects.first())
            self.create_party("End User", organisation, PartyType.END_USER,
                              application)
            self.create_party("Third party", organisation,
                              PartyType.THIRD_PARTY, application)
            self.add_party_documents(
                application,
                safe_document,
                consignee=case_type == CaseTypeEnum.EXHIBITION)
            if additional_information:
                self.add_additional_information(application)
            application.intended_end_use = "intended end use here"
            application.save()
        else:
            self.create_party("End User", organisation, PartyType.END_USER,
                              application)
            self.create_party("Third party", organisation,
                              PartyType.THIRD_PARTY, application)
            self.add_party_documents(
                application,
                safe_document,
                consignee=case_type == CaseTypeEnum.EXHIBITION)

        if case_type not in [
                CaseTypeEnum.F680, CaseTypeEnum.EXHIBITION,
                CaseTypeEnum.GIFTING
        ]:
            self.create_party("Consignee", organisation, PartyType.CONSIGNEE,
                              application)

        # Add a good to the standard application
        self.good_on_application = GoodOnApplication.objects.create(
            good=GoodFactory(organisation=organisation,
                             is_good_controlled=True),
            application=application,
            quantity=10,
            unit=Units.NAR,
            value=500,
        )

        self.create_application_document(application)

        if case_type == CaseTypeEnum.EXHIBITION:
            # Add a site to the application
            SiteOnApplication(site=organisation.primary_site,
                              application=application).save()

        return application
Example #16
0
    def create_draft_standard_application(
        self,
        organisation: Organisation,
        reference_name="Standard Draft",
        safe_document=True,
        parties=True,
        site=True,
        case_type_id=CaseTypeEnum.SIEL.id,
        add_a_good=True,
        user: ExporterUser = None,
        good=None,
    ):
        if not user:
            user = UserOrganisationRelationship.objects.filter(
                organisation_id=organisation.id).first().user

        application = StandardApplication(
            name=reference_name,
            export_type=ApplicationExportType.PERMANENT,
            case_type_id=case_type_id,
            have_you_been_informed=ApplicationExportLicenceOfficialType.YES,
            reference_number_on_information_form="",
            activity="Trade",
            usage="Trade",
            organisation=organisation,
            status=get_case_status_by_status(CaseStatusEnum.DRAFT),
            is_military_end_use_controls=False,
            is_informed_wmd=False,
            is_suspected_wmd=False,
            is_eu_military=False,
            is_compliant_limitations_eu=None,
            intended_end_use="this is our intended end use",
            is_shipped_waybill_or_lading=True,
            non_waybill_or_lading_route_details=None,
            status_id="00000000-0000-0000-0000-000000000000",
            submitted_by=user,
        )

        application.save()

        if add_a_good:
            # Add a good to the standard application
            self.good_on_application = GoodOnApplication.objects.create(
                good=good if good else GoodFactory(organisation=organisation,
                                                   is_good_controlled=True),
                application=application,
                quantity=10,
                unit=Units.NAR,
                value=500,
            )

        if parties:
            self.create_party("End User", organisation, PartyType.END_USER,
                              application)
            self.create_party("Consignee", organisation, PartyType.CONSIGNEE,
                              application)
            self.create_party("Third party", organisation,
                              PartyType.THIRD_PARTY, application)
            # Set the application party documents

            self.add_party_documents(application, safe_document)

        self.create_application_document(application)

        # Add a site to the application
        if site:
            SiteOnApplication(site=organisation.primary_site,
                              application=application).save()

        return application
        generate_compliance_site_case(case)

        self.assertFalse(ComplianceSiteCase.objects.exists())

    @parameterized.expand([
        ("ML21", True),
        ("ML22", True),
        ("ML2", False),
        ("0D", True),
    ])
    def tests_siel_good_control_code(self, control_code, exists):
        case = self.create_standard_application_case(self.organisation)

        good = GoodFactory(
            organisation=self.organisation,
            is_good_controlled=True,
            control_list_entries=[control_code],
        )
        GoodOnLicenceFactory(
            good=GoodOnApplicationFactory(application=case, good=good),
            licence=LicenceFactory(case=case),
            quantity=100,
            value=1,
        )

        generate_compliance_site_case(case)

        self.assertEqual(ComplianceSiteCase.objects.exists(), exists)

    def test_multiple_cases_creates_one_compliance_case(self):
        # Both cases uses the organisation primary site by default on creation