def test_basic(self): md = {} with self.assertRaises(ModelError): measure = create_measure(md) measure = create_measure("amount") self.assertIsInstance(measure, Measure) self.assertEqual("amount", measure.name) md = {"name": "amount"} measure = create_measure(md) self.assertEqual("amount", measure.name)
def test_create_default_aggregates(self): measure = create_measure("amount") aggs = measure.default_aggregates() self.assertEqual(1, len(aggs)) agg = aggs[0] self.assertEqual("amount_sum", agg.name) self.assertEqual("amount", agg.measure) self.assertEqual("sum", agg.function) self.assertIsNone(agg.formula) md = {"name": "amount", "aggregates": ["sum", "min"]} measure = create_measure(md) aggs = measure.default_aggregates() self.assertEqual(2, len(aggs)) self.assertEqual("amount_sum", aggs[0].name) self.assertEqual("amount", aggs[0].measure) self.assertEqual("sum", aggs[0].function) self.assertIsNone(aggs[0].formula) self.assertEqual("amount_min", aggs[1].name) self.assertEqual("amount", aggs[1].measure) self.assertEqual("min", aggs[1].function) self.assertIsNone(aggs[1].formula)
def test_copy(self): md = {"name": "amount"} measure = create_measure(md) measure2 = copy.deepcopy(measure) self.assertEqual(measure, measure2)