def test_get_two_legged_request_keys(self): y = yql.TwoLegged('test-api-key', 'test-secret') # Accessed this was because it's private request = y._TwoLegged__two_legged_request('http://google.com') self.assertEqual(set(['oauth_nonce', 'oauth_version', 'oauth_timestamp', 'oauth_consumer_key', 'oauth_signature_method', 'oauth_body_hash', 'oauth_version', 'oauth_signature']), set(request.keys()))
def test_get_two_legged_from_file(self): query = 'SELECT * from foo' y = yql.TwoLegged('test-api-key', 'test-secret', httplib2_inst=httplib2.Http()) # Accessed this was because it's private self.assertTrue(y.execute(query) is not None)
def test_get_two_legged_request_values(self): y = yql.TwoLegged('test-api-key', 'test-secret') # Accessed this was because it's private request = y._TwoLegged__two_legged_request('http://google.com') self.assertEqual(request['oauth_consumer_key'], 'test-api-key') self.assertEqual(request['oauth_signature_method'], 'HMAC-SHA1') self.assertEqual(request['oauth_version'], '1.0')
def test_get_two_legged_request_param(): from httplib2 import Http y = yql.TwoLegged('test-api-key', 'test-secret') # Accessed this way because it's private request = y._TwoLegged__two_legged_request('http://google.com', {"test-param": "test"}) assert request.get('test-param') == 'test'
def test_public_request(self): """Test public two-legged request to flickr""" query = """select * from flickr.photos.search where text="panda" and api_key='%s' LIMIT 3""" % FLICKR_API_KEY y = yql.TwoLegged(YQL_API_KEY, YQL_SHARED_SECRET) res = y.execute(query) assert len(res.rows) == 3
def test_get_two_legged_request_values(): from httplib2 import Http y = yql.TwoLegged('test-api-key', 'test-secret') # Accessed this was because it's private request = y._TwoLegged__two_legged_request('http://google.com') assert request['oauth_consumer_key'] == 'test-api-key' assert request['oauth_signature_method'] == 'HMAC-SHA1' assert request['oauth_version'] == '1.0'
def test_two_legged_weather_select(self): """Tests the weather tables using two-legged""" query = """select * from weather.forecast where location in (select id from xml where url='http://xoap.weather.com/search/search?where=london' and itemPath='search.loc')""" y = yql.TwoLegged(YQL_API_KEY, YQL_SHARED_SECRET) res = y.execute(query) assert len(res.rows) > 1
def test_get_two_legged_request_values(self): y = yql.TwoLegged('test-api-key', 'test-secret') y.endpoint = "http://query.yahooapis.com/v1/yql" # Accessed this was because it's private request = y._TwoLegged__two_legged_request() self.assertTrue(y.endpoint.startswith("http")) self.assertEqual(request['oauth_consumer_key'], 'test-api-key') self.assertEqual(request['oauth_signature_method'], 'HMAC-SHA1') self.assertEqual(request['oauth_version'], '1.0')
def test_get_two_legged_request_keys(): from httplib2 import Http y = yql.TwoLegged('test-api-key', 'test-secret') # Accessed this was because it's private request = y._TwoLegged__two_legged_request('http://google.com') assert set([ 'oauth_nonce', 'oauth_version', 'oauth_timestamp', 'oauth_consumer_key', 'oauth_signature_method', 'oauth_version', 'oauth_signature' ]) == set(request.keys())
def test_write_bitly_url(self): """Test writing bit.ly url""" query = """USE 'http://www.datatables.org/bitly/bit.ly.shorten.xml'; SELECT * from bit.ly.shorten where login='******' and apiKey='%s' and longUrl='http://yahoo.com'""" % (BITLY_USER, BITLY_API_KEY) y = yql.TwoLegged(YQL_API_KEY, YQL_SHARED_SECRET) res = y.execute(query) assert res.one()["data"]["url"] == "http://yhoo.it/9PPTOr"
def yql_request(query): """ Update locations older than x days using YQL. """ API_KEY = getattr(settings, "YQL_API_KEY", None) SECRET = getattr(settings, "YQL_CONSUMER_SECRET", None) if not API_KEY and not SECRET: raise Exception('No api key and secret found.') y = yql.TwoLegged(API_KEY, SECRET) try: result = y.execute(query) except yql.YQLError as e: raise e logger.debug("%s" % query) return result
def test_get_two_legged_request_param(self): y = yql.TwoLegged('test-api-key', 'test-secret') # Accessed this way because it's private request = y._TwoLegged__two_legged_request('http://google.com', {"test-param": "test"}) self.assertEqual(request.get('test-param'), 'test')
def test_api_key_and_secret_attrs(self): y = yql.TwoLegged('test-api-key', 'test-secret') self.assertEqual(y.api_key, 'test-api-key') self.assertEqual(y.secret, 'test-secret')
def test_get_two_legged_from_file(): query = 'SELECT * from foo' from httplib2 import Http y = yql.TwoLegged('test-api-key', 'test-secret', httplib2_inst=Http()) # Accessed this was because it's private assert y.execute(query) is not None
def test_api_key_and_secret_attrs(): from httplib2 import Http y = yql.TwoLegged('test-api-key', 'test-secret') assert y.api_key == 'test-api-key' assert y.secret == 'test-secret'