def test_create_new_token(self): counter = random.randrange(100000) url = "http://xlarrakoetxea{0}.org".format(random.randrange(100)) # Set the counter ShortLink.set_counter(counter) # Call the async task with celery result = tasks.create_token.delay(url) new_token = result.get() #Check if the returned token is ok self.assertEquals(utils.counter_to_token(counter + 1), new_token) self.assertTrue(result.successful()) # Check if the link is stored in the database correctly sl = ShortLink.find(url=url)[0] # creation_date is trap!! :P sl2 = ShortLink(counter=counter + 1, url=url, creation_date=sl.creation_date) # The host and title are set after the instance was created so we add sl2.host = sl.host sl2.title = sl.title self.assertEquals(sl2, sl)
def test_increment_stored_counter(self): counter = random.randrange(0, 100000) times = random.randrange(0, 100) ShortLink.set_counter(counter) for i in range(times): self.assertEquals(counter + i + 1, ShortLink.incr_counter()) self.assertEquals(counter + times, ShortLink.get_counter())
def test_stored_counter_set_get(self): counter = random.randrange(0, 100000) ShortLink.set_counter(counter) self.assertEquals(counter, ShortLink.get_counter())