Exemplo n.º 1
0
    def test_cut_from_dict(self):
        # d = {"type":"point", "path":[2010]}
        # self.assertRaises(Exception, cubes.cut_from_dict, d)

        d = {"type":"point", "path":[2010], "dimension":"date",
                "level_depth":1, "hierarchy": None}
        cut = cubes.cut_from_dict(d)
        tcut = cubes.PointCut("date", [2010])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        d = {"type":"range", "from":[2010], "to":[2012, 10],
                "dimension":"date", "level_depth":2, "hierarchy":None}
        cut = cubes.cut_from_dict(d)
        tcut = cubes.RangeCut("date", [2010], [2012, 10])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        d = {"type":"set", "paths":[[2010], [2012, 10]],
                "dimension":"date", "level_depth":2, "hierarchy":None}
        cut = cubes.cut_from_dict(d)
        tcut = cubes.SetCut("date", [[2010], [2012, 10]])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        self.assertRaises(ArgumentError, cubes.cut_from_dict, {"type":"xxx"})
Exemplo n.º 2
0
    def report(self, cube):
        """Create multi-query report response."""
        self.create_browser(cube)
        self.prepare_cell()

        report_request = self.json_request()

        try:
            queries = report_request["queries"]
        except KeyError:
            help = "Wrap all your report queries under a 'queries' key. The " \
                    "old documentation was mentioning this requirement, however it " \
                    "was not correctly implemented and wrong example was provided."
            raise RequestError("Report request does not contain 'queries' key",
                                        help=help)

        cell_cuts = report_request.get("cell")

        if cell_cuts:
            # Override URL cut with the one in report
            cuts = [cubes.cut_from_dict(cut) for cut in cell_cuts]
            cell = cubes.Cell(self.browser.cube, cuts)
            self.logger.info("using cell from report specification (URL parameters are ignored)")
        else:
            cell = self.cell

        result = self.browser.report(cell, queries)

        return self.json_response(result)
Exemplo n.º 3
0
    def report(self, cube):
        """Create multi-query report response."""
        self.create_browser(cube)
        self.prepare_cell()

        report_request = self.json_request()

        try:
            queries = report_request["queries"]
        except KeyError:
            help = "Wrap all your report queries under a 'queries' key. The " \
                    "old documentation was mentioning this requirement, however it " \
                    "was not correctly implemented and wrong example was provided."
            raise RequestError("Report request does not contain 'queries' key",
                                        help=help)

        cell_cuts = report_request.get("cell")

        if cell_cuts:
            # Override URL cut with the one in report
            cuts = [cubes.cut_from_dict(cut) for cut in cell_cuts]
            cell = cubes.Cell(self.browser.cube, cuts)
            self.logger.info("using cell from report specification (URL parameters are ignored)")
        else:
            cell = self.cell

        result = self.browser.report(cell, queries)

        return self.json_response(result)
Exemplo n.º 4
0
    def test_cut_from_dict(self):
        # d = {"type":"point", "path":[2010]}
        # self.assertRaises(Exception, cubes.cut_from_dict, d)

        d = {
            "type": "point",
            "path": [2010],
            "dimension": "date",
            "level_depth": 1,
            "hierarchy": None
        }
        cut = cubes.cut_from_dict(d)
        tcut = cubes.PointCut("date", [2010])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        d = {
            "type": "range",
            "from": [2010],
            "to": [2012, 10],
            "dimension": "date",
            "level_depth": 2,
            "hierarchy": None
        }
        cut = cubes.cut_from_dict(d)
        tcut = cubes.RangeCut("date", [2010], [2012, 10])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        d = {
            "type": "set",
            "paths": [[2010], [2012, 10]],
            "dimension": "date",
            "level_depth": 2,
            "hierarchy": None
        }
        cut = cubes.cut_from_dict(d)
        tcut = cubes.SetCut("date", [[2010], [2012, 10]])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        self.assertRaises(ArgumentError, cubes.cut_from_dict, {"type": "xxx"})
Exemplo n.º 5
0
    def test_cut_from_dict(self):
        # d = {"type":"point", "path":[2010]}
        # self.assertRaises(Exception, cubes.cut_from_dict, d)
        
        d = {"type":"point", "path":[2010], "dimension":"date"}
        cut = cubes.cut_from_dict(d)
        tcut = cubes.PointCut("date", [2010])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        d = {"type":"range", "from":[2010], "to":[2012, 10], "dimension":"date"}
        cut = cubes.cut_from_dict(d)
        tcut = cubes.RangeCut("date", [2010], [2012, 10])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())

        d = {"type":"set", "paths":[[2010], [2012, 10]], "dimension":"date"}
        cut = cubes.cut_from_dict(d)
        tcut = cubes.SetCut("date", [[2010], [2012, 10]])
        self.assertEqual(tcut, cut)
        self.assertEqual(d, tcut.to_dict())
Exemplo n.º 6
0
    def make_report(self, request, cube_name):
        cube = self.get_cube(request, cube_name)
        browser = self.get_browser(cube)
        self.assert_enabled_action(request, browser, 'report')

        report_request = request.DATA
        try:
            queries = report_request["queries"]
        except KeyError:
            message = "Report request does not contain 'queries' key"
            logging.error(message)
            raise ParseError(detail=message)

        cell = self.get_cell(request, cube, restrict=True)
        cell_cuts = report_request.get("cell")

        if cell_cuts:
            # Override URL cut with the one in report
            cuts = [cut_from_dict(cut) for cut in cell_cuts]
            cell = Cell(cube, cuts)
            logging.info(
                "Using cell from report specification (URL parameters are ignored)"
            )

            if self.workspace.authorizer:
                cell = self.workspace.authorizer.restricted_cell(
                    request.user, cube=cube, cell=cell
                )
        else:
            if not cell:
                cell = Cell(cube)
            else:
                cell = cell

        report = browser.report(cell, queries)
        return Response(report)
Exemplo n.º 7
0
    def make_report(self, request, cube_name):
        cube = self.get_cube(request, cube_name)
        browser = self.get_browser(cube)
        self.assert_enabled_action(request, browser, 'report')

        report_request = request.DATA
        try:
            queries = report_request["queries"]
        except KeyError:
            message = "Report request does not contain 'queries' key"
            logging.error(message)
            raise ParseError(detail=message)

        cell = self.get_cell(request, cube, restrict=True)
        cell_cuts = report_request.get("cell")

        if cell_cuts:
            # Override URL cut with the one in report
            cuts = [cut_from_dict(cut) for cut in cell_cuts]
            cell = Cell(cube, cuts)
            logging.info(
                "Using cell from report specification (URL parameters are ignored)"
            )

            if self.workspace.authorizer:
                cell = self.workspace.authorizer.restricted_cell(request.user,
                                                                 cube=cube,
                                                                 cell=cell)
        else:
            if not cell:
                cell = Cell(cube)
            else:
                cell = cell

        report = browser.report(cell, queries)
        return Response(report)