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

        country = CountryFactory.create(mapbox_id='42')
        user = UserFactory.create(userprofile={'geo_country': country})

        result = {
            'country': {
                'name': country.name,
                'id': '24'
            }
        }

        result_to_country(result)

        country_qs = Country.objects.filter(name=country.name)
        eq_(country_qs.count(), 1)
        eq_(country_qs[0].mapbox_id, '24')
        ok_(not Country.objects.filter(mapbox_id='42').exists())

        userprofile = UserProfile.objects.get(pk=user.userprofile.id)
        eq_(userprofile.geo_country.name, country.name)
        eq_(userprofile.geo_country.mapbox_id, '24')
Esempio n. 2
0
 def test_with_country(self):
     result = {'country': {'id': 'mapbox_id', 'name': 'Petoria'}}
     country = result_to_country(result)
     ok_(country is not None)
     ok_(isinstance(country, Country))
     eq_('mapbox_id', country.mapbox_id)
     eq_('Petoria', country.name)
Esempio n. 3
0
 def test_with_country(self):
     result = {'country': {'id': 'mapbox_id', 'name': 'Petoria'}}
     country = result_to_country(result)
     ok_(country is not None)
     ok_(isinstance(country, Country))
     eq_('mapbox_id', country.mapbox_id)
     eq_('Petoria', country.name)
Esempio n. 4
0
 def test_update_country_name(self):
     # If country name has changed, we update our database
     country = CountryFactory.create()
     # Mapbox returns same country ID, but new improved country name
     new_name = 'Democratic Republic of %s' % country.name
     result = {'country': {'id': country.mapbox_id, 'name': new_name}}
     country = result_to_country(result)
     country = Country.objects.get(pk=country.pk)
     eq_(new_name, country.name)
Esempio n. 5
0
 def test_update_country_name(self):
     # If country name has changed, we update our database
     country = CountryFactory.create()
     # Mapbox returns same country ID, but new improved country name
     new_name = 'Democratic Republic of %s' % country.name
     result = {'country': {'id': country.mapbox_id,
                           'name': new_name}}
     country = result_to_country(result)
     country = Country.objects.get(pk=country.pk)
     eq_(new_name, country.name)
Esempio n. 6
0
    def test_duplicate_results(self):
        """Test that in case mapbox API returns a country already stored in DB
        with diferrent mapbox_id, we gracefully update all entries and foreign keys
        with the latest mapbox data."""

        country = CountryFactory.create(mapbox_id='42')
        user = UserFactory.create(userprofile={'geo_country': country})

        result = {'country': {'name': country.name, 'id': '24'}}

        result_to_country(result)

        country_qs = Country.objects.filter(name=country.name)
        eq_(country_qs.count(), 1)
        eq_(country_qs[0].mapbox_id, '24')
        ok_(not Country.objects.filter(mapbox_id='42').exists())

        userprofile = UserProfile.objects.get(pk=user.userprofile.id)
        eq_(userprofile.geo_country.name, country.name)
        eq_(userprofile.geo_country.mapbox_id, '24')
Esempio n. 7
0
 def test_no_country(self):
     eq_(None, result_to_country({'foo': 1}))
Esempio n. 8
0
 def test_country_code_set(self):
     greece = {'country': {'id': 'mapbox_id', 'name': 'Greece'}}
     country = result_to_country(greece)
     ok_(isinstance(country, Country))
     eq_(country.code, u'gr')
Esempio n. 9
0
 def test_no_country(self):
     eq_(None, result_to_country({'foo': 1}))
Esempio n. 10
0
 def test_country_code_set(self):
     greece = {'country': {'id': 'mapbox_id', 'name': 'Greece'}}
     country = result_to_country(greece)
     ok_(isinstance(country, Country))
     eq_(country.code, u'gr')