def test_252_token_manager_claim_fail_missing(self): m = TokenManager() consumer = Consumer('consumer-key', 'consumer-secret') callback = 'oob' token = m.generateRequestToken(consumer.key, callback) m.remove(token) # remove it self.assertRaises(TokenInvalidError, m.claimRequestToken, token, 'u') self.assertEqual(token.user, None)
def test_251_token_manager_claim_fail_access(self): m = TokenManager() consumer = Consumer('consumer-key', 'consumer-secret') callback = 'oob' token = m.generateRequestToken(consumer.key, callback) token.access = True # hack it to be access token. self.assertRaises(TokenInvalidError, m.claimRequestToken, token, 'u') self.assertEqual(token.user, None)
def test_250_token_manager_claim(self): m = TokenManager() consumer = Consumer('consumer-key', 'consumer-secret') callback = 'oob' token = m.generateRequestToken(consumer.key, callback) m.claimRequestToken(token, 'user') self.assertEqual(token.user, 'user') self.assertTrue(token.expiry > int(time.time()))
def test_200_token_manager_generate_request_token(self): m = TokenManager() consumer = Consumer('consumer-key', 'consumer-secret') callback = 'oob' token = m.generateRequestToken(consumer.key, callback) self.assertEqual(m.get(token.key), token) self.assertEqual(m.get(token.key).consumer_key, consumer.key) self.assertEqual(m.get(token.key).access, False) self.assertEqual(m.getRequestToken(token.key).key, token.key)
def test_310_token_manager_generate_access_token_no_user(self): m = TokenManager() consumer = Consumer('consumer-key', 'consumer-secret') callback = 'oob' server_token = m.generateRequestToken(consumer.key, callback) # simulate passing only the key and secret to consumer request_token = Token(server_token.key, server_token.secret) # However, it's not claimed by a user yet, so expiry is not set, # thus... self.assertRaises(TokenInvalidError, m.generateAccessToken, consumer.key, request_token.key)
def test_300_token_manager_generate_access_token(self): m = TokenManager() consumer = Consumer('consumer-key', 'consumer-secret') callback = 'oob' server_token = m.generateRequestToken(consumer.key, callback) verifier = server_token.verifier # Also simulate user claiming the token m.claimRequestToken(server_token.key, 'user') # now simulate passing only the key and secret to consumer request_token = Token(server_token.key, server_token.secret) token = m.generateAccessToken(consumer.key, request_token.key) self.assertEqual(m.get(token.key), token) self.assertEqual(m.get(token.key).consumer_key, consumer.key) self.assertEqual(m.get(token.key).access, True) self.assertEqual(m.get(token.key).user, 'user') # Also, assert that this token key is available in the method # that returns these keys by user id. self.assertEqual(m.getTokensForUser('user'), [token])