Beispiel #1
0
 def test_should_not_update_cookie_if_cookie_is_none(self):
     self.request.COOKIES[
         settings.GEOIP_COOKIE_NAME] = settings.GEOIP_LOCATION_EMPTY_VALUE
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertFalse(
         storage._should_update_cookie(
             new_value=settings.GEOIP_LOCATION_EMPTY_VALUE))
Beispiel #2
0
 def test_do_set(self, mock):
     mock.utcnow.return_value = datetime(2030, 1, 1, 0, 0, 0)
     base_response = HttpResponse()
     storage = LocationCookieStorage(request=self.request,
                                     response=base_response)
     storage._do_set(10)
     expected = [
         'Set-Cookie: geoip_location_id=10',
         'expires=Thu, 02-Jan-2031 00:00:00 GMT'
     ]
     self.assertEqual(
         base_response.cookies[settings.GEOIP_COOKIE_NAME].output().split(
             '; ')[:2], expected)
Beispiel #3
0
 def test_malicious_cookie_is_no_problem(self):
     self.request.COOKIES[settings.GEOIP_COOKIE_NAME] = "wtf"
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertEqual(storage.get(), None)
Beispiel #4
0
 def test_validate_location_if_cookies_is_empty_value(self):
     value = settings.GEOIP_LOCATION_EMPTY_VALUE
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertTrue(storage._validate_location(location=value))
Beispiel #5
0
 def test_should_update_cookie_if_cookie_is_empty_value(self):
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertTrue(
         storage._should_update_cookie(
             new_value=settings.GEOIP_LOCATION_EMPTY_VALUE))
Beispiel #6
0
 def test_should_update_cookie_if_cookie_is_obsolete(self):
     self.request.COOKIES[settings.GEOIP_COOKIE_NAME] = 42
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertTrue(storage._should_update_cookie(new_value=10))
Beispiel #7
0
 def test_should_update_cookie_if_cookie_doesnt_exist(self):
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertTrue(storage._should_update_cookie(new_value=10))
Beispiel #8
0
 def test_should_not_update_cookie_if_no_location_in_request(self):
     storage = LocationCookieStorage(request=HttpRequest(),
                                     response=HttpResponse())
     self.assertFalse(storage._should_update_cookie(new_value=10))
Beispiel #9
0
 def test_get_cookie_domain_no_settings(self):
     self.request.get_host = Mock(return_value='my.localserver.tld')
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertEqual(storage.get_cookie_domain(), None)
Beispiel #10
0
 def test_get_cookie_domain_from_settings(self):
     storage = LocationCookieStorage(request=self.request,
                                     response=HttpResponse())
     self.assertEqual(storage.get_cookie_domain(), '.testserver.local')