コード例 #1
0
ファイル: tests.py プロジェクト: josuebrunel/myql
class TestRemoteFilters(unittest.TestCase):

    def setUp(self,):
        self.yql = YQL(diagnostics=True, )

    def test_remote_filter_get_count(self,):
        data = self.yql.get('geo.countries', remote_filter=(10,))
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_remote_filter_get_start_and_count(self,):
        data = self.yql.get('geo.countries', remote_filter=(100,10))
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
        

    def test_remote_filter_select_count(self,):
        data = self.yql.select('geo.counties', remote_filter=(20,)).where(['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
        
    def test_remote_filter_select_start_and_count(self,):
        data = self.yql.select('geo.counties', remote_filter=(60,20)).where(['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_raise_exception_remote_filter_not_tuple(self,):

        with self.assertRaises(TypeError):
            data = self.yql.get('geo.countries', remote_filter=10)
コード例 #2
0
ファイル: tests.py プロジェクト: kounkou/myql
class TestRemoteFilters(unittest.TestCase):
    def setUp(self, ):
        self.yql = YQL(diagnostics=True, )

    def test_remote_filter_get_count(self, ):
        data = self.yql.get('geo.countries', remote_filter=(10, ))
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_remote_filter_get_start_and_count(self, ):
        data = self.yql.get('geo.countries', remote_filter=(100, 10))
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_remote_filter_select_count(self, ):
        data = self.yql.select('geo.counties', remote_filter=(20, )).where(
            ['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_remote_filter_select_start_and_count(self, ):
        data = self.yql.select('geo.counties',
                               remote_filter=(60,
                                              20)).where(['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_raise_exception_remote_filter_not_tuple(self, ):

        with self.assertRaises(TypeError):
            data = self.yql.get('geo.countries', remote_filter=10)
コード例 #3
0
ファイル: tests.py プロジェクト: josuebrunel/myql
class TestPaging(unittest.TestCase):

    def setUp(self,):
        self.yql = YQL()

    def tearDown(self,):
        pass

    def test_limit(self,):
        data = self.yql.select('geo.states', limit=3, offset=2).where(['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
        self.assertEqual(data.json()['query']['count'], 3)

    def test_offset_raw_query(self,):
        data = self.yql.raw_query("SELECT * FROM geo.counties WHERE place='CA' LIMIT 10 OFFSET 5 | sort(field='name')")
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_offset_get(self,):
        data = self.yql.get('yql.table.list', limit=10, offset=3)
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_offset_select(self):
        data = self.yql.select('geo.counties', limit=10, offset=3).where(['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
コード例 #4
0
ファイル: tests.py プロジェクト: kounkou/myql
class TestPaging(unittest.TestCase):
    def setUp(self, ):
        self.yql = YQL()

    def tearDown(self, ):
        pass

    def test_limit(self, ):
        data = self.yql.select('geo.states', limit=3,
                               offset=2).where(['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
        self.assertEqual(data.json()['query']['count'], 3)

    def test_offset_raw_query(self, ):
        data = self.yql.raw_query(
            "SELECT * FROM geo.counties WHERE place='CA' LIMIT 10 OFFSET 5 | sort(field='name')"
        )
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_offset_get(self, ):
        data = self.yql.get('yql.table.list', limit=10, offset=3)
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_offset_select(self):
        data = self.yql.select('geo.counties', limit=10,
                               offset=3).where(['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
コード例 #5
0
ファイル: tests.py プロジェクト: josuebrunel/myql
class TestFilters(unittest.TestCase):

    def setUp(self,):
        self.yql = YQL()

    def tearDown(self,):
        pass

    def test_filter_not_equal(self,):
        data = self.yql.select('geo.countries', ['name', 'placeTypeName']).where(['name', 'like', 'A%'], ['placeTypeName.content', '!=', 'Country'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_greater_than_or_equal(self,):
        data = self.yql.select('geo.countries',['woeid', 'name', 'placeTypeName']).where(['place', '=', 'North America'], ['place.woeid', '>=', 56042304])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_less_than_or_equal(self,):
        data = self.yql.select('geo.countries',['name', 'placeTypeName']).where(['place', '=', 'North America'], ['place.woeid', '<=', 23424758])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_not_in(self,):
        data = self.yql.select('geo.countries',['name', 'placeTypeName']).where(['placeTypeName.content', 'NOT IN', ('Country','Territory','Overseas Collectivity')])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_is_null(self,):
        data = self.yql.select('youtube.user').where(['id','=','120u12a'], ['user.description','IS NULL'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_is_not_null(self,):
        data = self.yql.select('youtube.user').where(['id','=','120u12a'], ['user.description','IS NOT NULL'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_like(self,):
        data = self.yql.select('yql.table.list').where(['content','like','%apple%'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_not_like(self,):
        data = self.yql.select('geo.counties', ['name', 'placeTypeName']).where(['place', '=', 'CT'], ['name', 'NOT LIKE', '%d'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_matches(self,):
        data = self.yql.select('yql.table.list').where(['content','MATCHES','.*itunes$'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_not_matches(self,):
        data = self.yql.select('geo.countries', ['name', 'placeTypeName']).where(['placeTypeName.content','NOT MATCHES','^(Country|Territory)$'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
コード例 #6
0
class TestFilters(unittest.TestCase):

    def setUp(self,):
        self.yql = YQL()

    def tearDown(self,):
        pass

    def test_filter_not_equal(self,):
        data = self.yql.select('geo.countries', ['name', 'placeTypeName']).where(['name', 'like', 'A%'], ['placeTypeName.content', '!=', 'Country'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_greater_than_or_equal(self,):
        data = self.yql.select('geo.countries',['woeid', 'name', 'placeTypeName']).where(['place', '=', 'North America'], ['place.woeid', '>=', 56042304])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_less_than_or_equal(self,):
        data = self.yql.select('geo.countries',['name', 'placeTypeName']).where(['place', '=', 'North America'], ['place.woeid', '<=', 23424758])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_not_in(self,):
        data = self.yql.select('geo.countries',['name', 'placeTypeName']).where(['placeTypeName.content', 'NOT IN', ('Country','Territory','Overseas Collectivity')])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_is_null(self,):
        data = self.yql.select('youtube.user').where(['id','=','120u12a'], ['user.description','IS NULL'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_is_not_null(self,):
        data = self.yql.select('youtube.user').where(['id','=','120u12a'], ['user.description','IS NOT NULL'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_like(self,):
        data = self.yql.select('yql.table.list').where(['content','like','%apple%'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_not_like(self,):
        data = self.yql.select('geo.counties', ['name', 'placeTypeName']).where(['place', '=', 'CT'], ['name', 'NOT LIKE', '%d'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_matches(self,):
        data = self.yql.select('yql.table.list').where(['content','MATCHES','.*itunes$'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_filter_not_matches(self,):
        data = self.yql.select('geo.countries', ['name', 'placeTypeName']).where(['placeTypeName.content','NOT MATCHES','^(Country|Territory)$'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
コード例 #7
0
ファイル: tests.py プロジェクト: josuebrunel/myql
    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)
コード例 #8
0
    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)
コード例 #9
0
ファイル: tests.py プロジェクト: josuebrunel/myql
class TestFuncFilters(unittest.TestCase):

    def setUp(self,):
        self.yql = YQL()

    def tearDown(self,):
        pass

    def test_func_filter_reverse(self,):
        func_filters = ['reverse']
        data = self.yql.select('geo.states', func_filters=func_filters).where(['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_tail(self,):
        func_filters = [('tail', 2)]
        data = self.yql.select('geo.states', func_filters=func_filters).where(['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_truncate(self,):
        func_filters = [('truncate', 2)]
        data = self.yql.select('geo.states', func_filters=func_filters).where(['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_sanitize(self,):
        #func_filters = [('sanitize', '')]
        #data = self.yql.select('geo.states', func_filters=func_filters).where(['place', '=', 'Congo'])
        #logging.debug(pretty_json(data.content))
        #self.assertEqual(data.status_code, 200)
        pass

    def test_func_filter_sort(self,):
        func_filters = [
            {'sort': [
                ('field','name'),
                ('descending','true')
            ]},
            ('tail', 10),
            #('reverse')
        ]
        data = self.yql.select('geo.counties', func_filters=func_filters).where(['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_unique(self,):
        func_filters = [
            {'unique': [
                ('field','content'),
                ('hideRepeatCount','false')
            ]},
            ('truncate', 5)
        ]
        data = self.yql.get('yql.table.list', func_filters=func_filters)
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_raise_exception_func_filter(self):
        func_filters = 'unique'
        with self.assertRaises(TypeError):
           data =  self.yql.get('yql.table.list', func_filters=func_filters)

    def test_raise_exception_func_filter_invalid_type(self):
        func_filters = [30]
        with self.assertRaises(TypeError):
            data = self.yql.get('yql.table.list', func_filters=func_filters)
コード例 #10
0
ファイル: tests.py プロジェクト: josuebrunel/myql
 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)
コード例 #11
0
ファイル: tests.py プロジェクト: kounkou/myql
class TestFuncFilters(unittest.TestCase):
    def setUp(self, ):
        self.yql = YQL()

    def tearDown(self, ):
        pass

    def test_func_filter_reverse(self, ):
        func_filters = ['reverse']
        data = self.yql.select('geo.states', func_filters=func_filters).where(
            ['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_tail(self, ):
        func_filters = [('tail', 2)]
        data = self.yql.select('geo.states', func_filters=func_filters).where(
            ['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_truncate(self, ):
        func_filters = [('truncate', 2)]
        data = self.yql.select('geo.states', func_filters=func_filters).where(
            ['place', '=', 'Congo'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_sanitize(self, ):
        #func_filters = [('sanitize', '')]
        #data = self.yql.select('geo.states', func_filters=func_filters).where(['place', '=', 'Congo'])
        #logging.debug(pretty_json(data.content))
        #self.assertEqual(data.status_code, 200)
        pass

    def test_func_filter_sort(self, ):
        func_filters = [
            {
                'sort': [('field', 'name'), ('descending', 'true')]
            },
            ('tail', 10),
            #('reverse')
        ]
        data = self.yql.select('geo.counties',
                               func_filters=func_filters).where(
                                   ['place', '=', 'CA'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_func_filter_unique(self, ):
        func_filters = [{
            'unique': [('field', 'content'), ('hideRepeatCount', 'false')]
        }, ('truncate', 5)]
        data = self.yql.get('yql.table.list', func_filters=func_filters)
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_raise_exception_func_filter(self):
        func_filters = 'unique'
        with self.assertRaises(TypeError):
            data = self.yql.get('yql.table.list', func_filters=func_filters)

    def test_raise_exception_func_filter_invalid_type(self):
        func_filters = [30]
        with self.assertRaises(TypeError):
            data = self.yql.get('yql.table.list', func_filters=func_filters)
コード例 #12
0
ファイル: tests.py プロジェクト: kounkou/myql
 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)