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_change_approve_final_advice_deletes_good_country_decisions(self):
        self.gov_user.role.permissions.set([
            constants.GovPermissions.MANAGE_LICENCE_FINAL_ADVICE.name,
        ])
        case = self.create_open_application_case(self.organisation)
        url = reverse("cases:case_final_advice", kwargs={"pk": case.id})
        goods_type = GoodsTypeFactory(application=case)
        FinalAdviceFactory(
            user=self.gov_user,
            team=self.team,
            case=case,
            goods_type=goods_type,
            type=AdviceType.APPROVE,
        )
        GoodCountryDecisionFactory(case=case,
                                   goods_type=goods_type,
                                   country=Country.objects.first())

        data = {
            "text": "Changed my mind. Reject this",
            "type": AdviceType.REFUSE,
            "goods_type": str(goods_type.id),
        }
        response = self.client.post(url, **self.gov_headers, data=[data])

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.json()["advice"][0]["goods_type"],
                         str(goods_type.id))
        self.assertFalse(
            GoodCountryDecision.objects.filter(goods_type=goods_type).exists())
Пример #3
0
 def setUp(self):
     super().setUp()
     self.gov_user.role.permissions.set(
         [GovPermissions.MANAGE_LICENCE_FINAL_ADVICE.name])
     self.case = self.create_open_application_case(self.organisation)
     self.url = reverse("cases:goods_countries_decisions",
                        kwargs={"pk": self.case.id})
     # Covers every combination of APPROVE/REFUSE for goods_type on country
     self.countries = [Country.objects.first(), Country.objects.last()]
     self.approved_country = self.countries[0]
     self.refused_country = self.countries[1]
     self.approved_goods_type = GoodsTypeFactory(application=self.case)
     self.approved_goods_type_clcs = [ControlListEntry.objects.first()]
     self.approved_goods_type.control_list_entries.set(
         self.approved_goods_type_clcs)
     self.approved_goods_type.countries.set(self.countries)
     self.refused_goods_type = GoodsTypeFactory(application=self.case)
     self.refused_goods_type_clcs = [ControlListEntry.objects.last()]
     self.refused_goods_type.control_list_entries.set(
         self.refused_goods_type_clcs)
     self.refused_goods_type.countries.set(self.countries)
     FinalAdviceFactory(
         user=self.gov_user,
         team=self.team,
         case=self.case,
         goods_type=self.approved_goods_type,
         type=AdviceType.APPROVE,
     )
     FinalAdviceFactory(
         user=self.gov_user,
         team=self.team,
         case=self.case,
         goods_type=self.refused_goods_type,
         type=AdviceType.REFUSE,
     )
     FinalAdviceFactory(user=self.gov_user,
                        team=self.team,
                        case=self.case,
                        country=self.approved_country,
                        type=AdviceType.APPROVE)
     FinalAdviceFactory(user=self.gov_user,
                        team=self.team,
                        case=self.case,
                        country=self.refused_country,
                        type=AdviceType.REFUSE)
Пример #4
0
    def setUp(self):
        super().setUp()

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

        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_open_application(
            organisation=self.organisation)

        self.good_1 = GoodsTypeFactory(application=self.application)
        self.good_1.flags.add(self.create_flag("New Flag", "Good", self.team))
        self.good_2 = GoodsTypeFactory(application=self.application)

        self.case = self.submit_application(self.application)
        self.url = reverse_lazy("goods:control_list_entries",
                                kwargs={"case_pk": self.case.id})
Пример #5
0
    def create_draft_open_application(self,
                                      organisation: Organisation,
                                      reference_name="Open Draft",
                                      case_type_id=CaseTypeEnum.OIEL.id):
        application = OpenApplication(
            name=reference_name,
            case_type_id=case_type_id,
            export_type=ApplicationExportType.PERMANENT,
            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,
            intended_end_use="intended end use is none of your business",
            is_shipped_waybill_or_lading=True,
            non_waybill_or_lading_route_details=None,
            status_id="00000000-0000-0000-0000-000000000000",
            submitted_by=self.exporter_user,
        )

        application.save()

        # Add a goods description
        GoodsTypeFactory(application=application, is_good_controlled=True)
        GoodsTypeFactory(application=application, is_good_controlled=True)

        # Add a country to the application - GB cannot be a destination on licences!
        CountryOnApplication(application=application,
                             country=get_country("FR")).save()

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

        return application
Пример #6
0
    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 test_cannot_remove_goodstype_from_open_cryptographic_application(self):
        self.create_draft_open_application(self.organisation)
        application = self.create_draft_open_application(organisation=self.organisation)
        application.goodstype_category = GoodsTypeCategory.CRYPTOGRAPHIC
        application.save()
        goodstype = GoodsTypeFactory(application=application)
        initial_goods_count = GoodsType.objects.all().count()
        url = reverse(
            "applications:application_goodstype", kwargs={"pk": application.id, "goodstype_pk": goodstype.id},
        )

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

        self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEquals(GoodsType.objects.all().count(), initial_goods_count)
Пример #8
0
class OpenApplicationAdviceDocumentsTests(DataTestClient):
    def test_get_final_advice_documents_refuse_good_on_country(self):
        case = self.create_open_application_case(self.organisation)
        url = reverse("cases:final_advice_documents", kwargs={"pk": case.id})
        country = Country.objects.first()
        goods_type = GoodsTypeFactory(application=case)
        goods_type.countries.set([country])
        FinalAdviceFactory(
            user=self.gov_user, team=self.team, case=case, goods_type=goods_type, type=AdviceType.APPROVE,
        )
        GoodCountryDecisionFactory(case=case, country=country, approve=False)

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

        # GoodCountryDecision overrides the approve final advice with a rejection
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response_data, {"refuse": {"value": "Refuse"}})
    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)
Пример #10
0
class GoodsVerifiedTestsOpenApplication(DataTestClient):
    def setUp(self):
        super().setUp()

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

        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_open_application(
            organisation=self.organisation)

        self.good_1 = GoodsTypeFactory(application=self.application)
        self.good_1.flags.add(self.create_flag("New Flag", "Good", self.team))
        self.good_2 = GoodsTypeFactory(application=self.application)

        self.case = self.submit_application(self.application)
        self.url = reverse_lazy("goods:control_list_entries",
                                kwargs={"case_pk": self.case.id})

    def test_verify_single_good(self):
        """
        Post a singular good to the endpoint, and check that the control code is updated, and flags are removed
        """
        data = {
            "objects": self.good_1.pk,
            "comment": "I Am Easy to Find",
            "report_summary": self.report_summary.pk,
            "is_good_controlled": True,
            "control_list_entries": ["ML1a"],
        }

        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.assertEqual(
            list(
                self.good_1.control_list_entries.values_list("rating",
                                                             flat=True)),
            ["ML1a"])

        # determine that flags have been removed when good verified
        self.assertFalse(is_not_verified_flag_set_on_good(self.good_1))

    def test_verify_only_change_comment_doesnt_remove_flags(self):
        """
        Assert that not changing the control code does not remove the flags
        """
        self.good_1.is_good_controlled = True
        self.good_1.control_list_entries.set([get_control_list_entry("ML1a")])
        self.good_1.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": True,
        }

        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.assertEqual(
            list(
                self.good_1.control_list_entries.values_list("rating",
                                                             flat=True)),
            ["ML1a"])

        # determine that flags have not been removed when control code hasn't changed
        self.assertEqual(self.good_1.flags.count(), 1)

    def test_invalid_control_list_entries(self):
        """
        Post multiple goods to the endpoint, and that a bad request is returned, and that flags are not updated
        """

        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": ["invalid"],
            "is_good_controlled": "True",
        }

        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
        self.good_1.refresh_from_db()
        self.good_2.refresh_from_db()
        self.assertTrue(is_not_verified_flag_set_on_good(self.good_1))
        self.assertTrue(is_not_verified_flag_set_on_good(self.good_2))

    def test_user_cannot_review_goods_without_permissions(self):
        """
        Tests that the right level of permissions are required
        """
        # 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)