def test_sql_query_should_contain_one_like_stmt(self): query_string = "abc" dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertEqual( 3, len( dpq._build_sql_query(query, filters).whereclause._from_objects))
def search_packages(): """ Data Package Search --- tags: - search parameters: - in: query name: q type: string required: true description: search query string e.g. q=query publisher=pub responses: 500: description: Internal Server Error 200: description: Success Message schema: id: search_package_success properties: total_count: type: integer description: Total datapackage count items: type: list properties: type: object """ q = request.args.get('q') if q is None: q = '' limit = request.args.get('limit') result = DataPackageQuery(query_string=q.strip(), limit=limit).get_data() return jsonify(dict(items=result, total_count=len(result)))
def test_get_data_should_return_all_data_by_publisher(self): query_string = "* publisher:pub1" dpq = DataPackageQuery(query_string) self.assertEqual(3, len(dpq.get_data())) query_string = "* publisher:pub3" dpq = DataPackageQuery(query_string) self.assertEqual(0, len(dpq.get_data()))
def test_should_return_data_package_with_limit(self): query_string = "details publisher:pub1" dpq = DataPackageQuery(query_string, limit=5) self.assertEqual(3, len(dpq.get_data())) query_string = "details publisher:pub1 publisher:pub2" dpq = DataPackageQuery(query_string, limit=3) self.assertEqual(3, len(dpq.get_data()))
def test_should_take_first_query_occurrence(self): query_string = "bca publisher:pub1 publisher:pub2 abc " dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertEqual('bca', query) self.assertEqual(2, len(filters)) query_string = "publisher:pub1 publisher:pub2 abc " dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertEqual('abc', query) self.assertEqual(2, len(filters))
def test_sql_query_should_contain_join_stmt(self): query_string = "abc publisher:core" dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertEqual( 2, len(dpq._build_sql_query(query, filters)._join_entities))
def test_should_contain_multiple_filters(self): query_string = "publisher:pub1 publisher:pub2 abc " dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertEqual('abc', query) self.assertEqual(2, len(filters))
def test_should_return_query(self): query_string = "abc" dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertEqual('abc', query) self.assertEqual(0, len(filters))
def test_should_return_query_and_filter(self): query_string = "abc publisher:core" dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertEqual('abc', query) self.assertEqual('publisher:core', filters[0])
def test_should_not_visible_after_soft_delete(self): logic.Package.delete(self.pub1_name, 'pack1') query_string = "details publisher:pub1" dpq = DataPackageQuery(query_string, limit=3) self.assertEqual(2, len(dpq.get_data()))
def test_limit_should_be_maximum_1000(self): dpq = DataPackageQuery('details publisher:pub1', limit=1005) self.assertEqual(1000, dpq.limit)
def test_should_return_data_package_containing_query(self): query_string = "none-query publisher:pub1" dpq = DataPackageQuery(query_string) self.assertEqual(0, len(dpq.get_data())) query_string = "one publisher:pub1" dpq = DataPackageQuery(query_string) self.assertEqual(1, len(dpq.get_data())) self.assertEqual('pub1', dpq.get_data()[0]['publisher_name']) query_string = "details publisher:pub1" dpq = DataPackageQuery(query_string) self.assertEqual(3, len(dpq.get_data())) query_string = "details publisher:pub1 publisher:pub2" dpq = DataPackageQuery(query_string) self.assertEqual(6, len(dpq.get_data()))
def test_get_data_should_return_all_data_contains_query_string(self): query_string = "*" dpq = DataPackageQuery(query_string) self.assertEqual(6, len(dpq.get_data()))
def test_sql_query_should_not_contain_like_stmt(self): query_string = "*" dpq = DataPackageQuery(query_string) query, filters = dpq._parse_query_string() self.assertIsNone(dpq._build_sql_query(query, filters).whereclause)