Added a test verifying that the SimpleBuzzWrapper can post as an authorised user. Added a property file in oacurl format for the test account. Changed wrapper to use user_ids rather than full email addresses
This commit is contained in:
@@ -40,7 +40,7 @@ def _abstract():
|
|||||||
|
|
||||||
|
|
||||||
def _oauth_uri(name, discovery, params):
|
def _oauth_uri(name, discovery, params):
|
||||||
"""Look up the OAuth UR from the discovery
|
"""Look up the OAuth URI from the discovery
|
||||||
document and add query parameters based on
|
document and add query parameters based on
|
||||||
params.
|
params.
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,8 @@
|
|||||||
# Copyright (C) 2010 Google Inc.
|
#!/usr/bin/python2.4
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Copyright 2010 Google Inc. All Rights Reserved.
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
__author__ = 'ade@google.com'
|
__author__ = 'ade@google.com (Ade Oshineye)'
|
||||||
|
|
||||||
import apiclient.discovery
|
import apiclient.discovery
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
# Copyright (C) 2010 Google Inc.
|
#!/usr/bin/python2.4
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Copyright 2010 Google Inc. All Rights Reserved.
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
__author__ = 'ade@google.com (Ade Oshineye)'
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
import buzz_gae_client
|
import buzz_gae_client
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -22,7 +15,7 @@ class SimpleBuzzWrapper(object):
|
|||||||
|
|
||||||
self.builder = buzz_gae_client.BuzzGaeClient(consumer_key, consumer_secret, api_key=api_key)
|
self.builder = buzz_gae_client.BuzzGaeClient(consumer_key, consumer_secret, api_key=api_key)
|
||||||
if oauth_token and oauth_token_secret:
|
if oauth_token and oauth_token_secret:
|
||||||
logging.info('Using api_client with authorisation')
|
logging.debug('Using api_client with authorisation')
|
||||||
oauth_params_dict = {}
|
oauth_params_dict = {}
|
||||||
oauth_params_dict['consumer_key'] = consumer_key
|
oauth_params_dict['consumer_key'] = consumer_key
|
||||||
oauth_params_dict['consumer_secret'] = consumer_secret
|
oauth_params_dict['consumer_secret'] = consumer_secret
|
||||||
@@ -30,7 +23,7 @@ class SimpleBuzzWrapper(object):
|
|||||||
oauth_params_dict['oauth_token_secret'] = oauth_token_secret
|
oauth_params_dict['oauth_token_secret'] = oauth_token_secret
|
||||||
self.api_client = self.builder.build_api_client(oauth_params=oauth_params_dict)
|
self.api_client = self.builder.build_api_client(oauth_params=oauth_params_dict)
|
||||||
else:
|
else:
|
||||||
logging.info('Using api_client that doesn\'t have authorisation')
|
logging.debug('Using api_client that doesn\'t have authorisation')
|
||||||
self.api_client = self.builder.build_api_client()
|
self.api_client = self.builder.build_api_client()
|
||||||
|
|
||||||
def search(self, query, user_token=None, max_results=10):
|
def search(self, query, user_token=None, max_results=10):
|
||||||
@@ -42,14 +35,10 @@ class SimpleBuzzWrapper(object):
|
|||||||
return json['items']
|
return json['items']
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def post(self, sender, message_body):
|
def post(self, message_body, user_id='@me'):
|
||||||
if message_body is None or message_body.strip() is '':
|
if message_body is None or message_body.strip() is '':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#TODO(ade) What happens with users who have hidden their email address?
|
|
||||||
# Maybe we should switch to @me so it won't matter?
|
|
||||||
user_id = sender.split('@')[0]
|
|
||||||
|
|
||||||
activities = self.api_client.activities()
|
activities = self.api_client.activities()
|
||||||
logging.info('Retrieved activities for: %s' % user_id)
|
logging.info('Retrieved activities for: %s' % user_id)
|
||||||
activity = activities.insert(userId=user_id, body={
|
activity = activities.insert(userId=user_id, body={
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
__author__ = 'ade@google.com (Ade Oshineye)'
|
__author__ = 'ade@google.com (Ade Oshineye)'
|
||||||
|
|
||||||
from contrib.buzz.simple_buzz_wrapper import SimpleBuzzWrapper
|
from contrib.buzz.simple_buzz_wrapper import SimpleBuzzWrapper
|
||||||
|
|
||||||
|
import httplib2
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import pickle
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class SimpleBuzzWrapperTest(unittest.TestCase):
|
class SimpleBuzzWrapperTest(unittest.TestCase):
|
||||||
@@ -13,15 +18,15 @@ class SimpleBuzzWrapperTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_wrapper_rejects_empty_post(self):
|
def test_wrapper_rejects_empty_post(self):
|
||||||
wrapper = SimpleBuzzWrapper()
|
wrapper = SimpleBuzzWrapper()
|
||||||
self.assertEquals(None, wrapper.post('sender@example.org', ''))
|
self.assertEquals(None, wrapper.post('', '108242092577082601423'))
|
||||||
|
|
||||||
def test_wrapper_rejects_post_containing_only_whitespace(self):
|
def test_wrapper_rejects_post_containing_only_whitespace(self):
|
||||||
wrapper = SimpleBuzzWrapper()
|
wrapper = SimpleBuzzWrapper()
|
||||||
self.assertEquals(None, wrapper.post('sender@example.org', ' '))
|
self.assertEquals(None, wrapper.post(' ', '108242092577082601423'))
|
||||||
|
|
||||||
def test_wrapper_rejects_none_post(self):
|
def test_wrapper_rejects_none_post(self):
|
||||||
wrapper = SimpleBuzzWrapper()
|
wrapper = SimpleBuzzWrapper()
|
||||||
self.assertEquals(None, wrapper.post('sender@example.org', None))
|
self.assertEquals(None, wrapper.post(None, '108242092577082601423'))
|
||||||
|
|
||||||
def test_wrapper_rejects_empty_search(self):
|
def test_wrapper_rejects_empty_search(self):
|
||||||
wrapper = SimpleBuzzWrapper()
|
wrapper = SimpleBuzzWrapper()
|
||||||
@@ -36,25 +41,46 @@ class SimpleBuzzWrapperTest(unittest.TestCase):
|
|||||||
self.assertEquals(None, wrapper.search(None))
|
self.assertEquals(None, wrapper.search(None))
|
||||||
|
|
||||||
class SimpleBuzzWrapperRemoteTest(unittest.TestCase):
|
class SimpleBuzzWrapperRemoteTest(unittest.TestCase):
|
||||||
# These tests make remote calls
|
# These tests make remote calls
|
||||||
|
def __init__(self, method_name):
|
||||||
|
unittest.TestCase.__init__(self, method_name)
|
||||||
|
oauth_params_dict = {}
|
||||||
|
for line in open('./contrib_tests/test_account.oacurl.properties'):
|
||||||
|
line = line.strip()
|
||||||
|
if line.startswith('#'):
|
||||||
|
continue
|
||||||
|
key,value = line.split('=')
|
||||||
|
oauth_params_dict[key.strip()] = value.strip()
|
||||||
|
|
||||||
|
self.wrapper = SimpleBuzzWrapper(consumer_key=oauth_params_dict['consumerKey'],
|
||||||
|
consumer_secret=oauth_params_dict['consumerSecret'], oauth_token=oauth_params_dict['accessToken'],
|
||||||
|
oauth_token_secret=oauth_params_dict['accessTokenSecret'])
|
||||||
|
|
||||||
def test_searching_returns_results(self):
|
def test_searching_returns_results(self):
|
||||||
wrapper = SimpleBuzzWrapper()
|
results = self.wrapper.search('oshineye')
|
||||||
results = wrapper.search('oshineye')
|
|
||||||
self.assertTrue(results is not None)
|
self.assertTrue(results is not None)
|
||||||
|
|
||||||
def test_searching_honours_max_results(self):
|
def test_searching_honours_max_results(self):
|
||||||
wrapper = SimpleBuzzWrapper()
|
|
||||||
max = 5
|
max = 5
|
||||||
results = wrapper.search('oshineye', max_results=max)
|
results = self.wrapper.search('oshineye', max_results=max)
|
||||||
self.assertEquals(max, len(results))
|
self.assertEquals(max, len(results))
|
||||||
|
|
||||||
def test_can_fetch_profile(self):
|
def test_can_fetch_profile(self):
|
||||||
wrapper = SimpleBuzzWrapper()
|
profile = self.wrapper.get_profile('googlebuzz')
|
||||||
profile = wrapper.get_profile('googlebuzz')
|
|
||||||
self.assertTrue(profile is not None)
|
self.assertTrue(profile is not None)
|
||||||
|
|
||||||
profile = wrapper.get_profile(user_id = 'adewale')
|
profile = self.wrapper.get_profile(user_id='adewale')
|
||||||
self.assertTrue(profile is not None)
|
self.assertTrue(profile is not None)
|
||||||
|
|
||||||
|
def test_can_post_without_user_id(self):
|
||||||
|
url = self.wrapper.post('test message')
|
||||||
|
self.assertTrue(url is not None)
|
||||||
|
self.assertTrue(url.startswith('http://www.google.com/buzz/'))
|
||||||
|
|
||||||
|
def test_can_post_with_user_id(self):
|
||||||
|
url = self.wrapper.post('test message', '108242092577082601423')
|
||||||
|
self.assertTrue(url is not None)
|
||||||
|
self.assertTrue(url.startswith('http://www.google.com/buzz/'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
6
contrib_tests/test_account.oacurl.properties
Normal file
6
contrib_tests/test_account.oacurl.properties
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#Mon Oct 04 23:45:49 PDT 2010
|
||||||
|
#A set of credentials for posting as http://www.google.com/profiles/108242092577082601423
|
||||||
|
consumerSecret=anonymous
|
||||||
|
accessToken=1/80QKKG4CbMwOZjmW1udam-fVaiUOY1zO-8u3dhiLK6g
|
||||||
|
consumerKey=anonymous
|
||||||
|
accessTokenSecret=R6CnehJTZf9aKuSMtgkmX7KZ
|
||||||
@@ -5,15 +5,13 @@
|
|||||||
"""Discovery document tests
|
"""Discovery document tests
|
||||||
|
|
||||||
Functional tests that verify we can retrieve data from existing services.
|
Functional tests that verify we can retrieve data from existing services.
|
||||||
|
|
||||||
These tests are read-only in order to ensure they're repeatable. They also
|
|
||||||
only work with publicly visible data in order to avoid dealing with OAuth.
|
|
||||||
"""
|
"""
|
||||||
import httplib2
|
|
||||||
import pprint
|
|
||||||
|
|
||||||
__author__ = 'ade@google.com (Ade Oshineye)'
|
__author__ = 'ade@google.com (Ade Oshineye)'
|
||||||
|
|
||||||
|
import httplib2
|
||||||
|
import pprint
|
||||||
|
|
||||||
from apiclient.discovery import build
|
from apiclient.discovery import build
|
||||||
import httplib2
|
import httplib2
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
Reference in New Issue
Block a user