def render(self, context): url = self.baseObject.render(context) # Make the URL absolute root_url = getattr(settings, "ROOT_URL", None) if not root_url: raise ValueError("Config setting 'ROOT_URL' must be defined, and must be the sites root url") root_url = root_url.rstrip("/") url = get_hashed_url(root_url + url) return url
def render(self, context): url = self.baseObject.render(context) # Make the URL absolute root_url = getattr(settings, "ROOT_URL", None) if not root_url: raise ValueError( "Config setting 'ROOT_URL' must be defined, and must be the sites root url" ) root_url = root_url.rstrip("/") url = get_hashed_url(root_url + url) return url
def handle(self, *args, **options): for url in args: print get_hashed_url(url)
def test_is_valid_url_bad_hash(self): url = utilities.get_hashed_url( self.url, datetime.datetime.now() + datetime.timedelta(days=10)) url += "xxx" self.assertFalse(utilities.is_valid_url(url))
def test_is_valid_url_expired(self): url = utilities.get_hashed_url( self.url, datetime.datetime.now() + datetime.timedelta(days=-10)) self.assertFalse(utilities.is_valid_url(url))
def test_is_valid_url_no_time(self): url = utilities.get_hashed_url(self.url) self.assertFalse(utilities.is_valid_url(url))
def test_is_valid_url_ok(self): url = utilities.get_hashed_url( self.url, datetime.datetime.now() + datetime.timedelta(days=10)) self.assertTrue(utilities.is_valid_url(url))
def test_get_hashed_url_with_datetime(self): url = utilities.get_hashed_url( self.url, datetime.datetime(2011, 6, 1, 9, 33, 22, 441717)) expected = "https://moo.com:88/mooo/cow/?xx=yy&aa=bb&_t=1306920802&_h=effefe2db031944bee6b79943db24badf7f968fe" self.assertEqual(url, expected)
def test_get_hashed_url_with_time(self): url = utilities.get_hashed_url(self.url, 123) expected = "https://moo.com:88/mooo/cow/?xx=yy&aa=bb&_t=123&_h=839201dc174753d0099e3669a5841b94ddecb393" self.assertEqual(url, expected)
def test_get_hashed_url_no_time(self): url = utilities.get_hashed_url(self.url) expected = "https://moo.com:88/mooo/cow/?xx=yy&aa=bb&_t=&_h=47f37d04c98a06a0c45790e0af2a1fd64129dfb2" self.assertEqual(url, expected)