def test_yahoo_fantasy_sport(self,): oauth = OAuth1(None, None, from_file='credentials.json') yql = MYQL(format='json', oauth=oauth) teams = ('mlb.l.1328.t.1','mlb.l.1328.t.2') year = '2015-05-05' for team in teams: response = yql.select('fantasysports.teams.roster').where(['team_key','=',team],['date','=',year]) self.assertEqual(response.status_code, 200) if not response.status_code == 200: return False data = response.json() try: current_team = data['query']['results']['team'] print(current_team['team_id'],current_team['name'],current_team['number_of_trades'],current_team['number_of_moves']) except (Exception,) as e: print(e)
def test_yahoo_fantasy_sport(self,): oauth = OAuth1(None, None, from_file='credentials.json') yql = MYQL(format='json', oauth=oauth) teams = ('mlb.l.1328.t.1','mlb.l.1328.t.2') year = '2015-05-05' for team in teams: response = yql.select('fantasysports.teams.roster').where(['team_key','=',team],['date','=',year]) self.assertEqual(response.status_code, 200) if not response.status_code == 200: return False data = response.json() try: current_team = data['query']['results']['team'] print((current_team['team_id'],current_team['name'],current_team['number_of_trades'],current_team['number_of_moves'])) except (Exception,) as e: print(e)
class TestMYQL(unittest.TestCase): def setUp(self,): self.yql = MYQL(format='json',community=True) self.insert_result = None def tearDown(self): pass def test_desc(self,): response = self.yql.desc('weather.forecast') logging.debug(prettyfy(response, 'json')) self.assertEqual(response.status_code, 200) def test_show_tables(self,): yql = MYQL(format='xml', community=False) response = yql.show_tables(format='xml') logging.debug(prettyfy(response, 'xml')) self.assertEqual(response.status_code, 200) def test_use(self): self.yql.use('http://www.josuebrunel.org/users.xml',name='users') response = self.yql.raw_query('select * from users', format='xml') self.yql.yql_table_url = None logging.debug(pretty_xml(response.content)) self.assertEqual(response.status_code, 200) def test_raw_query(self,): response = self.yql.raw_query('select name, woeid from geo.states where place="Congo"') logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_get(self,): self.yql.format = 'xml' response = self.yql.get('geo.countries', ['name', 'woeid'], 1) self.yql.format = 'json' logging.debug(pretty_xml(response.content)) self.assertEqual(response.status_code, 200) def test_select(self,): response = self.yql.select('geo.countries', ['name', 'code', 'woeid']).where(['name', '=', 'Canada']) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_select_in(self,): response = self.yql.select('yahoo.finance.quotes').where(['symbol','in',("YHOO","AAPL","GOOG")]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_select_in_2(self,): response = self.yql.select('weather.forecast',['units','atmosphere']).where(['woeid','IN',('select woeid from geo.places(1) where text="Paris"',)]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_raise_exception_select_where_in(self,): with self.assertRaises(TypeError): response = self.yql.select('weather.forecast',['units','atmosphere']).where(['woeid','IN',('select woeid from geo.places(1) where text="Paris"')]) def test_1_insert(self,): response = self.yql.insert('yql.storage.admin',('value',),('http://josuebrunel.org',)) try: logging.debug(pretty_json(response.content)) data = response.json()['query']['results']['inserted'] logging.debug(data) json_write_data(data,'yql_storage.json') except (Exception,) as e: logging.error(response.content) logging.error(e) self.assertEqual(response.status_code, 200) def test_2_check_insert(self,): json_data = json_get_data('yql_storage.json') response = self.yql.select('yql.storage').where(['name','=',json_data['select']]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_3_update(self,): json_data = json_get_data('yql_storage.json') response = self.yql.update('yql.storage',('value',),('https://josuebrunel.org',)).where(['name','=',json_data['update']]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_4_delete(self,): json_data = json_get_data('yql_storage.json') response = self.yql.delete('yql.storage').where(['name','=',json_data['update']]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_cross_product(self): yql = YQL(format='xml', crossProduct=True) response = yql.select('weather.forecast').where(['location', '=', '90210']) logging.debug("{0} {1}".format(response.status_code, response.reason)) self.assertEqual(response.status_code, 200) def test_variable_substitution(self,): yql = YQL() var = {'home': 'Congo'} yql.set(var) response = yql.select('geo.states', remote_filter=(5,)).where(['place', '=', '@home']) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_raise_exception_no_table_selected(self): with self.assertRaises(NoTableSelectedError): response = self.yql.select(None).where([])
class TestMYQL(unittest.TestCase): def setUp(self, ): self.yql = MYQL(format='json', community=True) self.insert_result = None def tearDown(self): pass def test_desc(self, ): response = self.yql.desc('weather.forecast') logging.debug(prettyfy(response, 'json')) self.assertEqual(response.status_code, 200) def test_show_tables(self, ): yql = MYQL(format='xml', community=False) response = yql.show_tables(format='xml') logging.debug(prettyfy(response, 'xml')) self.assertEqual(response.status_code, 200) def test_use(self): self.yql.use('http://www.josuebrunel.org/users.xml', name='users') response = self.yql.raw_query('select * from users', format='xml') self.yql.yql_table_url = None logging.debug(pretty_xml(response.content)) self.assertEqual(response.status_code, 200) def test_raw_query(self, ): response = self.yql.raw_query( 'select name, woeid from geo.states where place="Congo"') logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_get(self, ): self.yql.format = 'xml' response = self.yql.get('geo.countries', ['name', 'woeid'], 1) self.yql.format = 'json' logging.debug(pretty_xml(response.content)) self.assertEqual(response.status_code, 200) def test_select(self, ): response = self.yql.select('geo.countries', ['name', 'code', 'woeid']).where( ['name', '=', 'Canada']) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_select_in(self, ): response = self.yql.select('yahoo.finance.quotes').where( ['symbol', 'in', ("YHOO", "AAPL", "GOOG")]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_select_in_2(self, ): response = self.yql.select( 'weather.forecast', ['units', 'atmosphere']).where([ 'woeid', 'IN', ('select woeid from geo.places(1) where text="Paris"', ) ]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_raise_exception_select_where_in(self, ): with self.assertRaises(TypeError): response = self.yql.select( 'weather.forecast', ['units', 'atmosphere']).where([ 'woeid', 'IN', ('select woeid from geo.places(1) where text="Paris"') ]) def test_1_insert(self, ): response = self.yql.insert('yql.storage.admin', ('value', ), ('http://josuebrunel.org', )) try: logging.debug(pretty_json(response.content)) data = response.json()['query']['results']['inserted'] logging.debug(data) json_write_data(data, 'yql_storage.json') except (Exception, ) as e: logging.error(response.content) logging.error(e) self.assertEqual(response.status_code, 200) def test_2_check_insert(self, ): json_data = json_get_data('yql_storage.json') response = self.yql.select('yql.storage').where( ['name', '=', json_data['select']]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_3_update(self, ): json_data = json_get_data('yql_storage.json') response = self.yql.update('yql.storage', ('value', ), ('https://josuebrunel.org', )).where( ['name', '=', json_data['update']]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_4_delete(self, ): json_data = json_get_data('yql_storage.json') response = self.yql.delete('yql.storage').where( ['name', '=', json_data['update']]) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_cross_product(self): yql = YQL(format='xml', crossProduct=True) response = yql.select('weather.forecast').where( ['location', '=', '90210']) logging.debug("{0} {1}".format(response.status_code, response.reason)) self.assertEqual(response.status_code, 200) def test_variable_substitution(self, ): yql = YQL() var = {'home': 'Congo'} yql.set(var) response = yql.select('geo.states', remote_filter=(5, )).where( ['place', '=', '@home']) logging.debug(pretty_json(response.content)) self.assertEqual(response.status_code, 200) def test_raise_exception_no_table_selected(self): with self.assertRaises(NoTableSelectedError): response = self.yql.select(None).where([])