Beispiel #1
0
    def test_template(self):
        dims = {"date": self.dimension}
        desc = {"template": "date", "name": "date"}

        dim = cubes.create_dimension(desc, dims)
        self.assertEqual(self.dimension, dim)
        hier = dim.hierarchy()
        self.assertEqual(4, len(hier.levels))

        desc["hierarchy"] = ["year", "month"]
        dim = cubes.create_dimension(desc, dims)
        self.assertEqual(1, len(dim.hierarchies))
        hier = dim.hierarchy()
        self.assertEqual(2, len(hier.levels))

        template = self.dimension.to_dict()
        template["hierarchies"] = [
            {"name": "ym", "levels": ["year", "month"]},
            {"name": "ymd", "levels": ["year", "month", "day"]}
        ]

        template["default_hierarchy_name"] = "ym"
        template = cubes.create_dimension(template)
        dims = {"date": template}
        desc = {"template": "date", "name":"another_date"}
        dim = cubes.create_dimension(desc, dims)
        self.assertEqual(2, len(dim.hierarchies))
        self.assertEqual(["ym", "ymd"],
                         [hier.name for hier in dim.hierarchies.values()])
Beispiel #2
0
    def test_template_info(self):
        md = {
            "name": "template",
            "levels": [{
                "name": "one",
                "info": {
                    "units": "$",
                    "format": "foo"
                }
            }]
        }
        tempdim = create_dimension(md)

        md = {
            "name": "dim",
            "levels": [{
                "name": "one",
                "info": {
                    "units": "USD"
                }
            }],
            "template": "template"
        }

        templates = {"template": tempdim}
        dim = create_dimension(md, templates)

        level = dim.level("one")
        self.assertIn("units", level.info)
        self.assertIn("format", level.info)
        self.assertEqual(level.info["units"], "USD")
        self.assertEqual(level.info["format"], "foo")
Beispiel #3
0
    def test_template_hierarchies(self):
        md = {
            "name": "time",
            "levels": ["year", "month", "day", "hour"],
            "hierarchies": [
                {"name": "full", "levels": ["year", "month", "day", "hour"]},
                {"name": "ymd", "levels": ["year", "month", "day"]},
                {"name": "ym", "levels": ["year", "month"]},
                {"name": "y", "levels": ["year"]},
            ]
        }
        dim_time = cubes.create_dimension(md)
        templates = {"time": dim_time}
        md = {
            "name": "date",
            "template": "time",
            "hierarchies": [
                "ymd", "ym", "y"
            ]
        }

        dim_date = cubes.create_dimension(md, templates)

        self.assertEqual(dim_date.name, "date")
        self.assertEqual(len(dim_date.hierarchies), 3)
        names = [h.name for h in dim_date.hierarchies.values()]
        self.assertEqual(["ymd", "ym", "y"], names)
Beispiel #4
0
    def test_template_info(self):
        md = {
            "name": "template",
            "levels": [
                { "name": "one", "info": {"units":"$", "format": "foo"}}
            ]
        }
        tempdim = cubes.create_dimension(md)

        md = {
            "name": "dim",
            "levels": [
                { "name": "one", "info": {"units":"USD"}}
            ],
            "template": "template"
        }

        templates = {"template": tempdim}
        dim = cubes.create_dimension(md, templates)

        level = dim.level("one")
        self.assertIn("units", level.info)
        self.assertIn("format", level.info)
        self.assertEqual(level.info["units"], "USD")
        self.assertEqual(level.info["format"], "foo")
Beispiel #5
0
    def setUp(self):
        engine = create_engine('sqlite://')
        self.connection = engine.connect()
        self.metadata = MetaData()
        self.metadata.bind = engine

        self.table_name = "test"

        # Prepare table
        table = sqlalchemy.Table(self.table_name, self.metadata)
        table.append_column(Column("id", String))
        table.append_column(Column("color", String))
        table.append_column(Column("tone", String))
        table.append_column(Column("size", String))
        table.append_column(Column("temperature", String))
        table.create(self.connection)

        self.table = table

        # Prepare model
        self.model = cubes.Model()
        self.cube = cubes.Cube("test")
        self.model.add_cube(self.cube)

        desc = {"name": "color", "levels": ["color", "tone"]}
        dimension = cubes.create_dimension(desc)
        self.cube.add_dimension(dimension)

        dimension = cubes.create_dimension("size")
        self.cube.add_dimension(dimension)
Beispiel #6
0
    def test_template(self):
        dims = {"date": self.dimension}
        desc = {"template": "date", "name": "date"}

        dim = create_dimension(desc, dims)
        self.assertEqual(self.dimension, dim)
        hier = dim.hierarchy()
        self.assertEqual(4, len(hier.levels))

        desc["hierarchy"] = ["year", "month"]
        dim = create_dimension(desc, dims)
        self.assertEqual(1, len(dim.hierarchies))
        hier = dim.hierarchy()
        self.assertEqual(2, len(hier.levels))

        template = self.dimension.to_dict()
        template["hierarchies"] = [{
            "name": "ym",
            "levels": ["year", "month"]
        }, {
            "name": "ymd",
            "levels": ["year", "month", "day"]
        }]

        template["default_hierarchy_name"] = "ym"
        template = create_dimension(template)
        dims = {"date": template}
        desc = {"template": "date", "name": "another_date"}
        dim = create_dimension(desc, dims)
        self.assertEqual(2, len(dim.hierarchies))
        self.assertEqual(["ym", "ymd"],
                         [hier.name for hier in dim.hierarchies])
Beispiel #7
0
    def setUp(self):
        engine = create_engine('sqlite://')
        self.connection = engine.connect()
        self.metadata = MetaData()
        self.metadata.bind = engine
        
        self.table_name = "test"
        
        # Prepare table
        table = sqlalchemy.Table(self.table_name, self.metadata)
        table.append_column(Column("id", String))
        table.append_column(Column("color", String))
        table.append_column(Column("tone", String))
        table.append_column(Column("size", String))
        table.append_column(Column("temperature", String))
        table.create(self.connection)

        self.table = table

        # Prepare model
        self.model = cubes.Model()
        self.cube = cubes.Cube("test")
        self.model.add_cube(self.cube)

        desc = {"name": "color", "levels":["color", "tone"]}
        dimension = cubes.create_dimension(desc)
        self.cube.add_dimension(dimension)

        dimension = cubes.create_dimension("size")
        self.cube.add_dimension(dimension)
Beispiel #8
0
    def test_dimension_validation(self):
        date_desc = {
            "name": "date",
            "levels": [{
                "name": "year",
                "attributes": ["year"]
            }]
        }
        dim = cubes.create_dimension(date_desc)
        self.assertEqual(1, len(dim.levels))
        results = dim.validate()
        self.assertValidation(results, "No levels")
        self.assertValidation(results, "No defaut hierarchy")

        # FIXME: uncomment this after implementing https://github.com/Stiivi/cubes/issues/8
        # self.assertValidationError(results, "No hierarchies in dimension", expected_type = "default")

        date_desc = {"name": "date", "levels": self.date_levels}
        dim = cubes.create_dimension(date_desc)
        results = dim.validate()

        # FIXME: uncomment this after implementing https://github.com/Stiivi/cubes/issues/8
        # self.assertValidationError(results, "No hierarchies in dimension.*more", expected_type = "error")

        date_desc = {
            "name": "date",
            "levels": self.date_levels,
            "hierarchies": self.date_hiers
        }
        dim = cubes.create_dimension(date_desc)
        results = dim.validate()

        self.assertValidation(results, "No levels in dimension",
                              "Dimension is invalid without levels")
        self.assertValidation(results, "No hierarchies in dimension",
                              "Dimension is invalid without hierarchies")
        # self.assertValidationError(results, "No default hierarchy name")

        dim.default_hierarchy_name = 'foo'
        results = dim.validate()
        self.assertValidationError(results, "Default hierarchy .* does not")
        self.assertValidation(results, "No default hierarchy name")

        dim.default_hierarchy_name = 'ym'
        results = dim.validate()
        self.assertValidation(results, "Default hierarchy .* does not")

        date_desc = {
            "name": "date",
            "levels": self.date_levels2,
            "hierarchies": self.date_hiers2
        }
        dim = cubes.create_dimension(date_desc)
        results = dim.validate()
        self.assertValidationError(results,
                                   "No defaut hierarchy .* more than one")
Beispiel #9
0
    def test_comparisons(self):
        """Comparison of dimension instances"""

        dim1 = cubes.create_dimension(DIM_DATE_DESC)
        dim2 = cubes.create_dimension(DIM_DATE_DESC)

        self.assertListEqual(dim1.levels, dim2.levels)
        self.assertListEqual(dim1.hierarchies.items(), dim2.hierarchies.items())

        self.assertEqual(dim1, dim2)
Beispiel #10
0
    def test_comparisons(self):
        """Comparison of dimension instances"""

        dim1 = create_dimension(DIM_DATE_DESC)
        dim2 = create_dimension(DIM_DATE_DESC)

        self.assertListEqual(dim1.levels, dim2.levels)
        self.assertListEqual(dim1.hierarchies, dim2.hierarchies)

        self.assertEqual(dim1, dim2)
Beispiel #11
0
    def test_template(self):
        dims = {"date":self.dimension}
        desc = {"template":"date", "name":"date"}
        dim = cubes.create_dimension(desc, dims)
        self.assertEqual(self.dimension, dim)
        hier = dim.hierarchy()
        self.assertEqual(4, len(hier.levels))

        desc["hierarchy"] = ["year", "month"]
        dim = cubes.create_dimension(desc, dims)
        self.assertEqual(1, len(dim.hierarchies))
        hier = dim.hierarchy()
        self.assertEqual(2, len(hier.levels))
Beispiel #12
0
 def setUp(self):
     a = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]
     self.measures = cubes.attribute_list(["amount", "discount"])
     self.dimensions = [cubes.create_dimension(desc) for desc in a]
     self.cube = cubes.Cube("contracts",
                             dimensions=self.dimensions,
                             measures=self.measures)
Beispiel #13
0
    def test_to_dict(self):
        desc = self.dimension.to_dict()
        dim = cubes.create_dimension(desc)

        self.assertEqual(self.dimension.hierarchies, dim.hierarchies)
        self.assertEqual(self.dimension.levels, dim.levels)
        self.assertEqual(self.dimension, dim)
Beispiel #14
0
    def test_to_dict(self):
        desc = self.dimension.to_dict()
        dim = cubes.create_dimension(desc)

        self.assertEqual(self.dimension.hierarchies, dim.hierarchies)
        self.assertEqual(self.dimension.levels, dim.levels)
        self.assertEqual(self.dimension, dim)
Beispiel #15
0
 def setUp(self):
     a = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]
     self.measures = cubes.attribute_list(["amount", "discount"])
     self.dimensions = [cubes.create_dimension(desc) for desc in a]
     self.cube = cubes.Cube("contracts",
                            dimensions=self.dimensions,
                            measures=self.measures)
Beispiel #16
0
 def setUp(self):
     a = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]
     self.measures = cubes.attribute_list(["amount", "discount"])
     self.dimensions = [cubes.create_dimension(desc) for desc in a]
     self.cube = cubes.Cube("contracts",
                            dimensions=self.dimensions,
                            measures=self.measures)
     self.model = cubes.Model(cubes=[self.cube], dimensions=self.dimensions)
     self.model_path = os.path.join(DATA_PATH, 'model.json')
Beispiel #17
0
 def setUp(self):
     a = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]
     self.measures = attribute_list(["amount", "discount"], Measure)
     self.details = attribute_list(["detail"], Attribute)
     self.dimensions = [create_dimension(desc) for desc in a]
     self.cube = Cube("contracts",
                      dimensions=self.dimensions,
                      measures=self.measures,
                      details=self.details)
Beispiel #18
0
 def setUp(self):
     a = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]
     self.measures = attribute_list(["amount", "discount"], Measure)
     self.details = attribute_list(["detail"], Attribute)
     self.dimensions = [create_dimension(desc) for desc in a]
     self.cube = Cube("contracts",
                             dimensions=self.dimensions,
                             measures=self.measures,
                             details=self.details)
Beispiel #19
0
 def setUp(self):
     a = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]
     self.measures = cubes.attribute_list(["amount", "discount"])
     self.dimensions = [cubes.create_dimension(desc) for desc in a]
     self.cube = cubes.Cube("contracts",
                             dimensions=self.dimensions,
                             measures=self.measures)
     self.model = cubes.Model(cubes=[self.cube],
                              dimensions=self.dimensions)
     self.model_path = os.path.join(DATA_PATH, 'model.json')
Beispiel #20
0
    def test_dimension_validation(self):
        date_desc = { "name": "date",
                      "levels": [
                            {"name": "year", "attributes": ["year"]}
                         ]
                    }
        dim = cubes.create_dimension(date_desc)
        self.assertEqual(1, len(dim.levels))
        results = dim.validate()
        self.assertValidation(results, "No levels")
        self.assertValidation(results, "No defaut hierarchy")

        # FIXME: uncomment this after implementing https://github.com/Stiivi/cubes/issues/8
        # self.assertValidationError(results, "No hierarchies in dimension", expected_type = "default")

        date_desc = { "name": "date", "levels": self.date_levels}
        dim = cubes.create_dimension(date_desc)
        results = dim.validate()

        # FIXME: uncomment this after implementing https://github.com/Stiivi/cubes/issues/8
        # self.assertValidationError(results, "No hierarchies in dimension.*more", expected_type = "error")

        date_desc = { "name": "date", "levels": self.date_levels , "hierarchies": self.date_hiers }
        dim = cubes.create_dimension(date_desc)
        results = dim.validate()

        self.assertValidation(results, "No levels in dimension", "Dimension is invalid without levels")
        self.assertValidation(results, "No hierarchies in dimension", "Dimension is invalid without hierarchies")
        # self.assertValidationError(results, "No default hierarchy name")

        dim.default_hierarchy_name = 'foo'
        results = dim.validate()
        self.assertValidationError(results, "Default hierarchy .* does not")
        self.assertValidation(results, "No default hierarchy name")

        dim.default_hierarchy_name = 'ym'
        results = dim.validate()
        self.assertValidation(results, "Default hierarchy .* does not")

        date_desc = { "name": "date", "levels": self.date_levels2 , "hierarchies": self.date_hiers2 }
        dim = cubes.create_dimension(date_desc)
        results = dim.validate()
        self.assertValidationError(results, "No defaut hierarchy .* more than one")
Beispiel #21
0
    def test_create(self):
        """Dimension from a dictionary"""
        dim = cubes.create_dimension("year")
        self.assertIsInstance(dim, cubes.Dimension)
        self.assertEqual("year", dim.name)
        self.assertEqual(["year"], [str(a) for a in dim.all_attributes()])

        # Test default: explicit level attributes
        desc = {"name": "date", "levels": ["year"]}
        dim = cubes.create_dimension(desc)
        self.assertTrue(dim.is_flat)
        self.assertFalse(dim.has_details)
        self.assertIsInstance(dim, cubes.Dimension)
        self.assertEqual("date", dim.name)
        self.assertEqual(["year"], [str(a) for a in dim.all_attributes()])

        desc = {"name": "date", "levels": ["year", "month", "day"]}
        dim = cubes.create_dimension(desc)
        self.assertIsInstance(dim, cubes.Dimension)
        self.assertEqual("date", dim.name)
        names = [str(a) for a in dim.all_attributes()]
        self.assertEqual(["year", "month", "day"], names)
        self.assertFalse(dim.is_flat)
        self.assertFalse(dim.has_details)
        self.assertEqual(3, len(dim.levels))
        for level in dim.levels:
            self.assertIsInstance(level, cubes.Level)
        self.assertEqual(1, len(dim.hierarchies))
        self.assertEqual(3, len(dim.hierarchy()))

        # Test default: implicit single level attributes
        desc = {"name": "product", "attributes": ["code", "name"]}
        dim = cubes.create_dimension(desc)
        names = [str(a) for a in dim.all_attributes()]
        self.assertEqual(["code", "name"], names)
        self.assertEqual(1, len(dim.levels))
        self.assertEqual(1, len(dim.hierarchies))

        self.assertRaises(cubes.ModelInconsistencyError,
                          cubes.Dimension,
                          "date",
                          levels=["year", "month"])
Beispiel #22
0
    def test_create(self):
        """Dimension from a dictionary"""
        dim = cubes.create_dimension("year")
        self.assertIsInstance(dim, cubes.Dimension)
        self.assertEqual("year", dim.name)
        self.assertEqual(["year"], [str(a) for a in dim.all_attributes()])

        # Test default: explicit level attributes
        desc = { "name":"date", "levels":["year"] }
        dim = cubes.create_dimension(desc)
        self.assertTrue(dim.is_flat)
        self.assertFalse(dim.has_details)
        self.assertIsInstance(dim, cubes.Dimension)
        self.assertEqual("date", dim.name)
        self.assertEqual(["year"], [str(a) for a in dim.all_attributes()])

        desc = { "name":"date", "levels":["year", "month", "day"] }
        dim = cubes.create_dimension(desc)
        self.assertIsInstance(dim, cubes.Dimension)
        self.assertEqual("date", dim.name)
        names = [str(a) for a in dim.all_attributes()]
        self.assertEqual(["year", "month", "day"], names)
        self.assertFalse(dim.is_flat)
        self.assertFalse(dim.has_details)
        self.assertEqual(3, len(dim.levels))
        for level in dim.levels:
            self.assertIsInstance(level, cubes.Level)
        self.assertEqual(1, len(dim.hierarchies))
        self.assertEqual(3, len(dim.hierarchy()))

        # Test default: implicit single level attributes
        desc = { "name":"product", "attributes":["code", "name"] }
        dim = cubes.create_dimension(desc)
        names = [str(a) for a in dim.all_attributes()]
        self.assertEqual(["code", "name"], names)
        self.assertEqual(1, len(dim.levels))
        self.assertEqual(1, len(dim.hierarchies))

        self.assertRaises(cubes.ModelInconsistencyError,
                     cubes.Dimension, "date", levels=["year", "month"])
Beispiel #23
0
    def setUp(self):
        super(ModelTestCase, self).setUp()

        a = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]
        self.measures = cubes.attribute_list(["amount", "discount"], Measure)
        self.dimensions = [cubes.create_dimension(desc) for desc in a]
        self.cube = cubes.Cube("contracts",
                                dimensions=self.dimensions,
                                measures=self.measures)
        self.model = cubes.Model(cubes=[self.cube],
                                 dimensions=self.dimensions)

        self.model_file = "model.json"
Beispiel #24
0
    def test_template_hierarchies(self):
        md = {
            "name":
            "time",
            "levels": ["year", "month", "day", "hour"],
            "hierarchies": [
                {
                    "name": "full",
                    "levels": ["year", "month", "day", "hour"]
                },
                {
                    "name": "ymd",
                    "levels": ["year", "month", "day"]
                },
                {
                    "name": "ym",
                    "levels": ["year", "month"]
                },
                {
                    "name": "y",
                    "levels": ["year"]
                },
            ]
        }
        dim_time = create_dimension(md)
        templates = {"time": dim_time}
        md = {
            "name": "date",
            "template": "time",
            "hierarchies": ["ymd", "ym", "y"]
        }

        dim_date = create_dimension(md, templates)

        self.assertEqual(dim_date.name, "date")
        self.assertEqual(len(dim_date.hierarchies), 3)
        names = [h.name for h in dim_date.hierarchies]
        self.assertEqual(["ymd", "ym", "y"], names)
Beispiel #25
0
    def test_flat_dimension(self):
        """Flat dimension and 'has details' flags"""
        dim = cubes.create_dimension("foo")
        self.assertTrue(dim.is_flat)
        self.assertFalse(dim.has_details)
        self.assertEqual(1, len(dim.levels))

        level = dim.level("foo")
        self.assertIsInstance(level, cubes.Level)
        self.assertEqual("foo", level.name)
        self.assertEqual(1, len(level.attributes))
        self.assertEqual("foo", str(level.key))

        attr = level.attributes[0]
        self.assertIsInstance(attr, cubes.Attribute)
        self.assertEqual("foo", attr.name)
Beispiel #26
0
    def test_flat_dimension(self):
        """Flat dimension and 'has details' flags"""
        dim = cubes.create_dimension("foo")
        self.assertTrue(dim.is_flat)
        self.assertFalse(dim.has_details)
        self.assertEqual(1, len(dim.levels))

        level = dim.level("foo")
        self.assertIsInstance(level, cubes.Level)
        self.assertEqual("foo", level.name)
        self.assertEqual(1, len(level.attributes))
        self.assertEqual("foo", str(level.key))

        attr = level.attributes[0]
        self.assertIsInstance(attr, cubes.Attribute)
        self.assertEqual("foo", attr.name)
Beispiel #27
0
    def test_inherit_nonadditive(self):
        dims = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]

        cube = {
            "name": "contracts",
            "dimensions": ["date", "product"],
            "nonadditive": "time",
            "measures": ["amount", "discount"]
        }

        dims = [create_dimension(md) for md in dims]
        dims = dict((dim.name, dim) for dim in dims)

        cube = create_cube(cube)

        measures = cube.measures
        self.assertEqual(measures[0].nonadditive, "time")
Beispiel #28
0
    def test_inherit_nonadditive(self):
        dims = [DIM_DATE_DESC, DIM_PRODUCT_DESC, DIM_FLAG_DESC]

        cube = {
            "name": "contracts",
            "dimensions": ["date", "product"],
            "nonadditive": "time",
            "measures": ["amount", "discount"]
        }

        dims = [cubes.create_dimension(md) for md in dims]
        dims = dict((dim.name, dim) for dim in dims)

        cube = cubes.create_cube(cube)

        measures = cube.measures
        self.assertEqual(measures[0].nonadditive, "time")
Beispiel #29
0
    def setUp(self):
        date_desc = { "name": "date", 
                      "levels": { 
                                    "year": { 
                                        "key": "year", 
                                        "attributes": [
                                            {
                                                "name":"year",
                                                "order":"ascending"
                                            }
                                            ]
                                        }, 
                                    "month": {
                                        "key": "month", 
                                        "attributes": [
                                            {"name":"month", "order":"ascending"},
                                            {"name":"month_name"}] }
                                } , 
                       "default_hierarchy": "ym",
                       "hierarchies": { 
                                "ym": { 
                                    "levels": ["year", "month"]
                                } 
                        }
                    }

        class_desc = { "name": "cls", 
                      "levels": { 
                                    "group": { "key": "group_id", "attributes": ["group_id", "group_desc"] }, 
                                    "class": { "key": "class_id", "attributes": ["class_id", "class_desc"] }
                                } , 
                       "default_hierarchy": "default",
                       "hierarchies": { 
                                "default": { 
                                    "levels": ["group", "class"]
                                } 
                        }
                    }
                    
        cube = {
            "name": "testcube",
        }
        
        self.date_dim = cubes.create_dimension(date_desc)
        self.class_dim = cubes.create_dimension(class_desc)
        dims = [self.date_dim, self.class_dim]

        self.model = cubes.Model('test', dimensions=dims)
        self.cube = cubes.Cube("testcube", dimensions=dims)

        self.model.add_cube(self.cube)
        
        self.cube.measures = [cubes.Attribute("amount")]
        self.cube.mappings = {
                                "amount": "ft_contracts.amount",
                                "date.year": "dm_date.year",
                                "date.month": "dm_date.month",
                                "date.month_name": "dm_date.month_name",
                                "cls.group_id": "dm_cls.group_id",
                                "cls.class_id": "dm_cls.class_id",
                                "cls.group_desc": "dm_cls.group_desc",
                                "cls.class_desc": "dm_cls.class_desc",
                                "cls.id": "dm_cls.id",
                                "date.id": "dm_date.id",
                                "fact.date_id": "ft_contracts.date_id",
                                "fact.cls_id": "ft_contracts.cls_id"
                             }
        self.cube.fact = "ft_contracts"
        self.mappings2 = {
                              "amount": "ft_contracts.amount"
                           }
        self.cube.joins = [
                            { "master": "fact.date_id", "detail": "date.id"},
                            { "master": "fact.cls_id", "detail": "cls.id"}
                            ]

        self.prepare_data()
Beispiel #30
0
    def setUp(self):
        date_desc = {
            "name": "date",
            "levels": {
                "year": {
                    "key": "year",
                    "attributes": [{
                        "name": "year",
                        "order": "ascending"
                    }]
                },
                "month": {
                    "key":
                    "month",
                    "attributes": [{
                        "name": "month",
                        "order": "ascending"
                    }, {
                        "name": "month_name"
                    }]
                }
            },
            "default_hierarchy": "ym",
            "hierarchies": {
                "ym": {
                    "levels": ["year", "month"]
                }
            }
        }

        class_desc = {
            "name": "cls",
            "levels": {
                "group": {
                    "key": "group_id",
                    "attributes": ["group_id", "group_desc"]
                },
                "class": {
                    "key": "class_id",
                    "attributes": ["class_id", "class_desc"]
                }
            },
            "default_hierarchy": "default",
            "hierarchies": {
                "default": {
                    "levels": ["group", "class"]
                }
            }
        }

        cube = {
            "name": "testcube",
        }

        self.date_dim = cubes.create_dimension(date_desc)
        self.class_dim = cubes.create_dimension(class_desc)
        dims = [self.date_dim, self.class_dim]

        self.model = cubes.Model('test', dimensions=dims)
        self.cube = cubes.Cube("testcube", dimensions=dims)

        self.model.add_cube(self.cube)

        self.cube.measures = [cubes.Attribute("amount")]
        self.cube.mappings = {
            "amount": "ft_contracts.amount",
            "date.year": "dm_date.year",
            "date.month": "dm_date.month",
            "date.month_name": "dm_date.month_name",
            "cls.group_id": "dm_cls.group_id",
            "cls.class_id": "dm_cls.class_id",
            "cls.group_desc": "dm_cls.group_desc",
            "cls.class_desc": "dm_cls.class_desc",
            "cls.id": "dm_cls.id",
            "date.id": "dm_date.id",
            "fact.date_id": "ft_contracts.date_id",
            "fact.cls_id": "ft_contracts.cls_id"
        }
        self.cube.fact = "ft_contracts"
        self.mappings2 = {"amount": "ft_contracts.amount"}
        self.cube.joins = [{
            "master": "fact.date_id",
            "detail": "date.id"
        }, {
            "master": "fact.cls_id",
            "detail": "cls.id"
        }]

        self.prepare_data()
Beispiel #31
0
    def test_should_not_accept_unknown_dimension(self):
        foo_desc = { "name": "foo", "levels": {"level": {"key": "boo"}}}
        foo_dim = cubes.create_dimension(foo_desc)

        self.assertRaises(AttributeError, cubes.common.all_cuboids,
                                          self.cube.dimensions, [foo_dim])
Beispiel #32
0
    def test_should_not_accept_unknown_dimension(self):
        foo_desc = {"name": "foo", "levels": {"level": {"key": "boo"}}}
        foo_dim = cubes.create_dimension(foo_desc)

        self.assertRaises(AttributeError, cubes.common.all_cuboids,
                          self.cube.dimensions, [foo_dim])