Beispiel #1
0
 def test_request_for_authorization_with_unauthorized_callback(self):
     #!!! Assuming the callback domain is authorized and is of valid format (not localhost).
     from tootwi import ApplicationCredentials
     from tootwi.errors import ParametersCallbackError
     application_credentials = ApplicationCredentials(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
     with self.assertRaises(ParametersCallbackError):
         temporary_credentials = application_credentials.request(self.UNAUTHORIZED_CALLBACK)
Beispiel #2
0
 def test_request_for_authorization_with_good_callback(self):
     #!!! Assuming the callback domain is authorized and is of valid format (not localhost).
     from tootwi import ApplicationCredentials, TemporaryCredentials
     application_credentials = ApplicationCredentials(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
     temporary_credentials = application_credentials.request(self.GOOD_CALLBACK)
     self.assertIsInstance(temporary_credentials, TemporaryCredentials)
     self.assertTrue(temporary_credentials.callback_confirmed)
Beispiel #3
0
 def test_request_for_authorization_with_no_callback(self):
     from tootwi import ApplicationCredentials, TemporaryCredentials
     application_credentials = ApplicationCredentials(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
     
     temporary_credentials = application_credentials.request()
     self.assertIsInstance(temporary_credentials, TemporaryCredentials)
     self.assertEqual(temporary_credentials.consumer_key, application_credentials.consumer_key)
     self.assertEqual(temporary_credentials.consumer_secret, application_credentials.consumer_secret)
     self.assertIsInstance(temporary_credentials.token_key, basestring)
     self.assertIsInstance(temporary_credentials.token_secret, basestring)
     self.assertTrue(temporary_credentials.token_key)
     self.assertTrue(temporary_credentials.token_secret)
     
     url = temporary_credentials.url
     self.assertIsInstance(url, basestring)
     self.assertTrue('http://' in url or 'https://' in url)
     self.assertTrue('://api.twitter.com/oauth/authorize?oauth_token=' in url)
Beispiel #4
0
def main():
    
    #
    # Stage 1 of 3: make request and gain temporary credentials.
    #
    application_credentials = ApplicationCredentials(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
    temporary_credentials = application_credentials.request()
    
    #
    # Stage 2 of 3: forward user to authorization page and retrieve pin code (or callback).
    #
    print(temporary_credentials.url)
    pin = raw_input('pin: ')
    
    #
    # Stage 3 of 3: gain access credentials with pin code or callback verifier.
    #
    token_credentials = temporary_credentials.confirm(pin)
    
    #
    # Last check: try to use access credentials (not a part of authorization already).
    #
    user = token_credentials.account.verify_credentials()
    print(user)
Beispiel #5
0
class OAuthConfirmAuthorizationScenarioTests(unittest.TestCase):
    CALLBACK = 'http://nolar.info.local/'
    
    def setUp(self):
        from tootwi import ApplicationCredentials, TemporaryCredentials
        self.application_credentials = ApplicationCredentials(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
        self.temporary_credentials = self.application_credentials.request()
    
    def test_confirm_authorization_with_no_verifier_fails(self):
        with self.assertRaises(TypeError):
            self.temporary_credentials.confirm()
    
    def test_confirm_authorization_with_empty_verifier_fails(self):
        from tootwi.errors import OperationNotPermittedError
        with self.assertRaises(OperationNotPermittedError):
            self.temporary_credentials.confirm('')
    
    def test_confirm_authorization_with_wrong_verifier_fails(self):
        from tootwi.errors import OperationNotPermittedError
        with self.assertRaises(OperationNotPermittedError):
            self.temporary_credentials.confirm('0123456789')
    
    @unittest.skip("Requires a lot of web page interaction (login, submit, etc).")#TODO later
    def test_confirm_authorization_with_pin_verifier_works(self):
        import urllib2
        content = urllib2.urlopen(self.temporary_credentials.url).read()
        # if it is a login page, then parse form, push login button
        # if it is a auth page, then parse form, push auth button
        # if it is a pin code page, then parse pin code
        # on ever step, remember cookies and form hidden values (this is a "session")
        #verifier = ...???...
        #self.temporary_credentials.confirm(verifier)
    
    @unittest.skip("Requires a lot of web page interaction (login, submit, etc).")#TODO later
    def test_confirm_authorization_with_callback_verifier_works(self):
        import urllib2
        content = urllib2.urlopen(self.temporary_credentials.url).read()
Beispiel #6
0
 def setUp(self):
     from tootwi import ApplicationCredentials, TemporaryCredentials
     self.application_credentials = ApplicationCredentials(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
     self.temporary_credentials = self.application_credentials.request()