Example #1
0
    def setUp(self):
        self.location_model_patcher = patch.object(
            settings, 'GEOIP_LOCATION_MODEL',
            'test_app.models.MyCustomLocation')
        self.location_model = self.location_model_patcher.start()

        self.locator = Locator(RequestFactory().get('/'))
Example #2
0
def get_location(request):
    from django_geoip.base import Locator
    if not hasattr(request, '_cached_location'):
        request._cached_location = Locator(request).locate()
    return request._cached_location
Example #3
0
 def test_get_stored_location_none(self):
     request = self.factory.get('/')
     self.assertEqual(Locator(request)._get_stored_location(), None)
Example #4
0
 def test_get_stored_location_ok(self):
     self.factory.cookies[settings.GEOIP_COOKIE_NAME] = 200
     request = self.factory.get('/')
     self.assertEqual(
         Locator(request)._get_stored_location(), self.my_location)