def test_is_expired_false(self): # given expires_str = '2017-01-01T00:00:00.000000Z' current_time = datetime(2016, 12, 31) conn = FakeIdentityConnector(expires_timestamp=expires_str) user = User(self.auth_url, self.username, self.api_key, config={}, conn=conn) user._get_data() # precondition self.assertIsNotNone(user.expires) # when result = user.is_expired(current_time=current_time) # then the token is not yet expired self.assertFalse(result)
def test_gets_expiration_timestamp_from_catalog(self): # given expires_str = '2017-01-01T00:00:00.000000Z' expires_dt = datetime(2017, 1, 1) conn = FakeIdentityConnector(expires_timestamp=expires_str) user = User(self.auth_url, self.username, self.api_key, config={}, conn=conn) # when result = user._get_data() # then the expiration timestamp was set to the correct value self.assertIsNotNone(user.expires) self.assertEqual(expires_dt, user.expires)
def test_get_data_makes_a_connection(self): # given conn = FakeIdentityConnector() user = User(self.auth_url, self.username, self.api_key, config={}, conn=conn) # precondition self.assertFalse(conn.called) self.assertIs(None, user.token) self.assertIs(None, user.tenant_id) # when result = user._get_data() # then the connector was called self.assertTrue(conn.called)
def test_get_data_sets_tenant_and_token(self): # given conn = FakeIdentityConnector() user = User(self.auth_url, self.username, self.api_key, config={}, conn=conn) # precondition self.assertFalse(conn.called) self.assertIs(None, user.token) self.assertIs(None, user.tenant_id) # when result = user._get_data() # then self.assertEqual(self.tenant, user.tenant_id) self.assertEqual(self.token, user.token)