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)
예제 #2
0
class GetCaseLicenceTests(DataTestClient):
    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,
        )

    def test_get_application_licences(self):
        data = get_case_licences(self.application)[0]
        self.assertEqual(data["id"], str(self.licence.id))
        self.assertEqual(data["reference_code"], self.licence.reference_code)
        self.assertEqual(data["status"],
                         LicenceStatus.to_str(self.licence.status))
        self.assertEqual(data["goods"][0]["control_list_entries"][0]["rating"],
                         "ML1a")
        self.assertEqual(data["goods"][0]["description"],
                         self.good.description)
        self.assertEqual(data["goods"][0]["quantity"],
                         self.good_on_licence.quantity)
        self.assertEqual(data["goods"][0]["usage"], self.good_on_licence.usage)

    def test_get_application_licences_application_level_control_list_entry(
            self):
        self.good_on_application.is_good_controlled = False
        self.good_on_application.save()
        self.good_on_application.control_list_entries.add(
            get_control_list_entry("ML1a"))
        self.good_on_application.control_list_entries.add(
            get_control_list_entry("ML13d1"))

        data = get_case_licences(self.application)[0]

        self.assertEqual(data["goods"][0]["is_good_controlled"], False)
        # ignore order of control list entries
        self.assertEqual(
            set([
                x["rating"] for x in data["goods"][0]["control_list_entries"]
            ]), {"ML1a", "ML13d1"})
    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)
예제 #4
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,
     )
예제 #5
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_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)
    @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
        case = self.create_open_application_case(self.organisation)
        case_2 = self.create_open_application_case(self.organisation)
        generate_compliance_site_case(case)
        generate_compliance_site_case(case_2)