Пример #1
0
    def indicators(self):
        default_indicators = [IndicatorFactory.from_spec({
            "column_id": "doc_id",
            "type": "expression",
            "display_name": "document id",
            "datatype": "string",
            "is_nullable": False,
            "is_primary_key": True,
            "expression": {
                "type": "root_doc",
                "expression": {
                    "type": "property_name",
                    "property_name": "_id"
                }
            }
        }, self.named_filter_objects)]

        default_indicators.append(IndicatorFactory.from_spec({
            "type": "inserted_at",
        }, self.named_filter_objects))

        if self.base_item_expression:
            default_indicators.append(IndicatorFactory.from_spec({
                "type": "repeat_iteration",
            }, self.named_filter_objects))
        return CompoundIndicator(
            self.display_name,
            default_indicators + [
                IndicatorFactory.from_spec(indicator, self.named_filter_objects)
                for indicator in self.configured_indicators
            ]
        )
Пример #2
0
 def testBadFilterType(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'column_id': 'col',
             'filter': 'wrong type',
         })
Пример #3
0
 def testEmptyFilter(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'column_id': 'col',
             'filter': None,
         })
Пример #4
0
 def testEmptyFilter(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'column_id': 'col',
             'filter': None,
         })
Пример #5
0
    def default_indicators(self):
        default_indicators = [IndicatorFactory.from_spec({
            "column_id": "doc_id",
            "type": "expression",
            "display_name": "document id",
            "datatype": "string",
            "is_nullable": False,
            "is_primary_key": True,
            "expression": {
                "type": "root_doc",
                "expression": {
                    "type": "property_name",
                    "property_name": "_id"
                }
            }
        }, self._get_factory_context())]

        default_indicators.append(IndicatorFactory.from_spec({
            "type": "inserted_at",
        }, self._get_factory_context()))

        if self.base_item_expression:
            default_indicators.append(IndicatorFactory.from_spec({
                "type": "repeat_iteration",
            }, self._get_factory_context()))

        return default_indicators
Пример #6
0
 def testBadFilterType(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'column_id': 'col',
             'filter': 'wrong type',
         })
Пример #7
0
    def indicators(self):
        default_indicators = [IndicatorFactory.from_spec({
            "column_id": "doc_id",
            "type": "expression",
            "display_name": "document id",
            "datatype": "string",
            "is_nullable": False,
            "is_primary_key": True,
            "expression": {
                "type": "root_doc",
                "expression": {
                    "type": "property_name",
                    "property_name": "_id"
                }
            }
        }, self.named_filter_objects)]

        default_indicators.append(IndicatorFactory.from_spec({
            "type": "inserted_at",
        }, self.named_filter_objects))

        if self.base_item_expression:
            default_indicators.append(IndicatorFactory.from_spec({
                "type": "repeat_iteration",
            }, self.named_filter_objects))
        return CompoundIndicator(
            self.display_name,
            default_indicators + [
                IndicatorFactory.from_spec(indicator, self.named_filter_objects)
                for indicator in self.configured_indicators
            ]
        )
Пример #8
0
    def default_indicators(self):
        default_indicators = [
            IndicatorFactory.from_spec(
                {
                    "column_id": "doc_id",
                    "type": "expression",
                    "display_name": "document id",
                    "datatype": "string",
                    "is_nullable": False,
                    "is_primary_key": True,
                    "expression": {
                        "type": "root_doc",
                        "expression": {
                            "type": "property_name",
                            "property_name": "_id"
                        }
                    }
                }, self.get_factory_context())
        ]

        default_indicators.append(
            IndicatorFactory.from_spec({
                "type": "inserted_at",
            }, self.get_factory_context()))

        if self.base_item_expression:
            default_indicators.append(
                IndicatorFactory.from_spec({
                    "type": "repeat_iteration",
                }, self.get_factory_context()))

        return default_indicators
Пример #9
0
 def testNoColumnId(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'filter': {
                 'type': 'property_match',
                 'property_name': 'foo',
                 'property_value': 'bar',
             }
         })
Пример #10
0
 def testInvalidFilter(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'column_id': 'col',
             'filter': {
                 'type': 'property_match',
                 'property_value': 'bar',
             }
         })
Пример #11
0
 def testNoColumnId(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'filter': {
                 'type': 'property_match',
                 'property_name': 'foo',
                 'property_value': 'bar',
             }
         })
Пример #12
0
 def testInvalidFilter(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': 'boolean',
             'column_id': 'col',
             'filter': {
                 'type': 'property_match',
                 'property_value': 'bar',
             }
         })
Пример #13
0
 def testEmptyColumnId(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': self.indicator_type,
             'column_id': '',
             'filter': {
                 'type': 'property_match',
                 'property_name': 'foo',
                 'property_value': 'bar',
             }
         })
Пример #14
0
 def testEmptyColumnId(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': self.indicator_type,
             'column_id': '',
             'filter': {
                 'type': 'property_match',
                 'property_name': 'foo',
                 'property_value': 'bar',
             }
         })
Пример #15
0
 def test_not_null_filter_root_doc(self):
     indicator = IndicatorFactory.from_spec(
         {
             "filter": {
                 "filter": {
                     "operator": "in",
                     "expression": {
                         "expression": {
                             "datatype": None,
                             "type": "property_name",
                             "property_name": "ccs_opened_date"
                         },
                         "type": "root_doc"
                     },
                     "type": "boolean_expression",
                     "property_value": [
                         "",
                         None
                     ]
                 },
                 "type": "not"
             },
             "type": self.indicator_type,
             "display_name": None,
             "column_id": "prop1_not_null"
         }
     )
     self._check_result(indicator, {}, 1, EvaluationContext(root_doc=dict(ccs_opened_date='not_null')))
     self._check_result(indicator, {}, 1, EvaluationContext(root_doc=dict(ccs_opened_date=' ')))
     self._check_result(indicator, {}, 0, EvaluationContext(root_doc=dict(ccs_opened_date='')))
     self._check_result(indicator, {}, 0, EvaluationContext(root_doc=dict(ccs_opened_date=None)))
     self._check_result(indicator, {}, 0, EvaluationContext(root_doc=dict()))
Пример #16
0
 def test_not_null_filter_root_doc(self):
     indicator = IndicatorFactory.from_spec(
         {
             "filter": {
                 "filter": {
                     "operator": "in",
                     "expression": {
                         "expression": {
                             "datatype": None,
                             "type": "property_name",
                             "property_name": "ccs_opened_date"
                         },
                         "type": "root_doc"
                     },
                     "type": "boolean_expression",
                     "property_value": [
                         "",
                         None
                     ]
                 },
                 "type": "not"
             },
             "type": self.indicator_type,
             "display_name": None,
             "column_id": "prop1_not_null"
         }
     )
     self._check_result(indicator, {}, 1, EvaluationContext(root_doc=dict(ccs_opened_date='not_null')))
     self._check_result(indicator, {}, 1, EvaluationContext(root_doc=dict(ccs_opened_date=' ')))
     self._check_result(indicator, {}, 0, EvaluationContext(root_doc=dict(ccs_opened_date='')))
     self._check_result(indicator, {}, 0, EvaluationContext(root_doc=dict(ccs_opened_date=None)))
     self._check_result(indicator, {}, 0, EvaluationContext(root_doc=dict()))
Пример #17
0
 def complex_indicator(self):
     # this expression is the equivalent to:
     #   doc.true_value if doc.test == 'match' else doc.false_value
     return IndicatorFactory.from_spec({
         "type": "expression",
         "expression": {
             'type': 'conditional',
             'test': {
                 'type': 'boolean_expression',
                 'expression': {
                     'type': 'property_name',
                     'property_name': 'test',
                 },
                 'operator': 'eq',
                 'property_value': 'match',
             },
             'expression_if_true': {
                 'type': 'property_name',
                 'property_name': 'true_value',
             },
             'expression_if_false': {
                 'type': 'property_name',
                 'property_name': 'false_value',
             },
         },
         "column_id": "foo",
         "datatype": "string",
         "display_name": "expression foos",
     })
Пример #18
0
 def complex_indicator(self):
     # this expression is the equivalent to:
     #   doc.true_value if doc.test == 'match' else doc.false_value
     return IndicatorFactory.from_spec({
         "type": "expression",
         "expression": {
             'type': 'conditional',
             'test': {
                 'type': 'boolean_expression',
                 'expression': {
                     'type': 'property_name',
                     'property_name': 'test',
                 },
                 'operator': 'eq',
                 'property_value': 'match',
             },
             'expression_if_true': {
                 'type': 'property_name',
                 'property_name': 'true_value',
             },
             'expression_if_false': {
                 'type': 'property_name',
                 'property_name': 'false_value',
             },
         },
         "column_id": "foo",
         "datatype": "string",
         "display_name": "expression foos",
     })
Пример #19
0
 def testCount(self):
     indicator = IndicatorFactory.from_spec({
         "type": "count",
         "column_id": "count",
         "display_name": "Count"
     })
     self._check_result(indicator, dict(), 1)
Пример #20
0
 def testCount(self):
     indicator = IndicatorFactory.from_spec({
         "type": "count",
         "column_id": "count",
         "display_name": "Count"
     })
     self._check_result(indicator, dict(), 1)
Пример #21
0
    def testComplexStructure(self):
        # in slightly more compact format:
        # ((foo=bar) or (foo1=bar1 and foo2=bar2 and (foo3=bar3 or foo4=bar4)))
        indicator = IndicatorFactory.from_spec({
            "type": self.indicator_type,
            "column_id": "col",
            "filter": {
                "type": "or",
                "filters": [
                    {
                        "type": "property_match",
                        "property_name": "foo",
                        "property_value": "bar"
                    },
                    {
                        "type": "and",
                        "filters": [
                            {
                                "type": "property_match",
                                "property_name": "foo1",
                                "property_value": "bar1"
                            },
                            {
                                "type": "property_match",
                                "property_name": "foo2",
                                "property_value": "bar2"
                            },
                            {
                                "type": "or",
                                "filters": [
                                    {
                                        "type": "property_match",
                                        "property_name": "foo3",
                                        "property_value": "bar3"
                                    },
                                    {
                                        "type": "property_match",
                                        "property_name": "foo4",
                                        "property_value": "bar4"
                                    }
                                ]
                            },
                        ]
                    },
                ]
            }
        })
        # first level or
        self._check_result(indicator, dict(foo='bar'), 1)
        # first level and with both or's
        self._check_result(indicator, dict(foo1='bar1', foo2='bar2', foo3='bar3'), 1)
        self._check_result(indicator, dict(foo1='bar1', foo2='bar2', foo4='bar4'), 1)

        # first and not right
        self._check_result(indicator, dict(foo1='not bar1', foo2='bar2', foo3='bar3'), 0)
        # second and not right
        self._check_result(indicator, dict(foo1='bar1', foo2='not bar2', foo3='bar3'), 0)
        # last and not right
        self._check_result(indicator, dict(foo1='bar1', foo2='bar2', foo3='not bar3', foo4='not bar4'), 0)
Пример #22
0
    def testComplexStructure(self):
        # in slightly more compact format:
        # ((foo=bar) or (foo1=bar1 and foo2=bar2 and (foo3=bar3 or foo4=bar4)))
        indicator = IndicatorFactory.from_spec({
            "type": "boolean",
            "column_id": "col",
            "filter": {
                "type": "or",
                "filters": [
                    {
                        "type": "property_match",
                        "property_name": "foo",
                        "property_value": "bar"
                    },
                    {
                        "type": "and",
                        "filters": [
                            {
                                "type": "property_match",
                                "property_name": "foo1",
                                "property_value": "bar1"
                            },
                            {
                                "type": "property_match",
                                "property_name": "foo2",
                                "property_value": "bar2"
                            },
                            {
                                "type": "or",
                                "filters": [
                                    {
                                        "type": "property_match",
                                        "property_name": "foo3",
                                        "property_value": "bar3"
                                    },
                                    {
                                        "type": "property_match",
                                        "property_name": "foo4",
                                        "property_value": "bar4"
                                    }
                                ]
                            },
                        ]
                    },
                ]
            }
        })
        # first level or
        self._check_result(indicator, dict(foo='bar'), 1)
        # first level and with both or's
        self._check_result(indicator, dict(foo1='bar1', foo2='bar2', foo3='bar3'), 1)
        self._check_result(indicator, dict(foo1='bar1', foo2='bar2', foo4='bar4'), 1)

        # first and not right
        self._check_result(indicator, dict(foo1='not bar1', foo2='bar2', foo3='bar3'), 0)
        # second and not right
        self._check_result(indicator, dict(foo1='bar1', foo2='not bar2', foo3='bar3'), 0)
        # last and not right
        self._check_result(indicator, dict(foo1='bar1', foo2='bar2', foo3='not bar3', foo4='not bar4'), 0)
Пример #23
0
 def test_literal(self):
     indicator = IndicatorFactory.from_spec({
         "type": "expression",
         "expression": 10,
         "column_id": "foo",
         "datatype": "integer"
     })
     self._check_result(indicator, {}, 10)
     self._check_result(indicator, {'foo': 'bar'}, 10)
     indicator = IndicatorFactory.from_spec({
         "type": "expression",
         "expression": 10,
         "column_id": "foo",
         "datatype": "small_integer"
     })
     self._check_result(indicator, {}, 10)
     self._check_result(indicator, {'foo': 'bar'}, 10)
Пример #24
0
    def indicators(self):

        return CompoundIndicator(
            self.display_name, self.default_indicators + [
                IndicatorFactory.from_spec(indicator,
                                           self._get_factory_context())
                for indicator in self.configured_indicators
            ])
Пример #25
0
 def test_literal(self):
     indicator = IndicatorFactory.from_spec({
         "type": "expression",
         "expression": 10,
         "column_id": "foo",
         "datatype": "integer"
     })
     self._check_result(indicator, {}, 10)
     self._check_result(indicator, {'foo': 'bar'}, 10)
     indicator = IndicatorFactory.from_spec({
         "type": "expression",
         "expression": 10,
         "column_id": "foo",
         "datatype": "small_integer"
     })
     self._check_result(indicator, {}, 10)
     self._check_result(indicator, {'foo': 'bar'}, 10)
Пример #26
0
 def indicators(self):
     doc_id_indicator = IndicatorFactory.from_spec({
         "column_id": "doc_id",
         "type": "raw",
         "display_name": "document id",
         "datatype": "string",
         "property_name": "_id",
         "is_nullable": False,
         "is_primary_key": True,
     }, self.named_filter_objects)
     return CompoundIndicator(
         self.display_name,
         [doc_id_indicator] + [
             IndicatorFactory.from_spec(indicator, self.named_filter_objects)
             for indicator in self.configured_indicators
         ]
     )
Пример #27
0
 def _default_nested_indicator(self, path):
     return IndicatorFactory.from_spec({
         "type": "raw",
         "column_id": "foo",
         "datatype": "string",
         "property_path": path,
         "display_name": "indexed",
     })
Пример #28
0
 def _default_nested_indicator(self, path):
     return IndicatorFactory.from_spec({
         "type": "raw",
         "column_id": "foo",
         "datatype": "string",
         "property_path": path,
         "display_name": "indexed",
     })
Пример #29
0
    def indicators(self):

        return CompoundIndicator(
            self.display_name,
            self.default_indicators + [
                IndicatorFactory.from_spec(indicator, self._get_factory_context())
                for indicator in self.configured_indicators
            ]
        )
Пример #30
0
    def testConstructChoiceList(self):
        indicator = IndicatorFactory.from_spec(self.spec)
        cols = indicator.get_columns()
        self.assertEqual(4, len(cols))
        for i, choice in enumerate(self.spec['choices']):
            self.assertTrue(self.spec['column_id'] in cols[i].id)
            self.assertTrue(choice in cols[i].id)

        self.assertEqual(self.spec['display_name'], indicator.display_name)
Пример #31
0
    def test_ledger_balances_indicator(self, get_values_by_product):
        get_values_by_product.return_value = self.stock_states
        indicator = IndicatorFactory.from_spec(self.spec)

        doc = {'_id': 'case1', 'domain': 'domain'}
        values = indicator.get_values(doc, EvaluationContext(doc, 0))

        self.assertEqual([(val.column.id, val.value) for val in values],
                         [('soh_abc', 32), ('soh_def', 85), ('soh_ghi', 11)])
Пример #32
0
 def testSingleSelectIndicators(self):
     indicator = IndicatorFactory.from_spec(self.spec)
     self._check_vals(indicator, dict(category='bug'), [1, 0, 0, 0])
     self._check_vals(indicator, dict(category='feature'), [0, 1, 0, 0])
     self._check_vals(indicator, dict(category='app'), [0, 0, 1, 0])
     self._check_vals(indicator, dict(category='schedule'), [0, 0, 0, 1])
     self._check_vals(indicator, dict(category='nomatch'), [0, 0, 0, 0])
     self._check_vals(indicator, dict(category=''), [0, 0, 0, 0])
     self._check_vals(indicator, dict(nocategory='bug'), [0, 0, 0, 0])
Пример #33
0
    def testConstructChoiceList(self):
        indicator = IndicatorFactory.from_spec(self.spec)
        cols = indicator.get_columns()
        self.assertEqual(4, len(cols))
        for i, choice in enumerate(self.spec['choices']):
            self.assertTrue(self.spec['column_id'] in cols[i].id)
            self.assertTrue(choice in cols[i].id)

        self.assertEqual(self.spec['display_name'], indicator.display_name)
Пример #34
0
 def testChoiceListWithPath(self):
     spec = copy(self.spec)
     del spec['property_name']
     spec['property_path'] = ['path', 'to', 'category']
     indicator = IndicatorFactory.from_spec(spec)
     self._check_vals(indicator, {'category': 'bug'}, [0, 0, 0, 0])
     self._check_vals(indicator, {'path': {'category': 'bug'}}, [0, 0, 0, 0])
     self._check_vals(indicator, {'path': {'to': {'category': 'bug'}}}, [1, 0, 0, 0])
     self._check_vals(indicator, {'path': {'to': {'nothing': 'bug'}}}, [0, 0, 0, 0])
Пример #35
0
 def testSingleSelectIndicators(self):
     indicator = IndicatorFactory.from_spec(self.spec)
     self._check_vals(indicator, dict(category='bug'), [1, 0, 0, 0])
     self._check_vals(indicator, dict(category='feature'), [0, 1, 0, 0])
     self._check_vals(indicator, dict(category='app'), [0, 0, 1, 0])
     self._check_vals(indicator, dict(category='schedule'), [0, 0, 0, 1])
     self._check_vals(indicator, dict(category='nomatch'), [0, 0, 0, 0])
     self._check_vals(indicator, dict(category=''), [0, 0, 0, 0])
     self._check_vals(indicator, dict(nocategory='bug'), [0, 0, 0, 0])
Пример #36
0
 def testChoiceListWithPath(self):
     spec = copy(self.spec)
     del spec['property_name']
     spec['property_path'] = ['path', 'to', 'category']
     indicator = IndicatorFactory.from_spec(spec)
     self._check_vals(indicator, {'category': 'bug'}, [0, 0, 0, 0])
     self._check_vals(indicator, {'path': {'category': 'bug'}}, [0, 0, 0, 0])
     self._check_vals(indicator, {'path': {'to': {'category': 'bug'}}}, [1, 0, 0, 0])
     self._check_vals(indicator, {'path': {'to': {'nothing': 'bug'}}}, [0, 0, 0, 0])
Пример #37
0
 def testDecimal(self):
     indicator = IndicatorFactory.from_spec({
         'type': 'raw',
         'column_id': 'col',
         "property_name": "foo",
         "datatype": "decimal",
     })
     self._check_result(indicator, dict(foo=5.5), Decimal(5.5))
     self._check_result(indicator, dict(foo=None), None)
     self._check_result(indicator, dict(foo="banana"), None)
Пример #38
0
 def testMetadataDefaults(self):
     indicator = IndicatorFactory.from_spec({
         "type": "raw",
         "column_id": "foo",
         "datatype": "integer",
         'property_name': 'foo',
         "display_name": "raw foos",
     })
     self.assertEqual(True, indicator.column.is_nullable)
     self.assertEqual(False, indicator.column.is_primary_key)
Пример #39
0
 def testMetadataDefaults(self):
     indicator = IndicatorFactory.from_spec({
         "type": "raw",
         "column_id": "foo",
         "datatype": "integer",
         'property_name': 'foo',
         "display_name": "raw foos",
     })
     self.assertEqual(True, indicator.column.is_nullable)
     self.assertEqual(False, indicator.column.is_primary_key)
Пример #40
0
 def testDecimal(self):
     indicator = IndicatorFactory.from_spec({
         'type': 'raw',
         'column_id': 'col',
         "property_name": "foo",
         "datatype": "decimal",
     })
     self._check_result(indicator, dict(foo=5.5), Decimal(5.5))
     self._check_result(indicator, dict(foo=None), None)
     self._check_result(indicator, dict(foo="banana"), None)
Пример #41
0
    def test_ledger_balances_indicator(self):
        indicator = IndicatorFactory.from_spec(self.spec)
        doc = {'_id': 'case1', 'domain': 'domain'}

        with patch('corehq.apps.userreports.indicators.get_values_by_product',
                   return_value=self.stock_states):
            values = indicator.get_values(doc, EvaluationContext(doc, 0))

        self.assertEqual([(val.column.id, val.value) for val in values],
                         [('soh_abc', 32), ('soh_def', 85), ('soh_ghi', 11)])
Пример #42
0
    def test_ledger_balances_indicator(self, get_values_by_product):
        get_values_by_product.return_value = self.stock_states
        indicator = IndicatorFactory.from_spec(self.spec)

        doc = {'_id': 'case1'}
        values = indicator.get_values(doc, EvaluationContext(doc, 0))

        self.assertEqual(
            [(val.column.id, val.value) for val in values],
            [('soh_abc', 32), ('soh_def', 85), ('soh_ghi', 11)]
        )
Пример #43
0
 def simple_indicator(self):
     return IndicatorFactory.from_spec({
         "type": "expression",
         "expression": {
             "type": "property_name",
             "property_name": "foo",
         },
         "column_id": "foo",
         "datatype": "string",
         "display_name": "expression foos",
     })
Пример #44
0
 def setUp(self):
     self.indicator = IndicatorFactory.from_spec({
         'type': 'boolean',
         'column_id': 'col',
         'filter': {
             'type': 'property_match',
             'property_name': 'foo',
             'property_value': 'bar',
         }
     })
     self.assertEqual(1, len(self.indicator.get_columns()))
Пример #45
0
 def simple_indicator(self):
     return IndicatorFactory.from_spec({
         "type": "expression",
         "expression": {
             "type": "property_name",
             "property_name": "foo",
         },
         "column_id": "foo",
         "datatype": "string",
         "display_name": "expression foos",
     })
Пример #46
0
    def test_ledger_balances_indicator(self):
        indicator = IndicatorFactory.from_spec(self.spec)
        doc = {'_id': 'case1', 'domain': 'domain'}

        with patch('corehq.apps.userreports.indicators.get_values_by_product', return_value=self.stock_states):
            values = indicator.get_values(doc, EvaluationContext(doc, 0))

        self.assertEqual(
            [(val.column.id, val.value) for val in values],
            [('soh_abc', 32), ('soh_def', 85), ('soh_ghi', 11)]
        )
Пример #47
0
    def setUp(self):
        self.indicator = IndicatorFactory.from_spec({
            'type': 'boolean',
            'column_id': 'col',
            'filter': {
                'type': 'property_match',
                'property_name': 'foo',
                'property_value': 'bar',
            }

        })
        self.assertEqual(1, len(self.indicator.get_columns()))
Пример #48
0
    def test_ledger_balances_indicator(self):
        indicator = IndicatorFactory.from_spec(self.spec)
        doc = {'_id': 'case1', 'domain': 'domain'}

        with patch('corehq.apps.userreports.indicators.get_values_by_product',
                   return_value=self.stock_states):
            values = indicator.get_values(doc, EvaluationContext(doc, 0))

        self.assertEqual([(val.column.id, val.value) for val in values],
                         [('immun_dates_tt_1', date(2016, 7, 18)),
                          ('immun_dates_tt_2', date(2016, 8, 7)),
                          ('immun_dates_hpv', date(2019, 4, 14)),
                          ('immun_dates_non_exist', date(1970, 1, 1))])
Пример #49
0
 def test_raw_strings(self):
     indicator = IndicatorFactory.from_spec({
         "type": "raw",
         "column_id": "foo",
         "datatype": "string",
         'property_name': 'foo',
         "display_name": "raw foos",
     })
     self._check_result(indicator, dict(foo="bar"), 'bar')
     self._check_result(indicator, dict(foo=1), 1)
     self._check_result(indicator, dict(foo=1.2), 1.2)
     self._check_result(indicator, dict(foo=None), None)
     self._check_result(indicator, dict(nofoo='foryou'), None)
Пример #50
0
 def test_raw_strings(self):
     indicator = IndicatorFactory.from_spec({
         "type": "raw",
         "column_id": "foo",
         "datatype": "string",
         'property_name': 'foo',
         "display_name": "raw foos",
     })
     self._check_result(indicator, dict(foo="bar"), 'bar')
     self._check_result(indicator, dict(foo=1), '1')
     self._check_result(indicator, dict(foo=1.2), '1.2')
     self._check_result(indicator, dict(foo=None), None)
     self._check_result(indicator, dict(nofoo='foryou'), None)
Пример #51
0
 def testMultiSelectIndicators(self):
     spec = copy(self.spec)
     spec['select_style'] = 'multiple'
     indicator = IndicatorFactory.from_spec(spec)
     self._check_vals(indicator, dict(category='bug'), [1, 0, 0, 0])
     self._check_vals(indicator, dict(category='feature'), [0, 1, 0, 0])
     self._check_vals(indicator, dict(category='app'), [0, 0, 1, 0])
     self._check_vals(indicator, dict(category='schedule'), [0, 0, 0, 1])
     self._check_vals(indicator, dict(category='nomatch'), [0, 0, 0, 0])
     self._check_vals(indicator, dict(category=''), [0, 0, 0, 0])
     self._check_vals(indicator, dict(nocategory='bug'), [0, 0, 0, 0])
     self._check_vals(indicator, dict(category='bug feature'), [1, 1, 0, 0])
     self._check_vals(indicator, dict(category='bug feature app schedule'), [1, 1, 1, 1])
     self._check_vals(indicator, dict(category='bug nomatch'), [1, 0, 0, 0])
Пример #52
0
 def testMultiSelectIndicators(self):
     spec = copy(self.spec)
     spec['select_style'] = 'multiple'
     indicator = IndicatorFactory.from_spec(spec)
     self._check_vals(indicator, dict(category='bug'), [1, 0, 0, 0])
     self._check_vals(indicator, dict(category='feature'), [0, 1, 0, 0])
     self._check_vals(indicator, dict(category='app'), [0, 0, 1, 0])
     self._check_vals(indicator, dict(category='schedule'), [0, 0, 0, 1])
     self._check_vals(indicator, dict(category='nomatch'), [0, 0, 0, 0])
     self._check_vals(indicator, dict(category=''), [0, 0, 0, 0])
     self._check_vals(indicator, dict(nocategory='bug'), [0, 0, 0, 0])
     self._check_vals(indicator, dict(category='bug feature'), [1, 1, 0, 0])
     self._check_vals(indicator, dict(category='bug feature app schedule'), [1, 1, 1, 1])
     self._check_vals(indicator, dict(category='bug nomatch'), [1, 0, 0, 0])
Пример #53
0
 def testRaw(self):
     indicator = IndicatorFactory.from_spec({
         "type": "raw",
         "column_id": "foo",
         "datatype": "integer",
         'property_name': 'foo',
         "display_name": "raw foos",
     })
     # todo: eventually data types should be smarter than this.
     # when this test starts failing that will be a good thing and when we should fix it.
     self._check_result(indicator, dict(foo="bar"), "bar")
     self._check_result(indicator, dict(foo=1), 1)
     self._check_result(indicator, dict(foo=1.2), 1.2)
     self._check_result(indicator, dict(foo=None), None)
     self._check_result(indicator, dict(nofoo='foryou'), None)
Пример #54
0
 def test_datasource_transform(self):
     indicator = IndicatorFactory.from_spec({
         "type": "expression",
         "column_id": "transformed_value",
         "display_name": "transformed value",
         "expression": {
             "type": "property_name",
             "property_name": "month",
         },
         "datatype": "string",
         "transform": {
             "type": "custom",
             "custom_type": "month_display"
         },
     })
     self._check_result(indicator, {'month': "3"}, "March")
Пример #55
0
    def test_ledger_balances_indicator(self):
        indicator = IndicatorFactory.from_spec(self.spec)
        doc = {'_id': 'case1', 'domain': 'domain'}

        with patch('corehq.apps.userreports.indicators.get_values_by_product', return_value=self.stock_states):
            values = indicator.get_values(doc, EvaluationContext(doc, 0))

        self.assertEqual(
            [(val.column.id, val.value) for val in values],
            [
                ('immun_dates_tt_1', date(2016, 7, 18)),
                ('immun_dates_tt_2', date(2016, 8, 7)),
                ('immun_dates_hpv', date(2019, 4, 14)),
                ('immun_dates_non_exist', date(1970, 1, 1))
            ]
        )
Пример #56
0
 def test_datasource_transform(self):
     indicator = IndicatorFactory.from_spec({
         "type": "expression",
         "column_id": "transformed_value",
         "display_name": "transformed value",
         "expression": {
             "type": "property_name",
             "property_name": "month",
         },
         "datatype": "string",
         "transform": {
             "type": "custom",
             "custom_type": "month_display"
         },
     })
     self._check_result(indicator, {'month': "3"}, "March")
Пример #57
0
 def testNoFilter(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': self.indicator_type,
             'column_id': 'col',
         })
Пример #58
0
 def testNoFilter(self):
     with self.assertRaises(BadSpecError):
         IndicatorFactory.from_spec({
             'type': self.indicator_type,
             'column_id': 'col',
         })