Exemplo n.º 1
0
def update_country_data():
    from geodata.importer.country import CountryImport
    ci = CountryImport()
    ci.update_country_center()
    ci.update_polygon()
    ci.update_regions()
    ci.update_alt_name()
class CountryImportTestCase(TestCase):

    def setUp(self):
        self.country_import = CountryImport()
        self.country = CountryFactory.create(code="AF")

    def test_update_polygon(self):

        data = {
            "type": "FeatureCollection", "features": [{
                "type": "Feature",
                "id": "AFG",
                "properties": {
                    "name": "Afghanistan",
                    "iso2": "AF"
                },
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [
                        [[61.210817, 35.650072], [62.230651, 35.270664]]
                    ]}},
            ]}
        self.country_import.get_json_data = MagicMock(return_value=data)
        self.country_import.update_polygon()

        self.assertEqual(1, self.country_import.get_json_data.call_count)
        self.assertEqual(1, Country.objects.all().count())
        country = Country.objects.all()[0]

        self.assertIsNotNone(country.polygon)
        self.assertEqual(country.code, self.country.code)

    def test_update_country_center(self):
        data = {"AF": {"latitude": "42.30", "longitude": "1.30"}, }
        self.country_import.get_json_data = MagicMock(return_value=data)
        self.country_import.update_country_center()
        country = Country.objects.all()[0]
        self.assertEqual(country.center_longlat.y, 42.3)
        self.assertEqual(country.center_longlat.x, 1.3)

    def test_update_regions(self):
        rv = vocabulary_factory.RegionVocabularyFactory()

        region = RegionFactory.create(code='689', region_vocabulary=rv)
        data = [{
            "country_name": "Afghanistan",
            "iso2": "AF",
            "dac_region_code": "689",
        }, ]
        self.country_import.get_json_data = MagicMock(return_value=data)
        self.country_import.update_regions()
        country = Country.objects.all()[0]
        self.assertEqual(country.region, region)
Exemplo n.º 3
0
class CountryImportTestCase(TestCase):

    def setUp(self):
        self.country_import = CountryImport()
        self.country = CountryFactory.create(code="AF")

    def test_update_polygon(self):

        data = {
            "type": "FeatureCollection", "features": [{
                "type": "Feature",
                "id": "AFG",
                "properties": {
                    "name": "Afghanistan",
                    "iso2": "AF"
                },
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [
                        [[61.210817, 35.650072], [62.230651, 35.270664]]
                    ]}},
            ]}
        self.country_import.get_json_data = MagicMock(return_value=data)
        self.country_import.update_polygon()

        self.assertEqual(1, self.country_import.get_json_data.call_count)
        self.assertEqual(1, Country.objects.all().count())
        country = Country.objects.all()[0]

        self.assertIsNotNone(country.polygon)
        self.assertEqual(country.code, self.country.code)

    def test_update_country_center(self):
        data = {"AF": {"latitude": "42.30", "longitude": "1.30"}, }
        self.country_import.get_json_data = MagicMock(return_value=data)
        self.country_import.update_country_center()
        country = Country.objects.all()[0]
        self.assertEqual(country.center_longlat.y, 42.3)
        self.assertEqual(country.center_longlat.x, 1.3)

    def test_update_regions(self):
        region = RegionFactory.create(code='689')
        data = [{
            "country_name": "Afghanistan",
            "iso2": "AF",
            "dac_region_code": "689",
        }, ]
        self.country_import.get_json_data = MagicMock(return_value=data)
        self.country_import.update_regions()
        country = Country.objects.all()[0]
        self.assertEqual(country.region, region)
Exemplo n.º 4
0
from geodata.importer.country import CountryImport
# from geodata.importer.region import RegionImport
from geodata.importer.subnational import SubnationalImport

# print('Region data')
# ri = RegionImport()
# ri.update_region_center()

print('Country data')
ci = CountryImport()
ci.update_polygon()
ci.update_alt_name()
ci.update_country_center()
ci.update_regions()
ci.update_hd_polygons()
ci.update_region_polygons_centers()

print('Subnational data')
si = SubnationalImport()
si.update_polygon()
si.update_kenya()
si.update_kenya_county_centers()
Exemplo n.º 5
0
def update_country_data():
    from geodata.importer.country import CountryImport
    ci = CountryImport()
    ci.update_country_center()
    ci.update_polygon()
    ci.update_regions()