Ejemplo n.º 1
0
class ModelTestCase(TestCase):

    def setUp(self):
        super(ModelTestCase, self).setUp()
        self.simple_model_data = load_json_fixture('models/simple_model.json')
        self.simple_model = Model(self.simple_model_data)

    def test_model_concepts(self):
        concepts = list(self.simple_model.concepts)
        assert len(concepts) == 7, len(concepts)

    def test_model_match(self):
        concepts = list(self.simple_model.match('foo'))
        assert len(concepts) == 1, len(concepts)

    def test_model_match_invalid(self):
        concepts = list(self.simple_model.match('fooxx'))
        assert len(concepts) == 0, len(concepts)

    def test_model_aggregates(self):
        aggregates = list(self.simple_model.aggregates)
        assert len(aggregates) == 2, aggregates

    def test_model_fact_table(self):
        assert self.simple_model.fact_table_name == 'simple'
        assert 'simple' in repr(self.simple_model), repr(self.simple_model)

    def test_deref(self):
        assert self.simple_model['foo'].name == 'foo'
        assert self.simple_model['foo.key'].name == 'key'
        assert self.simple_model['amount'].name == 'amount'
        assert 'amount' in self.simple_model
        assert 'amount.sum' in self.simple_model
        assert '_count' in self.simple_model
        assert 'yabba' not in self.simple_model
        assert 'foo.key' in self.simple_model

    def test_repr(self):
        assert 'amount' in repr(self.simple_model['amount'])
        assert 'amount.sum' in repr(self.simple_model['amount.sum'])
        assert 'foo.key' in repr(self.simple_model['foo.key'])
        assert 'foo' in repr(self.simple_model['foo'])
        assert 'foo' in unicode(self.simple_model['foo'])
        assert self.simple_model['foo'] == 'foo'

    def test_to_dict(self):
        data = self.simple_model.to_dict()
        assert 'measures' in data
        assert 'amount' in data['measures']
        assert 'amount.sum' in data['aggregates']
        assert 'ref' in data['measures']['amount']
        assert 'dimensions' in data
        assert 'foo' in data['dimensions']
Ejemplo n.º 2
0
 def __init__(self, engine, name, model, fact_table=None):
     self.name = name
     if not isinstance(model, Model):
         model = Model(model)
     self._fact_table = fact_table
     self.model = model
     self.engine = engine
     self.meta = MetaData(bind=engine)
Ejemplo n.º 3
0
 def model(self):
     if self._model is None:
         if not self.fact_table.exists:
             return
         data = self.data.get('model')
         if not isinstance(data, dict):
             return
         data['fact_table'] = self.fact_table.table_name
         model = Model(data)
         if not model.exists:
             return
         self._model = model
     return self._model
Ejemplo n.º 4
0
 def setUp(self):
     super(ModelTestCase, self).setUp()
     self.simple_model_data = load_json_fixture('models/simple_model.json')
     self.simple_model = Model(self.simple_model_data)
Ejemplo n.º 5
0
 def setUp(self):
     super(ModelTestCase, self).setUp()
     self.simple_model_data = load_json_fixture('models/simple_model.json')
     self.simple_model = Model(self.simple_model_data)
Ejemplo n.º 6
0
 def model(self):
     if not hasattr(self, '_model') or self._model is None:
         self._model = Model(self.spec.get('model', {}))
     return self._model