Esempio n. 1
0
    def get(self):
        helper = RequestHelper(self)
        try:
            if not users.is_current_user_admin():
                helper.error(403, "admin required")
                return

            oauth_token = self.request.get("oauth_token")
            if not oauth_token:
                # initial request, I store the request token key/secret as cookies and redirect to twitter's auth page
                request_token, auth_url = TwitterConnector.get_request_token_and_auth_url()
                logging.debug("request token key:%s, secret:%s" % (request_token.key, request_token.secret))

                helper.set_cookie("%s=%s; path=/" % (self._rtoken_key_cookie, request_token.key))
                helper.set_cookie("%s=%s; path=/" % (self._rtoken_secret_cookie, request_token.secret))
                helper.write_text("redirecting request token %s to %s" % (request_token.to_string(), auth_url))
                self.redirect(auth_url)
            else:
                # post verification request
                key = self.request.cookies.get(self._rtoken_key_cookie, None)
                secret = self.request.cookies.get(self._rtoken_secret_cookie, None)
                if not (key and secret):
                    helper.error(400, "key and secret not stored as cookies")
                    return
                access_token = TwitterConnector.get_access_token(key, secret)
                token_string = access_token.to_string()
                ConfigurationAccessor.update(twitter_access_token=token_string)
                helper.write_text("saved access token %s" % token_string)
        except Exception, e:
            msg = traceback.print_exc()
            helper.error(500, msg)
Esempio n. 2
0
    def test_put_friend(self):
        request, response = new_mock_request_response(self.m)
        self.m.StubOutWithMock(TwitterConnector, "new_api")

        api = _create_api(self.m)
        TwitterConnector.new_api().AndReturn(api)

        username = "******"
        api.CreateFriendship(username)
        response.set_status(204)

        handler = TwitterFriendHandler()
        handler.initialize(request, response)
        set_api_user(self.m)

        self.m.ReplayAll()
        handler.put(username)
        self.m.VerifyAll()
Esempio n. 3
0
 def test_put_friend(self):
     request, response = new_mock_request_response(self.m)
     self.m.StubOutWithMock(TwitterConnector, "new_api")
     
     api = _create_api(self.m)
     TwitterConnector.new_api().AndReturn(api)
     
     username = "******"
     api.CreateFriendship(username)
     response.set_status(204)
     
     handler = TwitterFriendHandler()
     handler.initialize(request, response)
     set_api_user(self.m)        
     
     self.m.ReplayAll()
     handler.put(username)
     self.m.VerifyAll()
Esempio n. 4
0
 def test_put_friend(self):
     request, response = new_mock_request_response(self.m)
     self.m.StubOutWithMock(TwitterConnector, "new_api")
     
     api = _create_api(self.m)
     TwitterConnector.new_api().AndReturn(api)
     
     username = "******"
     api.GetUser(username).AndReturn(Mock(name="hi", screen_name=username, 
         url="hi", statuses_count=1,
         followers_count=1, friends_count=1))
     
     handler = TwitterUserHandler()
     handler.initialize(request, response)
     set_api_user(self.m)        
     
     self.m.ReplayAll()
     handler.get(username)
     self.m.VerifyAll()
Esempio n. 5
0
    def get(self):
        helper = RequestHelper(self)
        try:
            if not users.is_current_user_admin():
                helper.error(403, "admin required")
                return

            oauth_token = self.request.get("oauth_token")
            if not oauth_token:
                # initial request, I store the request token key/secret as cookies and redirect to twitter's auth page
                request_token, auth_url = TwitterConnector.get_request_token_and_auth_url(
                )
                logging.debug("request token key:%s, secret:%s" %
                              (request_token.key, request_token.secret))

                helper.set_cookie("%s=%s; path=/" %
                                  (self._rtoken_key_cookie, request_token.key))
                helper.set_cookie(
                    "%s=%s; path=/" %
                    (self._rtoken_secret_cookie, request_token.secret))
                helper.write_text("redirecting request token %s to %s" %
                                  (request_token.to_string(), auth_url))
                self.redirect(auth_url)
            else:
                # post verification request
                key = self.request.cookies.get(self._rtoken_key_cookie, None)
                secret = self.request.cookies.get(self._rtoken_secret_cookie,
                                                  None)
                if not (key and secret):
                    helper.error(400, "key and secret not stored as cookies")
                    return
                access_token = TwitterConnector.get_access_token(key, secret)
                token_string = access_token.to_string()
                ConfigurationAccessor.update(twitter_access_token=token_string)
                helper.write_text("saved access token %s" % token_string)
        except Exception, e:
            msg = traceback.print_exc()
            helper.error(500, msg)
Esempio n. 6
0
    def test_put_friend(self):
        request, response = new_mock_request_response(self.m)
        self.m.StubOutWithMock(TwitterConnector, "new_api")

        api = _create_api(self.m)
        TwitterConnector.new_api().AndReturn(api)

        username = "******"
        api.GetUser(username).AndReturn(
            Mock(name="hi",
                 screen_name=username,
                 url="hi",
                 statuses_count=1,
                 followers_count=1,
                 friends_count=1))

        handler = TwitterUserHandler()
        handler.initialize(request, response)
        set_api_user(self.m)

        self.m.ReplayAll()
        handler.get(username)
        self.m.VerifyAll()