Ejemplo n.º 1
0
    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())
Ejemplo n.º 2
0
    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())
Ejemplo n.º 3
0
    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())
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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())
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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))
Ejemplo n.º 9
0
 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))
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
    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())
Ejemplo n.º 13
0
    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())
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
    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)