Example #1
0
    def test_key_label_attributes(self):
        attrs = [Attribute('code')]
        level = Level('product', attrs)
        self.assertIsInstance(level.key, Attribute)
        self.assertEqual('code', str(level.key))

        attrs = [Attribute('code'), Attribute('name')]
        level = Level('product', attrs)
        self.assertIsInstance(level.key, Attribute)
        self.assertEqual('code', str(level.key))

        attrs = [Attribute('info'), Attribute('code'), Attribute('name')]
        level = Level('product', attrs, key='code')
        self.assertIsInstance(level.key, Attribute)
        self.assertEqual('code', str(level.key))

        # Test key/label in full desc
        desc = {
            'name': 'product',
            'attributes': ['info', 'code', 'name'],
            'key': 'code'
        }

        level = Level.load(desc)
        self.assertIsInstance(level.key, Attribute)
        self.assertEqual('code', str(level.key))
Example #2
0
 def setUp(self):
     self.levels = [
         Level('year', attributes=Attribute.load_list(['year'])),
         Level('month',
               attributes=Attribute.load_list(
                   ['month', 'month_name', 'month_sname'])),
         Level('day', attributes=Attribute.load_list(['day'])),
         Level('week', attributes=Attribute.load_list(['week'])),
     ]
     self.level_names = [level.name for level in self.levels]
     self.dimension = Dimension('date', levels=self.levels)
Example #3
0
    def test_comparison(self):
        attrs = [Attribute('info'), Attribute('code'), Attribute('name')]
        level1 = Level('product', attrs, key='code')
        level2 = Level('product', attrs, key='code')
        level3 = Level('product', attrs)
        attrs = [Attribute('month'), Attribute('month_name')]
        level4 = Level('product', attrs)

        self.assertEqual(level1, level2)
        self.assertNotEqual(level2, level3)
        self.assertNotEqual(level2, level4)
Example #4
0
    def test_simplify(self):
        level = Level('name', attributes=[Attribute('name')])
        dim = Dimension('group', ref='_group', levels=[level])

        attr = dim.get_attribute('name')
        self.assertEqual('group.name', attr.name)
        self.assertEqual('_group.name', attr.ref)

        self.assertEqual('group', str(dim))

        level = Level('name', attributes=[Attribute('key'), Attribute('name')])
        dim = Dimension('group', levels=[level])
        attr = dim.get_attribute('name')
        self.assertEqual('name', attr.base_name)
        self.assertEqual('group.name', attr.name)
        self.assertEqual('group.name', str(attr))
        self.assertEqual('group.name', attr.ref)
Example #5
0
    def test_level_inherit(self):
        desc = {
            'name': 'product_type',
        }

        level = Level.load(desc)
        self.assertEqual(1, len(level.attributes))

        attr = level.attributes[0]
        self.assertEqual('product_type', attr.name)
Example #6
0
    def test_create(self):
        desc = 'year'
        level = Level.load(desc)
        self.assertIsInstance(level, Level)
        self.assertEqual('year', level.name)
        self.assertEqual(['year'], [str(a) for a in level.attributes])

        # Test default: Attributes
        desc = {'name': 'year'}
        level = Level.load(desc)
        self.assertIsInstance(level, Level)
        self.assertEqual('year', level.name)
        self.assertEqual(['year'], [str(a) for a in level.attributes])

        # Test default: Attributes
        desc = {'name': 'year', 'attributes': ['key']}
        level = Level.load(desc)
        self.assertIsInstance(level, Level)
        self.assertEqual('year', level.name)
        self.assertEqual(['key'], [str(a) for a in level.attributes])

        desc = {'name': 'year', 'attributes': ['key', 'label']}
        level = Level.load(desc)
        self.assertEqual(['key', 'label'], [str(a) for a in level.attributes])

        # Level from description with full details
        desc = {
            'name':
            'month',
            'attributes': [{
                'name': 'month'
            }, {
                'name': 'month_name'
            }, {
                'name': 'month_sname'
            }]
        }

        level = Level.load(desc)
        self.assertEqual(3, len(level.attributes))
        names = [str(a) for a in level.attributes]
        self.assertEqual(['month', 'month_name', 'month_sname'], names)
Example #7
0
    def test_create_attribute(self):
        level = Level('name', attributes=[Attribute('key'), Attribute('name')])
        dim = Dimension('group', levels=[level])

        obj = Attribute.load('name')
        self.assertIsInstance(obj, Attribute)
        self.assertEqual('name', obj.name)

        obj = Attribute.load({'name': 'key'})
        obj.dimension = dim
        self.assertIsInstance(obj, Attribute)
        self.assertEqual('key', obj.base_name)
        self.assertEqual('group.key', obj.name)
        self.assertEqual(dim, obj.dimension)

        obj = dim.get_attribute('key')
        obj.dimension = dim
        self.assertIsInstance(obj, Attribute)
        self.assertEqual('key', obj.base_name)
        self.assertEqual('group.key', obj.name)
Example #8
0
 def test_operators(self):
     attrs = [Attribute('foo')]
     self.assertEqual('date', str(Level('date', attrs)))