예제 #1
0
    def loop_through_codelists(self, version):
        downloaded_xml = urllib.request.Request(
            "http://reference.iatistandard.org/" + version.replace('.', '') +
            "/codelists/downloads/clv1/codelist.xml")

        file_opener = urllib.request.build_opener()
        xml_file = file_opener.open(downloaded_xml)
        context = etree.iterparse(xml_file, tag='codelist')
        # This updates / creates new Codelist objects (name argument is not
        # passed to 'get_codelist_data') AND adds Codelist items:
        self.fast_iter(context, self.get_codelist_data)
        self.add_missing_items()

        # XXX: where are these used?
        dsi = DacSectorImporter()
        dsi.update()

        # These look like Unesco-specific Sectors, but despite the fact
        # that they are not in IATI (we can not parse them), they are
        # (will be) used globally, so we have to keep them in OIPA:
        ssi = SdgSectorImporter()
        ssi.update()

        # Added M49 Regions if available
        M49RegionsImporter()
예제 #2
0
    def test_m49_regions_importer_region_should_empty(self):
        # If DATA_PLUGINS is just empty dictionary then not import anything
        # Override DATA_PLUGINS settings

        regions_before = Region.objects.count()

        with self.settings(DATA_PLUGINS={}):
            M49RegionsImporter()

        regions_after = Region.objects.count()

        # The Region should be empty
        self.assertEqual(regions_before, regions_after)
예제 #3
0
    def test_m49_regions_importer_should_ok(self):
        # Region is needed a vocabulary region
        RegionVocabulary(code='2', name='UN').save()

        os.path.dirname(iati_synchroniser.__file__)

        filename = '{app_path}/{file_path}'.format(
            app_path=os.path.dirname(iati_synchroniser.__file__),
            file_path='fixtures/test_m49_regions.json')
        M49RegionsImporter(filename=filename)

        # The name of code '1' should be 'World'
        # Check the fixture file on 'fixtures/test_m49_regions.json'
        region = Region.objects.get(code='1')

        self.assertEqual(region.name, 'World')
예제 #4
0
    def loop_through_codelists(self, version):
        codelist_file_url = (
            "http://reference.iatistandard.org/"
            + version.replace('.', '') +
            "/codelists/downloads/clv3/codelists.xml")

        response = self.get_xml(codelist_file_url)
        context = etree.iterparse(response, tag='codelist')

        # This updates / creates new Codelist objects (name argument is not
        # passed to 'get_codelist_data') AND adds Codelist items:
        self.fast_iter(context, self.get_codelist_data, None)
        self.add_missing_items()

        # XXX: where are these used?
        dsi = DacSectorImporter()
        dsi.update()

        # These look like Unesco-specific Sectors, but despite the fact
        # that they are not in IATI (we can not parse them), they are
        # (will be) used globally, so we have to keep them in OIPA:
        ssi = SdgSectorImporter()
        ssi.update()

        humanitarian_global_clusters = GlobalClustersSectorImporter()
        humanitarian_global_clusters.update()

        # aid-type codes for vocab-3
        aid_type_codes_importer = AidTypeVocab3Importer()
        aid_type_codes_importer.update()

        # vocabulary 7 codes
        vocab7_importer = Vocab7Importer()
        vocab7_importer.update()

        # Added M49 Regions if available
        M49RegionsImporter()