|
| 1 | +import sys |
| 2 | +import unittest |
| 3 | +import oauth.consumer |
| 4 | +import config |
| 5 | + |
| 6 | +class TestClient(unittest.TestCase): |
| 7 | + pass |
| 8 | + |
| 9 | + |
| 10 | +class TestClient(unittest.TestCase): |
| 11 | + |
| 12 | + def oauth(self, consumer, keys, threeleg, test_url, **kwargs): |
| 13 | + self.client = consumer(keys.CONSUMER_KEY, keys.CONSUMER_SECRET, callback_url='oob', **kwargs) |
| 14 | + user, url = self.client.start() |
| 15 | + if threeleg: |
| 16 | + print "Get the token from this url:\n%s\nToken: " % url |
| 17 | + verify = sys.stdin.readline().strip() |
| 18 | + else: |
| 19 | + verify = None |
| 20 | + token = user.get_request_token() |
| 21 | + self.client.verify(user, token.key, verify) |
| 22 | + if test_url: |
| 23 | + print user.get_access_token(), verify |
| 24 | + respons
8000
e = self.client.fetch(test_url, user) |
| 25 | + print response.read() |
| 26 | + |
| 27 | +class Yahoo(TestClient): |
| 28 | + |
| 29 | + def test_2leg(self): |
| 30 | + self.oauth(oauth.consumer.Yahoo, config.yahoo2leg, False, "http://query.yahooapis.com/v1/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.news.yahoo.com%2Frss%2Ftopstories'&format=json") |
| 31 | + |
| 32 | + def test_3leg(self): |
| 33 | + self.oauth(oauth.consumer.Yahoo, config.yahoo3leg, True, "http://social.yahooapis.com/v1/me/guid?format=json") |
| 34 | + |
| 35 | + |
| 36 | +class Twitter(TestClient): |
| 37 | + |
| 38 | + def test_oauth(self): |
| 39 | + self.oauth(oauth.consumer.Twitter, config.twitter, True, "http://twitter.com/account/verify_credentials.json") |
| 40 | + |
| 41 | +class Google(TestClient): |
| 42 | + |
| 43 | + def test_oauth(self): |
| 44 | + self.oauth(oauth.consumer.Google, config.google, True, "http://www.blogger.com/feeds/default/blogs", scope="http://www.blogger.com/feeds/") |
| 45 | + |
| 46 | +# myspace doesn't support oob auth |
| 47 | +#class Myspace(TestClient): |
| 48 | +# def test_oauth(self): |
| 49 | +# self.oauth(oauth.consumer.Myspace, config.myspace, True, "") |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + unittest.main() |
0 commit comments