예제 #1
0
    def test_activities_endpoint_by_reporting_organisation(self):
        '''Tests if Activities endpoint works properly when having
        organisation identifier as a query parameter
        '''
        publisher = PublisherFactory()
        organisation = publisher.organisation
        reporting_organisation = iati_factory.ActivityReportingOrganisationFactory(  # NOQA: E501
            organisation=organisation,
            # This is the query param:
            ref=organisation.organisation_identifier
        )

        url = reverse('activities:activity-list')
        endpoint_url = "%s?format=json&reporting_organisation_identifier=%s" % (  # NOQA: E501
            url, reporting_organisation.ref
        )

        response = self.c.get(endpoint_url)
        self.assertEqual(response.status_code, 200)

        resp_data = json.loads(response.content)
        self.assertEqual(resp_data['count'], 1)
        self.assertEqual(
            resp_data['results'][0]['iati_identifier'],
            reporting_organisation.activity.iati_identifier
        )
예제 #2
0
    def test_activities_endpoint_by_multiple_reporting_organisations(self):
        '''Tests if Activities endpoint works properly when having multiple
        organisation identifiers as a query parameter
        '''
        first_publisher = PublisherFactory()

        first_organisation = first_publisher.organisation
        second_organisation = iati_factory.OrganisationFactory(
            organisation_identifier='different_organisation_ID'
        )

        first_reporting_organisation = iati_factory.ActivityReportingOrganisationFactory(  # NOQA: E501
            organisation=first_organisation,
            # This is the query param:
            ref=first_organisation.organisation_identifier,
            activity=iati_factory.ActivityFactory(
                iati_identifier='A'
            )
        )
        second_reporting_organisation = iati_factory.ActivityReportingOrganisationFactory(  # NOQA: E501
            organisation=second_organisation,
            ref=second_organisation.organisation_identifier,
            activity=iati_factory.ActivityFactory(iati_identifier='B')
        )

        url = reverse('activities:activity-list')
        endpoint_url = "%s?format=json&reporting_organisation_identifier=%s,%s" % (  # NOQA: E501
            url,
            first_reporting_organisation.ref,
            second_reporting_organisation.ref
        )

        response = self.c.get(endpoint_url)
        self.assertEqual(response.status_code, 200)

        resp_data = json.loads(response.content)
        self.assertEqual(resp_data['count'], 2)

        self.assertEqual(
            resp_data['results'][0]['iati_identifier'],
            first_reporting_organisation.activity.iati_identifier
        )

        self.assertEqual(
            resp_data['results'][1]['iati_identifier'],
            second_reporting_organisation.activity.iati_identifier
        )