Esempio n. 1
0
    def test_update_or_create_publisher_organisation(self):
        """
        check if dataset is saved as expected
        """

        # setup
        publisher = synchroniser_factory.PublisherFactory.create(
            organisation=None)
        publisher_organization_type = "22"

        # call
        create_publisher_organisation(publisher, publisher_organization_type)

        # prepare
        publisher.refresh_from_db()
        organisation = Organisation.objects.get(
            organisation_identifier=publisher.publisher_iati_id)

        # assert
        self.assertEqual(publisher.publisher_iati_id,
                         organisation.organisation_identifier)
        self.assertEqual(publisher.display_name,
                         organisation.name.narratives.first().content)
        self.assertEqual(publisher_organization_type, organisation.type.code)
        self.assertEqual(publisher.publisher_iati_id,
                         organisation.reporting_org.reporting_org_identifier)
        self.assertEqual(publisher.display_name,
                         organisation.reporting_org.narratives.first().content)
Esempio n. 2
0
    def update_or_create_publisher(self, publisher):
        """

        """
        if publisher['package_count'] == 0:
            package_count = None
        else:
            package_count = publisher['package_count']

        obj, created = Publisher.objects.update_or_create(
            iati_id=publisher['id'],
            defaults={
                'publisher_iati_id': publisher['publisher_iati_id'],
                'name': publisher['name'],
                'display_name': publisher['title'],
                'package_count': package_count,
            })

        if not Organisation.objects.filter(
                organisation_identifier=publisher['publisher_iati_id']).exists(
                ):
            create_publisher_organisation(
                obj, publisher['publisher_organization_type'])

        return obj
    def test_update_or_create_publisher_organisation(self):
        """
        check if dataset is saved as expected
        """

        # setup
        publisher = synchroniser_factory.PublisherFactory.create(
            organisation=None)
        publisher_organization_type = "22"

        # call
        create_publisher_organisation(publisher, publisher_organization_type)

        # prepare
        publisher.refresh_from_db()
        organisation = Organisation.objects.get(
            organisation_identifier=publisher.publisher_iati_id)

        # assert
        self.assertEqual(publisher.publisher_iati_id,
                         organisation.organisation_identifier)
        self.assertEqual(publisher.display_name,
                         organisation.name.narratives.first().content)
        self.assertEqual(publisher_organization_type, organisation.type.code)
        self.assertEqual(publisher.publisher_iati_id,
                         organisation.reporting_org.reporting_org_identifier)
        self.assertEqual(publisher.display_name,
                         organisation.reporting_org.narratives.first().content)
Esempio n. 4
0
    def handle(self, *args, **options):
        publisher, created = Publisher.objects.update_or_create(
            iati_id=options['identifier'][0],
            defaults={
                'publisher_iati_id': options['identifier'][0],
                'name': options['name'][0],
                'display_name': options['name'][0]
            })

        publisher.save()
        create_publisher_organisation(publisher, options['identifier'][0],
                                      options['name'][0],
                                      options['organisation_type'][0])
Esempio n. 5
0
    def update_or_create_publisher(self, publisher):
        """

        """
        obj, created = Publisher.objects.update_or_create(
            iati_id=publisher['id'],
            defaults={
                'publisher_iati_id': publisher['publisher_iati_id'],
                'name': publisher['name'],
                'display_name': publisher['title']
            }
        )

        if not Organisation.objects.filter(
                organisation_identifier=publisher[
                    'publisher_iati_id'
                ]).exists():
            create_publisher_organisation(
                obj,
                publisher['publisher_organization_type']
            )

        return obj