Пример #1
0
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([])
Пример #2
0
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([])