Esempio n. 1
0
    def test_api_call(self):
        """Assert Address calls google API and get address"""
        a = Address(raw="Rua Teçaindá, 81, SP", raw2="Casa")
        a.save()

        a = Address.objects.get(pk=a.pk)
        self.assertTrue(a.raw == "Rua Teçaindá, 81, SP")
        self.assertTrue(a.raw2 == "Casa")
        self.assertTrue(a.address_line ==
                        "Rua Teçaindá, 81, Pinheiros, São Paulo, SP, Brazil")
        self.assertTrue(a.__str__() ==
                        "Rua Teçaindá, 81, Pinheiros, São Paulo, SP, Brazil")
        self.assertTrue(a.lat)
        self.assertTrue(a.lng)

        a.raw = "Rua Capote Valente, 701, SP"
        a.save()
        a = Address.objects.get(pk=a.pk)
        self.assertTrue(a.raw == "Rua Capote Valente, 701, SP")
        self.assertTrue(a.raw2 == "Casa")
        self.assertTrue(
            a.address_line ==
            "Rua Capote Valente, 701, Pinheiros, São Paulo, SP, Brazil")
        self.assertTrue(a.__str__(
        ) == "Rua Capote Valente, 701, Pinheiros, São Paulo, SP, Brazil")
        self.assertTrue(a.lat)
        self.assertTrue(a.lng)

        a.address_line = None
        self.assertTrue(a.__str__() == "")
Esempio n. 2
0
    def test_no_country(self):
        """Assert AddressModel.get_country_code returns None instead of rasing AttributeError if no country exists"""
        a = Address(raw="Chicago")
        a.save()

        AddressComponent.objects.all().delete()

        self.assertTrue(a.get_country_code() == None)
Esempio n. 3
0
    def test_locality(self):
        """Assert AddressModel.get_city_state preference order is locality, administrative_area_2"""
        a = Address(raw="Chicago")
        a.save()
        self.assertTrue("Chicago" in a.get_city_state())

        a = remove_component(a, ['locality'])
        self.assertTrue("Cook" in a.get_city_state())
Esempio n. 4
0
class PostSaveSignalTestCase(TestCase):
    def setUp(self):
        self.instance = Address(raw="Chicago")
        self.instance.save()

    @mock.patch('google_address.update.update_address', return_value=True)
    @override_settings(GOOGLE_ADDRESS={
        'API_LANGUAGE': 'en_US',
        'ASYNC_CALLS': True
    })
    def test_async_settings(self, mocked_update_address):
        """Assert configuring ASYNC_CALLS setting makes the post_save signal spawn a thread"""
        thread = address_post_save(Address, self.instance)
        thread.join()
Esempio n. 5
0
    def test_api_call_2(self):
        a = Address(raw2="Casa")
        a.raw = "Rua Capote Valente, 701, SP"
        a.save()
        a = Address.objects.get(pk=a.pk)
        self.assertTrue(a.raw == "Rua Capote Valente, 701, SP")
        self.assertTrue(a.raw2 == "Casa")
        self.assertTrue(
            a.address_line ==
            "Rua Capote Valente, 701, Pinheiros, São Paulo, SP, Brazil")
        self.assertTrue(a.__str__(
        ) == "Rua Capote Valente, 701, Pinheiros, São Paulo, SP, Brazil")
        self.assertTrue(a.lat)
        self.assertTrue(a.lng)

        a.address_line = None
        self.assertTrue(a.__str__() == "")
Esempio n. 6
0
    def test_address_field_from_pk(self):

        with self.assertRaises(ValidationError):
            d = DemoObj()
            d.address = 1
            d.save()

        a = Address(raw='Lombardia')
        a.save()

        d = DemoObj()
        d.address = a.pk
        d.save()
        assert isinstance(d.address, Address)
        assert d.address == a

        d = DemoObj.objects.last()
        assert isinstance(d.address, Address)
        assert d.address == a
Esempio n. 7
0
 def test_region_localized(self):
     a = Address(raw='Lombardia')
     a.save()
     print(a.__dict__)
Esempio n. 8
0
 def test_signal_returns_in_case_of_no_result(self):
     """Assert AddressModel.get_country_code returns None instead of rasing AttributeError if no country exists"""
     a = Address(raw="abcdefghijklmnopqrstuvwxyz")
     a.save()
     self.assertTrue(a.address_line == None)