예제 #1
0
    def test_duplicate_results(self):
        """Test that in case mapbox API returns a region already stored in DB
        with diferrent mapbox_id, we gracefully update all entries and foreign keys
        with the latest mapbox data."""

        region = RegionFactory.create(mapbox_id='42')
        user = UserFactory.create(userprofile={'geo_region': region})
        result = {
            'province': {
                'name': region.name,
                'id': '24'
            }
        }

        result_to_region(result, region.country)
        lookup_args = {
            'name': region.name,
            'country': region.country
        }

        region_qs = Region.objects.filter(**lookup_args)
        ok_(region_qs.count(), 1)
        eq_(region_qs[0].mapbox_id, '24')
        ok_(not Region.objects.filter(mapbox_id='42').exists())

        userprofile = UserProfile.objects.get(pk=user.userprofile.id)
        eq_(userprofile.geo_region.name, region.name)
        eq_(userprofile.geo_region.mapbox_id, '24')
예제 #2
0
 def test_update_name(self):
     # If region name has changed, we update our database
     country = CountryFactory.create()
     region = RegionFactory.create(country=country)
     new_name = 'New %s' % region.name
     result = {
         'province': {
             'name': new_name,
             'id': region.mapbox_id,
         }
     }
     result_to_region(result, country)
     region = Region.objects.get(pk=region.pk)
     eq_(new_name, region.name)
예제 #3
0
 def test_update_name(self):
     # If region name has changed, we update our database
     country = CountryFactory.create()
     region = RegionFactory.create(country=country)
     new_name = 'New %s' % region.name
     result = {
         'province': {
             'name': new_name,
             'id': region.mapbox_id,
         }
     }
     result_to_region(result, country)
     region = Region.objects.get(pk=region.pk)
     eq_(new_name, region.name)
예제 #4
0
 def test_with_region(self):
     country = CountryFactory.create()
     result = {'province': {'name': 'NC', 'id': 'ID'}}
     region = result_to_region(result, country)
     eq_('NC', region.name)
     eq_('ID', region.mapbox_id)
     eq_(country, region.country)
예제 #5
0
    def test_duplicate_results(self):
        """Test that in case mapbox API returns a region already stored in DB
        with diferrent mapbox_id, we gracefully update all entries and foreign keys
        with the latest mapbox data."""

        region = RegionFactory.create(mapbox_id='42')
        user = UserFactory.create(userprofile={'geo_region': region})
        result = {'province': {'name': region.name, 'id': '24'}}

        result_to_region(result, region.country)
        lookup_args = {'name': region.name, 'country': region.country}

        region_qs = Region.objects.filter(**lookup_args)
        ok_(region_qs.count(), 1)
        eq_(region_qs[0].mapbox_id, '24')
        ok_(not Region.objects.filter(mapbox_id='42').exists())

        userprofile = UserProfile.objects.get(pk=user.userprofile.id)
        eq_(userprofile.geo_region.name, region.name)
        eq_(userprofile.geo_region.mapbox_id, '24')
예제 #6
0
 def test_with_region(self):
     country = CountryFactory.create()
     result = {
         'province': {
             'name': 'NC',
             'id': 'ID'
         }
     }
     region = result_to_region(result, country)
     eq_('NC', region.name)
     eq_('ID', region.mapbox_id)
     eq_(country, region.country)
예제 #7
0
 def test_no_region(self):
     country = CountryFactory.create()
     eq_(None, result_to_region({}, country))
예제 #8
0
 def test_no_region(self):
     country = CountryFactory.create()
     eq_(None, result_to_region({}, country))