def test_auth_property(self): auth = haiker.BasicAuth('MyUsername', 'MyPassword') api = haiker.Haiker(auth) self.assertIs(api.auth, auth) auth2 = haiker.BasicAuth('MyUsername2', 'MyPassword2') api.auth = auth2 self.assertIs(api.auth, auth2)
def _check_with_auth(self, auth): api = haiker.Haiker(auth) url_name = api.show_user().screen_name user_keyword = 'id:{0}'.format(url_name) # Timeline APIs api.user_timeline(count=1) api.friends_timeline(count=1) # Entry and star APIs text = 'Hello world' eid = api.update_status(user_keyword, text, source=self.keyword).id api.show_status(eid) api.add_star(eid) api.remove_star(eid) api.delete_status(eid, url_name) # User and keyword APIs api.associate_keywords(user_keyword, self.keyword) api.dissociate_keywords(user_keyword, self.keyword) # Favorite APIs api.friends() api.followers() api.follow_user(self.someone) api.unfollow_user(self.someone) api.favorite_keywords(self.someone) api.follow_keyword(self.keyword) api.unfollow_keyword(self.keyword)
def check(auth): """Check that no exception is raised when calling Haiker methods using auth. """ url = re.compile('http://h\\.hatena\\.ne\\.jp/api/statuses/.+') responses.add(responses.GET, url, json=samples.STATUS) responses.add(responses.POST, url, json=samples.STATUS) api = haiker.Haiker(auth) api.show_status('xyz') api.update_status('BOT', 'Hello world')
def check_with_oauth(self, consumer_key, consumer_secret, oauth_token=None, token_secret=None): self._print_title('Checking APIs with OAuth') if oauth_token is None or token_secret is None: auth = haiker.OAuth(consumer_key, consumer_secret) auth.initiate(['read_public', 'write_public']) print('GOTO: {url}'.format(url=auth.auth_url())) verifier = input('verifier: ').strip() token, secret = auth.verify(verifier) print('oauth_token: {0}'.format(token)) print('oauth_secret: {0}'.format(secret)) print() else: auth = haiker.OAuth(consumer_key, consumer_secret, oauth_token, token_secret) api = haiker.Haiker(auth) self._check_with_auth(auth)
def check_without_auth(self): self._print_title('Checking APIs available without auth') api = haiker.Haiker() # Timeline APIs api.public_timeline() api.keyword_timeline(self.keyword) api.user_timeline(self.someone) api.friends_timeline(self.someone) api.album(word=self.keyword) # User and keyword APIs api.show_user(self.someone) api.show_keyword(self.keyword) api.hot_keywords() api.keyword_list(word=self.keyword) # Favorite APIs api.friends(self.someone) api.followers(self.someone)
def setUp(self): self.api = haiker.Haiker()