def test_create_goodstype_multiple_clcs_on_open_application_as_exporter_user_success( self): self.data["control_list_entries"] = ["ML1a", "ML1b"] response = self.client.post(self.url, self.data, **self.exporter_headers) self.assertEquals(response.status_code, status.HTTP_201_CREATED) response_data = response.json()["good"] self.assertEquals(response_data["description"], "Widget") self.assertEquals(response_data["is_good_controlled"], True) self.assertEquals( sorted(response_data["control_list_entries"], key=lambda i: i["rating"]), [ { "rating": "ML1a", "text": get_control_list_entry("ML1a").text }, { "rating": "ML1b", "text": get_control_list_entry("ML1b").text }, ], ) self.assertEquals(response_data["is_good_incorporated"], True)
def test_when_updating_clc_control_list_entries_then_new_control_list_entries_is_returned(self): request_data = {"is_good_controlled": True, "control_list_entries": ["ML1a", "ML1b"]} response = self.client.put(self.url, request_data, **self.exporter_headers) self.assertEquals(response.status_code, status.HTTP_200_OK) self.assertEquals( sorted(response.json()["good"]["control_list_entries"], key=lambda i: i["rating"]), [ {"rating": "ML1a", "text": get_control_list_entry("ML1a").text}, {"rating": "ML1b", "text": get_control_list_entry("ML1b").text}, ], ) self.assertEquals(Good.objects.all().count(), 1)
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_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_respond_to_control_list_classification_query_nlr(self): """ Ensure that a gov user can respond to a control list classification query with no licence required. """ control_list_entries = self.query.good.control_list_entries.set( [get_control_list_entry("ML1a")]) data = { "comment": "I Am Easy to Find", "report_summary": self.report_summary.pk, "is_good_controlled": "no" } response = self.client.put(self.url, data, **self.gov_headers) self.query.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( list( self.query.good.control_list_entries.values_list("rating", flat=True)), ["ML1a"]) self.assertEqual(self.query.good.is_good_controlled, False) self.assertEqual(self.query.good.status, GoodStatus.VERIFIED) # Check that an activity item has been added qs = Audit.objects.filter( target_object_id=self.query.id, target_content_type=ContentType.objects.get_for_model(self.query)) for audit in qs: verb = AuditType.GOOD_REVIEWED if audit.payload else AuditType.CLC_RESPONSE self.assertEqual(AuditType(audit.verb), verb)
def test_respond_to_control_list_classification_query_without_updating_control_list_entries_success( self): self.query.good.control_list_entries.set( [get_control_list_entry("ML1a")]) self.query.good.save() previous_query_control_list_entries = self.query.good.control_list_entries response = self.client.put(self.url, self.data, **self.gov_headers) self.query.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( [clc.rating for clc in self.query.good.control_list_entries.all()], self.data["control_list_entries"]) self.assertEqual(self.query.good.control_list_entries, previous_query_control_list_entries) self.assertEqual(self.query.good.is_good_controlled, True) self.assertEqual(self.query.good.status, GoodStatus.VERIFIED) case = self.query.get_case() # Check that an audit item has been added audit_qs = Audit.objects.filter( target_object_id=case.id, target_content_type=ContentType.objects.get_for_model(case)) self.assertEqual(audit_qs.count(), 1)
def get(self, request, rating): """ Returns details of a specific control ratings """ control_list_entry = get_control_list_entry(rating) serializer = ControlListEntrySerializerWithLinks(control_list_entry) return JsonResponse(data={"control_list_entry": serializer.data})
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 control_list_entries(self, create, extracted, **kwargs): if not create: # Simple build, do nothing. return control_list_entries = extracted or ["ML1a"] for control_list_entry in control_list_entries: self.control_list_entries.add( get_control_list_entry(control_list_entry))
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_goods_query_application(self): query = self.create_clc_query("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=[query.case_type.reference] ) good = query.good good.control_list_entries.set([get_control_list_entry("ML1a")]) good_flag = self.create_flag("good flag", FlagLevels.GOOD, self.team) self.create_flagging_rule( FlagLevels.GOOD, self.team, flag=good_flag, matching_values=[good.control_list_entries.first().rating] ) apply_flagging_rules_to_case(query) query.refresh_from_db() good.refresh_from_db() self.assertIn(case_flag, query.flags.all()) self.assertIn(good_flag, good.flags.all())
def setUp(self): super().setUp() self.good = Good( description="Good description", is_good_controlled=None, is_pv_graded=GoodPvGraded.NO, pv_grading_details=None, part_number="123456", organisation=self.organisation, ) self.good.control_list_entries.set([get_control_list_entry("ML1a")]) self.good.save() self.data = { "good_id": self.good.id, "not_sure_details_control_list_entries": ["ML1a"], "not_sure_details_details": "I " "don't know", } self.url = reverse("queries:goods_queries:goods_queries")
def to_internal_value(self, data): try: return get_control_list_entry(data) except NotFoundError: raise serializers.ValidationError( strings.Goods.CONTROL_LIST_ENTRY_IVALID)