def test_122_token_manager_access_token_get_user_no_access(self): m = TokenManager() token = Token('token-key', 'token-secret') token.user = '******' m.add(token) self.assertRaises(NotAccessTokenError, m.getAccessToken, 'token-key') self.assertEqual(m.getRequestToken('token-key'), token)
def test_123_token_manager_access_token_get_access_no_user(self): m = TokenManager() token = Token('token-key', 'token-secret') token.access = True m.add(token) self.assertRaises(TokenInvalidError, m.getAccessToken, 'token-key') self.assertRaises(NotRequestTokenError, m.getRequestToken, 'token-key')
def test_111_token_manager_addget_user(self): m = TokenManager() token = Token('token-key', 'token-secret') token.user = '******' token.access = True m.add(token) result = m.getTokensForUser('user') self.assertEqual(result, [token])
def test_112_token_manager_addget_user(self): m = TokenManager() token = Token('token-key', 'token-secret') token.user = '******' m.add(token) result = m.getTokensForUser('user') # only access tokens are tracked. self.assertEqual(result, [])
def test_125_token_manager_access_token_inconsistent_fail(self): m = TokenManager() token = Token('token-key', 'token-secret') token.access = True m.add(token) # this would result in the token not being indexed. token.user = '******' self.assertRaises(TokenInvalidError, m.getAccessToken, 'token-key') self.assertRaises(NotRequestTokenError, m.getRequestToken, 'token-key')
def test_113_token_manager_doubleadd_user(self): m = TokenManager() token = Token('token-key', 'token-secret') token.user = '******' token.access = True m.add(token) self.assertRaises(ValueError, m.add, token) result = m.getTokensForUser('user') # should not result in double entry. self.assertEqual(result, [token])
def afterSetUp(self): super(JsonClientTestCase, self).afterSetUp() register_layer(IPMR2JsonClientTestLayer, 'pmr2.jsonclient.tests') request = TestRequest() # Ensure that the most basic scope managers are being used. cmf = factory(ConsumerManager) tmf = factory(TokenManager) smf = factory(MockScopeManager) zope.component.provideAdapter(cmf, ( IAnnotatable, IPMR2JsonClientTestLayer, ), IConsumerManager) zope.component.provideAdapter(tmf, ( IAnnotatable, IPMR2JsonClientTestLayer, ), ITokenManager) zope.component.provideAdapter(smf, ( IAnnotatable, IPMR2JsonClientTestLayer, ), IScopeManager) # assuming none of these are overridden. self.consumer = Consumer('test.example.com', 'consumer-secret', u'PMR2 Test JSON Client', None) cm = zope.component.getMultiAdapter((self.portal, request), IConsumerManager) cm.add(self.consumer) token = Token('pmr2token', 'token-secret') token.access = True token.consumer_key = self.consumer.key token.user = default_user self.token = token tm = zope.component.getMultiAdapter((self.portal, request), ITokenManager) tm.add(self.token) # XXX especially this one. sm = zope.component.getMultiAdapter((self.portal, request), IScopeManager) sm.permitted = '^.*$' # permit everything. b = Browser() portal_url = self.portal.absolute_url() b.open(portal_url + '/login') b.getControl(name='__ac_name').value = default_user b.getControl(name='__ac_password').value = default_password b.getControl(name='submit').click() self.user_browser = b
def generate_consumer_and_token(self, consumer_key=None, save_consumer=False, save_token=False): if not consumer_key: consumer_key = self.default_consumer_key consumer = Consumer('consumer.example.com', 'consumer-secret') token = Token('token-key', 'token-secret') token.access = True token.user = self.default_user_id token.consumer_key = 'consumer.example.com' if save_consumer: self.consumerManager.add(consumer) if save_token: self.tokenManager.add(token) return consumer, token
def test_010_token_set_verifier(self): token = Token('token-key', 'token-secret') token.set_verifier() verifier = token.verifier token.set_verifier() self.assertEqual(verifier, token.verifier) token.set_verifier(True) self.assertNotEqual(verifier, token.verifier)
def test_020_token_get_callback_url(self): token = Token('token-key', 'token-secret') token.set_callback('http://example.com/') token.set_verifier('foo') url = token.get_callback_url() a = 'http://example.com/?oauth_verifier=foo&oauth_token=token-key' self.assertEqual(url, a)
def afterSetUp(self): super(JsonClientTestCase, self).afterSetUp() register_layer(IPMR2JsonClientTestLayer, "pmr2.jsonclient.tests") request = TestRequest() # Ensure that the most basic scope managers are being used. cmf = factory(ConsumerManager) tmf = factory(TokenManager) smf = factory(MockScopeManager) zope.component.provideAdapter(cmf, (IAnnotatable, IPMR2JsonClientTestLayer), IConsumerManager) zope.component.provideAdapter(tmf, (IAnnotatable, IPMR2JsonClientTestLayer), ITokenManager) zope.component.provideAdapter(smf, (IAnnotatable, IPMR2JsonClientTestLayer), IScopeManager) # assuming none of these are overridden. self.consumer = Consumer("test.example.com", "consumer-secret", u"PMR2 Test JSON Client", None) cm = zope.component.getMultiAdapter((self.portal, request), IConsumerManager) cm.add(self.consumer) token = Token("pmr2token", "token-secret") token.access = True token.consumer_key = self.consumer.key token.user = default_user self.token = token tm = zope.component.getMultiAdapter((self.portal, request), ITokenManager) tm.add(self.token) # XXX especially this one. sm = zope.component.getMultiAdapter((self.portal, request), IScopeManager) sm.permitted = "^.*$" # permit everything. b = Browser() portal_url = self.portal.absolute_url() b.open(portal_url + "/login") b.getControl(name="__ac_name").value = default_user b.getControl(name="__ac_password").value = default_password b.getControl(name="submit").click() self.user_browser = b
def test_115_token_manager_user_inconsistency(self): m = TokenManager() t1 = Token('token-key', 'token-secret') t1.user = '******' t1.access = True t2 = Token('token-key2', 'token-secret') t2.user = '******' t2.access = True m.add(t1) m.add(t2) m._del_user_map(t2) # User must know about the token for the getter to work. self.assertEqual(m.getTokensForUser('t2user'), [])
def test_114_token_manager_addremove_user(self): m = TokenManager() t1 = Token('token-key', 'token-secret') t1.user = '******' t1.access = True t2 = Token('token-key2', 'token-secret') t2.user = '******' t2.access = True m.add(t1) m.add(t2) self.assertEqual(m.getTokensForUser('user'), []) self.assertEqual(m.getTokensForUser('t1user'), [t1]) self.assertEqual(m.getTokensForUser('t2user'), [t2]) m.remove(t1.key) m.remove(t2) self.assertEqual(m.getTokensForUser('t1user'), []) self.assertEqual(m.getTokensForUser('t2user'), [])
def test_011_token_set_verifier_specific(self): token = Token('token-key', 'token-secret') token.set_verifier('verify') self.assertEqual('verify', token.verifier) token.set_verifier() self.assertEqual('verify', token.verifier)