def test_is_newer_than(self): now = timeutil.utcnow() after = now + MINS_15 self.assertFalse(timeutil.is_newer_than(after, timeutil.ONE_HOUR)) after = now + MINS_30 self.assertFalse(timeutil.is_newer_than(after, timeutil.ONE_HOUR)) after = now + MINS_45 self.assertFalse(timeutil.is_newer_than(after, timeutil.ONE_HOUR)) after = now + ONE_HOUR self.assertTrue(timeutil.is_newer_than(after, timeutil.ONE_HOUR))
def test_is_older_than(self): now = timeutil.utcnow() before = now - MINS_15 self.assertFalse(timeutil.is_older_than(before, timeutil.ONE_HOUR)) before = now - MINS_30 self.assertFalse(timeutil.is_older_than(before, timeutil.ONE_HOUR)) before = now - MINS_45 self.assertFalse(timeutil.is_older_than(before, timeutil.ONE_HOUR)) before = now - ONE_HOUR self.assertTrue(timeutil.is_older_than(before, timeutil.ONE_HOUR))
def authenticate(self): """Aquire authorization token for using thetvdb apis.""" if self.__token: try: resp = self._refresh_token() except exceptions.TVDBRequestException as err: # if a 401 is the cause try to login if getattr(err.response, 'status_code', 0) == 401: resp = self._login() else: raise else: resp = self._login() self.__token = resp.get('token') self._token_timer = timeutil.utcnow()
def test_token_expired(self): self.assertTrue(self.client.token_expired) # current time self.client._token_timer = timeutil.utcnow() self.assertFalse(self.client.token_expired) # 15 minutes after current self.client._token_timer += MINS_15 self.assertFalse(self.client.token_expired) # 30 minutes after current self.client._token_timer += MINS_15 self.assertFalse(self.client.token_expired) # 45 minutes after current self.client._token_timer += MINS_15 self.assertFalse(self.client.token_expired) # 60 minutes after current self.client._token_timer += MINS_15 self.assertTrue(self.client.token_expired)