def setUpTestData(cls): cls.traveler = UserFactory() cls.unicef_staff = UserFactory(is_staff=True) cls.travel = TravelFactory( reference_number=make_travel_reference_number(), traveler=cls.traveler, supervisor=cls.unicef_staff)
def setUp(self): self.unicef_staff = UserFactory(is_staff=True) self.unicef_superuser = UserFactory(is_superuser=True) self.partnership_manager_user = UserFactory(is_staff=True) self.group = GroupFactory() self.partnership_manager_user.groups.add(self.group) self.url = reverse('users_v2:myprofile-detail')
def setUpTestData(cls): cls.traveler = UserFactory(is_staff=True) cls.unicef_staff = UserFactory(is_staff=True) workspace = cls.unicef_staff.profile.country workspace.threshold_tae_usd = 100 workspace.threshold_tre_usd = 100 workspace.save()
def setUpTestData(cls): business_area = PublicsBusinessAreaFactory() cls.traveler = UserFactory(is_staff=True) cls.traveler.profile.vendor_number = 'usrvnd' cls.traveler.profile.save() workspace = cls.traveler.profile.country workspace.business_area_code = business_area.code workspace.save() cls.unicef_staff = UserFactory(is_staff=True) cls.travel = TravelFactory( reference_number=make_travel_reference_number(), traveler=cls.traveler, supervisor=cls.unicef_staff, start_date=datetime(2017, 4, 4, 12, 00, tzinfo=UTC), end_date=datetime(2017, 4, 14, 16, 00, tzinfo=UTC)) cls.travel.expenses.all().delete() ItineraryItemFactory(travel=cls.travel) ItineraryItemFactory(travel=cls.travel) cls.travel.submit_for_approval() cls.travel.approve() cls.travel.send_for_payment() cls.travel.save()
def setUp(self): self.unicef_staff = UserFactory(is_staff=True) self.unicef_superuser = UserFactory(is_superuser=True) self.partnership_manager_user = UserFactory(is_staff=True) self.group = GroupFactory() self.partnership_manager_user.groups.add(self.group) self.url = reverse("users_v3:users-list")
def setUpTestData(cls): cls.code_1 = "test_code_1" cls.file_type_1 = AttachmentFileTypeFactory(code=cls.code_1) cls.code_2 = "test_code_2" cls.file_type_2 = AttachmentFileTypeFactory(code=cls.code_2) cls.unicef_staff = UserFactory(is_staff=True) cls.user = UserFactory() cls.url = reverse("attachments:list") cls.attachment_1 = AttachmentFactory( file_type=cls.file_type_1, code=cls.code_1, file="sample1.pdf", content_object=cls.file_type_1, uploaded_by=cls.unicef_staff ) cls.attachment_2 = AttachmentFactory( file_type=cls.file_type_2, code=cls.code_2, file="sample2.pdf", content_object=cls.file_type_2, uploaded_by=cls.user ) cls.partner = PartnerFactory( partner_type=PartnerType.UN_AGENCY, vendor_number="V123", ) cls.agreement = AgreementFactory(partner=cls.partner) cls.assessment = AssessmentFactory(partner=cls.partner) cls.amendment = AgreementAmendmentFactory(agreement=cls.agreement) cls.intervention = InterventionFactory(agreement=cls.agreement) cls.result_link = InterventionResultLinkFactory( intervention=cls.intervention ) cls.intervention_amendment = InterventionAmendmentFactory( intervention=cls.intervention ) cls.intervention_attachment = InterventionAttachmentFactory( intervention=cls.intervention ) cls.tpm_partner = SimpleTPMPartnerFactory(vendor_number="V432") cls.tpm_visit = TPMVisitFactory(tpm_partner=cls.tpm_partner) cls.tpm_activity = TPMActivityFactory( partner=cls.partner, intervention=cls.intervention, tpm_visit=cls.tpm_visit ) cls.engagement = EngagementFactory(partner=cls.partner) cls.default_partner_response = [{ "partner": "", "partner_type": "", "vendor_number": "", "pd_ssfa_number": "", "agreement_reference_number": "", "source": "", }] * 2
def setUp(self): self.author = UserFactory() self.assignee = UserFactory() self.assigned_by = UserFactory() self.action_point = ActionPointFactory(status=self.status, author=self.author, assigned_by=self.assigned_by, assigned_to=self.assignee)
def setUpTestData(cls): cls.traveler = UserFactory(first_name='John', last_name='Doe') cls.unicef_staff = UserFactory(first_name='Max', last_name='Mustermann', is_staff=True) cls.travel = TravelFactory(traveler=cls.traveler, supervisor=cls.unicef_staff) cls.due_date = (datetime.now() + timedelta(days=1)).isoformat() mail.outbox = []
def setUpTestData(cls): group1 = GroupFactory(name='Group1') group2 = GroupFactory(name='Group2') cls.user1 = UserFactory(username='******') cls.user2 = UserFactory(username='******') cls.user1.groups = [group1] cls.user2.groups = [group2] Permission.objects.bulk_create([ Permission(user_type='Group1', permission='edit', target='parent.field'), Permission(user_type='Group1', permission='edit', target='parent.children2'), Permission(user_type='Group1', permission='edit', target='child2.field'), Permission(user_type='Group1', permission='view', target='child2.field2'), Permission(user_type='Group2', permission='view', target='parent.field'), Permission(user_type='Group2', permission='view', target='parent.children2'), Permission(user_type='Group2', permission='edit', target='child2.field2'), ]) class Child2Serializer(PermissionsBasedSerializerMixin, WritableNestedSerializerMixin, serializers.ModelSerializer): class Meta(PermissionsBasedSerializerMixin.Meta, WritableNestedSerializerMixin.Meta): model = Child2 fields = ['id', 'field'] permission_class = Permission class ParentSerializer(PermissionsBasedSerializerMixin, WritableNestedSerializerMixin, serializers.ModelSerializer): children2 = Child2Serializer(many=True) class Meta(PermissionsBasedSerializerMixin.Meta, WritableNestedSerializerMixin.Meta): model = Parent fields = ['id', 'field', 'children2'] permission_class = Permission cls.ParentSerializer = ParentSerializer
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.traveler = UserFactory() profile = cls.traveler.profile profile.vendor_number = 'user0001' profile.save() country = profile.country country.business_area_code = '0060' country.save()
def setUpTestData(cls): group1 = GroupFactory(name='Group1') group2 = GroupFactory(name='Group2') cls.user1 = UserFactory(username='******') cls.user2 = UserFactory(username='******') cls.user3 = UserFactory(username='******') cls.user1.groups = [group1] cls.user2.groups = [group2] cls.user3.groups = [group1, group2]
def test_no_permission(self): response = self.forced_auth_req( 'get', reverse("management_gis:locations-gis-geom-list"), user=UserFactory()) self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN) response = self.forced_auth_req( 'get', reverse("management_gis:locations-gis-in-use"), user=UserFactory()) self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN)
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.traveler1 = UserFactory() cls.traveler2 = UserFactory() cls.travel = TravelFactory( reference_number=make_travel_reference_number(), traveler=cls.traveler1, status=Travel.APPROVED, supervisor=cls.unicef_staff) # to filter against cls.travel_activity = TravelActivityFactory( primary_traveler=cls.traveler1) cls.travel_activity.travels.add(cls.travel)
def setUp(self): self.unicef_staff = UserFactory(is_superuser=True) group = GroupFactory() self.unicef_staff.groups.add(group) # The tested endpoints require the country id in the query string self.country = CountryFactory() self.unicef_staff.profile.country = self.country self.unicef_staff.save() self.location_no_geom = LocationFactory(name="Test no geom") self.location_with_geom = LocationFactory( name="Test with geom", geom="MultiPolygon(((10 10, 10 20, 20 20, 20 15, 10 10)), ((10 10, 10 20, 20 20, 20 15, 10 10)))" )
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.partner = PartnerFactory( partner_type=PartnerType.CIVIL_SOCIETY_ORGANIZATION, cso_type="International", hidden=False, vendor_number="DDD", short_name="Short name", ) cls.partner_staff = PartnerStaffFactory(partner=cls.partner) cls.partnership_manager_user = UserFactory(is_staff=True) cls.partnership_manager_user.groups.add(GroupFactory()) cls.partnership_manager_user.profile.partner_staff_member = cls.partner_staff.id cls.partnership_manager_user.save()
def setUpTestData(cls): cls.traveler = UserFactory(first_name='Jane', last_name='Doe') cls.traveler.profile.vendor_number = 'usrvnd' cls.traveler.profile.save() cls.unicef_staff = UserFactory(is_staff=True, first_name='John', last_name='Doe') cls.travel = TravelFactory(traveler=cls.traveler, supervisor=cls.unicef_staff) ItineraryItemFactory(travel=cls.travel) ItineraryItemFactory(travel=cls.travel) mail.outbox = []
def test_get(self): user = UserFactory(is_staff=True) response = self.forced_auth_req("get", reverse("users_v3:country-detail"), user=user) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data[0]["id"], user.profile.country.pk)
def test_staff_has_access(self): '''Ensure a staff user has access''' response = self.forced_auth_req('get', self.url, user=UserFactory(is_staff=True), data=self.query_param_data) self.assertEquals(response.status_code, status.HTTP_200_OK)
def test_get(self): self.user = UserFactory() response = self.forced_auth_req("get", reverse("users:user-api-profile"), user=self.user) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["id"], self.user.pk)
def test_get_no_result(self): user = UserFactory(is_staff=True, profile__country=None) response = self.forced_auth_req("get", reverse("users_v3:country-detail"), user=user) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 0)
def setUp(self): super().setUp() self.unicef_staff = UserFactory(is_staff=True) self.header = FundsCommitmentHeaderFactory( vendor_code="Vendor Code", fc_number="FC001", )
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) partner = PartnerFactory( partner_type='Government', vendor_number='Vendor No', short_name="Short Name", alternate_name="Alternate Name", shared_with=["DPKO", "ECA"], address="Address 123", phone_number="Phone no 1234567", email="*****@*****.**", rating="High", core_values_assessment_date=datetime.date.today(), total_ct_cp=10000, total_ct_cy=20000, deleted_flag=False, blocked=False, type_of_assessment="Type of Assessment", last_assessment_date=datetime.date.today(), ) partnerstaff = PartnerStaffFactory(partner=partner) cls.agreement = AgreementFactory( partner=partner, country_programme=CountryProgrammeFactory(wbs="random WBS"), attached_agreement="fake_attachment.pdf", start=datetime.date.today(), end=datetime.date.today(), signed_by_unicef_date=datetime.date.today(), signed_by=cls.unicef_staff, signed_by_partner_date=datetime.date.today() ) cls.agreement.authorized_officers.add(partnerstaff) cls.agreement.save()
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.result_link = InterventionResultLinkFactory() cls.lower_result = LowerResultFactory(result_link=cls.result_link) cls.indicator = IndicatorBlueprintFactory() cls.applied = AppliedIndicatorFactory(indicator=cls.indicator, lower_result=cls.lower_result)
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.intervention = InterventionFactory() cls.result_link = InterventionResultLinkFactory() cls.lower_result = LowerResultFactory( name="LL Name", result_link=cls.result_link, ) cls.indicator = IndicatorBlueprintFactory() AppliedIndicatorFactory( context_code="CC321", indicator=cls.indicator, lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link), cluster_name='ABC', ) AppliedIndicatorFactory( context_code="CC321", indicator=cls.indicator, lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link), cluster_name='XYZ', ) AppliedIndicatorFactory( context_code="CC321", indicator=cls.indicator, lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link), cluster_name='XYZ', ) AppliedIndicatorFactory( context_code="CC321", indicator=cls.indicator, lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link), ) cls.url = reverse("reports:cluster")
def setUpTestData(cls): cls.user = UserFactory( email="*****@*****.**", first_name="First", middle_name="Middle", last_name="Last", )
def setUpTestData(cls): cls.url = reverse("partners_api:partner-hact") cls.unicef_staff = UserFactory(is_staff=True) cls.partner = PartnerFactory( total_ct_cp=10.00, total_ct_cy=8.00, )
def setUpTestData(cls): cls.user = UserFactory(is_staff=True) # UNICEF staff user cls.result_type = ResultTypeFactory(name=ResultType.OUTPUT) today = datetime.date.today() cls.country_programme = CountryProgrammeFactory( wbs='0000/A0/01', from_date=datetime.date(today.year - 1, 1, 1), to_date=datetime.date(today.year + 1, 1, 1)) cls.result1 = ResultFactory( result_type=cls.result_type, country_programme=cls.country_programme, ) cls.result2 = ResultFactory( result_type=cls.result_type, country_programme=cls.country_programme ) cls.outcome = ResultFactory( result_type=ResultTypeFactory(name=ResultType.OUTCOME), country_programme=cls.country_programme ) cls.url = reverse('reports:report-result-list')
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.partner = PartnerFactory( partner_type=PartnerType.UN_AGENCY, vendor_number='Vendor No', short_name="Short Name", alternate_name="Alternate Name", shared_with=["DPKO", "ECA"], address="Address 123", phone_number="Phone no 1234567", email="*****@*****.**", rating="High", core_values_assessment_date=datetime.date.today(), total_ct_cp=10000, total_ct_cy=20000, total_ct_ytd=30000, deleted_flag=False, blocked=False, type_of_assessment="Type of Assessment", last_assessment_date=datetime.date.today(), hact_values= '{"outstanding_findings": 0, "audits": {"completed": 0, "minimum_requirements": 0}, "programmatic_visits": {"completed": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}, "planned": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}}, "spot_checks": {"completed": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}, "planned": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}, "follow_up_required": 0}}', ) cls.partnerstaff = PartnerStaffFactory(partner=cls.partner) cls.planned_visit = PartnerPlannedVisitsFactory(partner=cls.partner)
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.partner = PartnerFactory( partner_type=PartnerType.UN_AGENCY, vendor_number='Vendor No', short_name="Short Name", alternate_name="Alternate Name", shared_with=["DPKO", "ECA"], address="Address 123", phone_number="Phone no 1234567", email="*****@*****.**", rating=PartnerOrganization.RATING_HIGH, core_values_assessment_date=datetime.date.today(), total_ct_cp=10000, total_ct_cy=20000, net_ct_cy=100.0, reported_cy=300.0, total_ct_ytd=400.0, deleted_flag=False, blocked=False, type_of_assessment="Type of Assessment", last_assessment_date=datetime.date.today(), ) cls.partnerstaff = PartnerStaffFactory(partner=cls.partner) attachment = tempfile.NamedTemporaryFile(suffix=".pdf").name cls.agreement = AgreementFactory( partner=cls.partner, country_programme=CountryProgrammeFactory(wbs="random WBS"), attached_agreement=attachment, start=datetime.date.today(), end=datetime.date.today(), signed_by_unicef_date=datetime.date.today(), signed_by=cls.unicef_staff, signed_by_partner_date=datetime.date.today()) cls.agreement.authorized_officers.add(cls.partnerstaff) cls.agreement.save() # This is here to test partner scoping AgreementFactory(signed_by_unicef_date=datetime.date.today()) cls.intervention = InterventionFactory( agreement=cls.agreement, document_type='SHPD', status='draft', start=datetime.date.today(), end=datetime.date.today(), submission_date=datetime.date.today(), submission_date_prc=datetime.date.today(), review_date_prc=datetime.date.today(), signed_by_unicef_date=datetime.date.today(), signed_by_partner_date=datetime.date.today(), unicef_signatory=cls.unicef_staff, population_focus="Population focus", partner_authorized_officer_signatory=cls.partnerstaff, country_programme=cls.agreement.country_programme, ) cls.ib = InterventionBudgetFactory(intervention=cls.intervention, currency="USD") cls.planned_visit = PartnerPlannedVisitsFactory(partner=cls.partner) output_res_type, _ = ResultType.objects.get_or_create(name='Output') cls.result = ResultFactory(result_type=output_res_type)
def test_get_exists(self): user = UserFactory() token, _ = Token.objects.get_or_create(user=user) self.client.force_login(user) response = self.client.get(reverse("tokens:get")) self.assertEquals(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data, {"token": token.key})
def setUp(self): super().setUp() self.unicef_staff = UserFactory(is_superuser=True) group = GroupFactory() self.unicef_staff.groups.add(group) self.country = CountryFactory() self.unicef_staff.profile.country = self.country self.unicef_staff.save() self.partner = PartnerFactory() self.agreement = AgreementFactory(partner=self.partner) self.intervention = InterventionFactory(agreement=self.agreement) self.location_no_geom = LocationFactory(name="Test no geom") self.location_with_geom = LocationFactory( name="Test with geom", geom="MultiPolygon(((10 10, 10 20, 20 20, 20 15, 10 10)), ((10 10, 10 20, 20 20, 20 15, 10 10)))" ) self.inactive_location = LocationFactory(is_active=False) self.locations = [self.location_no_geom, self.location_with_geom]
class TestGisLocationViews(BaseTenantTestCase): def setUp(self): super().setUp() self.unicef_staff = UserFactory(is_superuser=True) group = GroupFactory() self.unicef_staff.groups.add(group) self.country = CountryFactory() self.unicef_staff.profile.country = self.country self.unicef_staff.save() self.partner = PartnerFactory() self.agreement = AgreementFactory(partner=self.partner) self.intervention = InterventionFactory(agreement=self.agreement) self.location_no_geom = LocationFactory(name="Test no geom") self.location_with_geom = LocationFactory( name="Test with geom", geom="MultiPolygon(((10 10, 10 20, 20 20, 20 15, 10 10)), ((10 10, 10 20, 20 20, 20 15, 10 10)))" ) self.inactive_location = LocationFactory(is_active=False) self.locations = [self.location_no_geom, self.location_with_geom] def assertGeomListResponseFundamentals(self, response, response_len, expected_keys=None): """ Assert common fundamentals about the response. """ self.assertEquals(response.status_code, status.HTTP_200_OK) if not expected_keys: expected_keys = ["features", "type"] self.assertEqual(sorted(response.data.keys()), expected_keys) # see if the response is a valid GeoJson self.assertEqual(response.data["type"], "FeatureCollection") self.assertEqual(len(response.data['features']), response_len) if len(response.data['features']) > 0: for feature in response.data['features']: self.assertKeysIn(['id', 'type', 'geometry', 'properties'], feature) def test_no_permission(self): response = self.forced_auth_req('get', reverse("management_gis:locations-gis-geom-list"), user=UserFactory()) self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN) response = self.forced_auth_req('get', reverse("management_gis:locations-gis-in-use"), user=UserFactory()) self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN) def test_invalid_geoformat(self): url = reverse("management_gis:locations-gis-geom-list") response = self.forced_auth_req( "get", url, # geo_format should be either geojson or wkt user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "whatever"}, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) url = reverse("management_gis:locations-gis-get-by-pcode", kwargs={"pcode": self.location_with_geom.p_code}) response = self.forced_auth_req("get", url, user=self.unicef_staff) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) url = reverse("management_gis:locations-gis-get-by-id", kwargs={"id": self.location_with_geom.id}) response = self.forced_auth_req("get", url, user=self.unicef_staff) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_locations_in_use(self): url = reverse("management_gis:locations-gis-in-use") # test with missing country, expect error response = self.forced_auth_req("get", url, user=self.unicef_staff) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) response = self.forced_auth_req( "get", reverse("management_gis:locations-gis-in-use"), user=self.unicef_staff, data={"country_id": self.country.id}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) # see if no location are in use yet self.assertEqual(len(response.data), 0) def test_travel_locations_in_use(self): travel = TravelFactory( traveler=self.unicef_staff, status=Travel.COMPLETED, ) travel_activity = TravelActivityFactory( travels=[travel], primary_traveler=self.unicef_staff, travel_type=TravelType.SPOT_CHECK, ) travel_activity.locations.add(self.location_no_geom.id, self.location_with_geom.id) travel_activity.save() response = self.forced_auth_req( "get", reverse("management_gis:locations-gis-in-use"), user=self.unicef_staff, data={"country_id": self.country.id}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(sorted(response.data[0].keys()), ["gateway_id", "id", "level", "name", "p_code", "parent_id"]) def test_intervention_locations_in_use(self): # add intervention locations and test the response intervention = InterventionFactory(status=Intervention.SIGNED) intervention.flat_locations.add(self.location_no_geom, self.location_with_geom) intervention.save() response = self.forced_auth_req( "get", reverse("management_gis:locations-gis-in-use"), user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "whatever"}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(sorted(response.data[0].keys()), ["gateway_id", "id", "level", "name", "p_code", "parent_id"]) def test_activities_in_use(self): activity = Activity( partner=self.partner, intervention=self.intervention ) activity.save() activity.locations.add(*self.locations) response = self.forced_auth_req( "get", reverse("management_gis:locations-gis-in-use"), user=self.unicef_staff, data={"country_id": self.country.id}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) self.assertEqual(sorted(response.data[0].keys()), ["gateway_id", "id", "level", "name", "p_code", "parent_id"]) def test_action_points_in_use(self): ActionPointFactory( location=self.location_no_geom ) response = self.forced_auth_req( "get", reverse("management_gis:locations-gis-in-use"), user=self.unicef_staff, data={"country_id": self.country.id}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) self.assertEqual(sorted(response.data[0].keys()), ["gateway_id", "id", "level", "name", "p_code", "parent_id"]) def test_intervention_locations_geom_bad_request(self): url = reverse("management_gis:locations-gis-geom-list") # test with no country in the query string, expect error response = self.forced_auth_req("get", url, user=self.unicef_staff) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_intervention_locations_geom(self): url = reverse("management_gis:locations-gis-geom-list") # test with no format filter, we should expect GeoJson in the response response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id}, ) # expect all 3(2 active + 1 inactive) locations in the response self.assertGeomListResponseFundamentals(response, 3) def test_intervention_locations_geom_status_all(self): url = reverse("management_gis:locations-gis-geom-list") response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, 'status': 'all'}, ) # expect all 3(2 active + 1 inactive) locations in the response self.assertGeomListResponseFundamentals(response, 3) def test_intervention_locations_geom_status_active(self): url = reverse("management_gis:locations-gis-geom-list") response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, 'status': 'active'}, ) # expect 2 active locations in the response self.assertGeomListResponseFundamentals(response, 2) def test_intervention_locations_geom_status_archived(self): # test with missing country in the query string, expect error url = reverse("management_gis:locations-gis-geom-list") response = self.forced_auth_req("get", url, user=self.unicef_staff) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, 'status': 'archived'}, ) # expect 1 archived location in the response self.assertGeomListResponseFundamentals(response, 1) def test_intervention_locations_geom_geojson(self): url = reverse("management_gis:locations-gis-geom-list") # test with GEOJSON format response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "geojson", "geom_type": "polygon"}, ) # expect 1 active polygon location in the response self.assertGeomListResponseFundamentals(response, 1) def test_intervention_locations_geom_wkt(self): url = reverse("management_gis:locations-gis-geom-list") # test with WKT format response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "wkt", "geom_type": "polygon"}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) # only one of the test locations has GEOM self.assertEqual(len(response.data), 1) self.assertEqual( sorted(response.data[0].keys()), ["gateway_id", "geom", "id", "level", "name", "p_code", "parent_id", "point"] ) self.assertEqual(response.data[0]["geom"], self.location_with_geom.geom.wkt) def test_intervention_locations_geom_by_pcode(self): url = reverse("management_gis:locations-gis-get-by-pcode", kwargs={"pcode": self.location_with_geom.p_code}) # test with missing country, expect error response = self.forced_auth_req("get", url, user=self.unicef_staff) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # request the result in WKT response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "wkt"}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( sorted(response.data.keys()), ["gateway_id", "geom", "id", "level", "name", "p_code", "parent_id", "point"] ) self.assertEqual(response.data["id"], str(self.location_with_geom.id)) self.assertEqual(response.data["geom"], self.location_with_geom.geom.wkt) # request the result in GeoJson response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "geojson"}, ) # see if the response is a valid Feature self.assertKeysIn(['id', 'type', 'geometry', 'properties'], response.data) self.assertEqual(response.data["type"], "Feature") self.assertEqual(response.data["geometry"]['type'], 'MultiPolygon') # TODO: check returned coordinates, and add 1 more test with POINT() returned self.assertIsNotNone(response.data["geometry"]['coordinates']) def test_intervention_locations_geom_by_id(self): url = reverse("management_gis:locations-gis-get-by-id", kwargs={"id": self.location_with_geom.id}) # test with missing country, expect error response = self.forced_auth_req("get", url, user=self.unicef_staff) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # request the result in WKT response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "wkt"}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( sorted(response.data.keys()), ["gateway_id", "geom", "id", "level", "name", "p_code", "parent_id", "point"] ) self.assertEqual(response.data["id"], str(self.location_with_geom.id)) self.assertEqual(response.data["geom"], self.location_with_geom.geom.wkt) # request the result in GeoJson response = self.forced_auth_req( "get", url, user=self.unicef_staff, data={"country_id": self.country.id, "geo_format": "geojson"}, ) # see if the response is a valid Feature self.assertKeysIn(['id', 'type', 'geometry', 'properties'], response.data) self.assertEqual(response.data["type"], "Feature") self.assertEqual(response.data["geometry"]['type'], 'MultiPolygon') # TODO: check returned coordinates, and add 1 more test with POINT() returned self.assertIsNotNone(response.data["geometry"]['coordinates'])