Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)