예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #9
0
파일: tests.py 프로젝트: josuebrunel/myql
 def setUp(self,):
     self.yql = YQL()
예제 #10
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)
예제 #11
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)
예제 #12
0
파일: tests.py 프로젝트: kounkou/myql
 def setUp(self, ):
     self.yql = YQL(diagnostics=True, )
예제 #13
0
파일: tests.py 프로젝트: kounkou/myql
 def setUp(self, ):
     self.yql = YQL()
예제 #14
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)
예제 #15
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)
예제 #16
0
파일: tests.py 프로젝트: josuebrunel/myql
 def setUp(self,):
     self.yql = YQL(diagnostics=True, )
예제 #17
0
파일: tests.py 프로젝트: kounkou/myql
 def setUp(self, ):
     self.oauth = OAuth1(None, None, from_file='credentials.json')
     self.yql = YQL(oauth=self.oauth)