def test_get_rows(self): context = DataContext() view = DataView() # Unless we tell the function to evaluate the rows, it should return # rows as a generator so we need to exclicitly evaluate it here. result = utils.get_result_rows(context, view, {}) self.assertEqual(len(list(result['rows'])), Employee.objects.count()) # Now, have the method evaluate the rows. result = utils.get_result_rows(context, view, {}, evaluate_rows=True) self.assertEqual(len(result['rows']), Employee.objects.count())
def test_pages(self): context = DataContext() view = DataView() query_options = { 'page': 1, 'stop_page': 10, } result = utils.get_result_rows(context, view, query_options) self.assertEqual(len(list(result['rows'])), Employee.objects.count()) query_options = { 'page': 1, 'stop_page': 1, } result = utils.get_result_rows(context, view, query_options) self.assertEqual(len(list(result['rows'])), Employee.objects.count())
def get(self, request, **kwargs): params = self.get_params(request) # Get the request's view and context view = self.get_view(request) context = self.get_context(request) # Configure the query options used for retrieving the results. query_options = { 'export_type': HTMLExporter.short_name, 'query_name': self._get_query_name(request), } query_options.update(**kwargs) query_options.update(params) try: row_data = utils.get_result_rows(context, view, query_options, request=request) except ValueError: raise Http404 return process_results(request, PREVIEW_RESULT_PROCESSOR_NAME, row_data)
def test_export_type(self): context = DataContext() view = DataView() export_type = 'json' query_options = { 'export_type': export_type, } result = utils.get_result_rows(context, view, query_options) self.assertEqual(len(list(result['rows'])), Employee.objects.count()) self.assertEqual(result['export_type'], export_type)
def test_processor(self): context = DataContext() view = DataView() processor = 'manager' query_options = { 'processor': processor, } result = utils.get_result_rows(context, view, query_options) self.assertEqual(len(list(result['rows'])), Employee.objects.filter(is_manager=True).count()) self.assertTrue(isinstance(result['processor'], ManagerQueryProcessor))
def test_limit(self): context = DataContext() view = DataView() limit = 2 query_options = { 'limit': limit, 'page': 1, } result = utils.get_result_rows(context, view, query_options) self.assertEqual(len(list(result['rows'])), limit) self.assertEqual(result['limit'], limit)
def test_get_order_only(self): field = DataField.objects.get(field_name='salary') concept = field.concepts.all()[0] context = DataContext() view = DataView(json=[{ 'concept': concept.pk, 'visible': False, 'sort': 'desc', }]) result = utils.get_result_rows(context, view, {}) self.assertEqual(len(list(result['rows'])), Employee.objects.count())
def get(self, request, **kwargs): params = self.get_params(request) # Configure the query options used for retrieving the results. query_options = { 'export_type': JSONExporter.short_name.lower(), 'query_name': self._get_query_name(request), } query_options.update(**kwargs) query_options.update(params) try: row_data = query_utils.get_result_rows(request.instance.context, request.instance.view, query_options, request=request) except ValueError: raise Http404 return process_results(request, QUERY_RESULT_PROCESSOR_NAME, row_data)
def get(self, request, export_type, **kwargs): view = self.get_view(request) context = self.get_context(request) params = self.get_params(request) # Configure the query options used for retrieving the results. query_options = { 'export_type': export_type, 'query_name': self._get_query_name(request, export_type), } query_options.update(**kwargs) query_options.update(params) try: row_data = utils.get_result_rows(context, view, query_options) except ValueError: raise Http404 return process_results( request, EXPORTER_RESULT_PROCESSOR_NAME, row_data)
def get(self, request, **kwargs): params = self.get_params(request) # Configure the query options used for retrieving the results. query_options = { 'export_type': JSONExporter.short_name.lower(), 'query_name': self._get_query_name(request), } query_options.update(**kwargs) query_options.update(params) try: row_data = query_utils.get_result_rows( request.instance.context, request.instance.view, query_options) except ValueError: raise Http404 return process_results( request, QUERY_RESULT_PROCESSOR_NAME, row_data)
def get(self, request, **kwargs): params = self.get_params(request) # Get the request's view and context view = self.get_view(request) context = self.get_context(request) # Configure the query options used for retrieving the results. query_options = { 'export_type': HTMLExporter.short_name, 'query_name': self._get_query_name(request), } query_options.update(**kwargs) query_options.update(params) try: row_data = utils.get_result_rows(context, view, query_options, request=request) except ValueError: raise Http404 return process_results( request, PREVIEW_RESULT_PROCESSOR_NAME, row_data)