示例#1
0
 def test_do_set(self, mock):
     mock.utcnow.return_value = datetime(2012, 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=Tue, 01-Jan-2013 00:00:00 GMT"]
     self.assertEqual(base_response.cookies[settings.GEOIP_COOKIE_NAME].output().split("; ")[:2], expected)
示例#2
0
 def test_get_cookie_domain_cant_find_first_part(self):
     self.request.get_host = Mock(return_value=None)
     storage = LocationCookieStorage(request=self.request, response=HttpResponse())
     self.assertEqual(storage._get_cookie_domain(), None)
示例#3
0
 def test_get_cookie_domain_remove_first_part(self):
     self.request.get_host = Mock(return_value="my.localserver.tld")
     storage = LocationCookieStorage(request=self.request, response=HttpResponse())
     self.assertEqual(storage._get_cookie_domain(), ".localserver.tld")
示例#4
0
 def test_get_cookie_domain_from_settings(self):
     storage = LocationCookieStorage(request=self.request, response=HttpResponse())
     self.assertEqual(storage._get_cookie_domain(), ".testserver.local")
示例#5
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))
示例#6
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))
示例#7
0
 def test_should_not_update_cookie_if_cookie_is_none(self):
     self.request.COOKIES[settings.GEOIP_COOKIE_NAME] = None
     storage = LocationCookieStorage(request=self.request, response=HttpResponse())
     self.assertFalse(storage._should_update_cookie(new_value=None))
示例#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))
示例#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)
示例#10
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)
示例#11
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))
示例#12
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))