本文整理汇总了Python中corehq.apps.userreports.reports.factory.ReportColumnFactory类的典型用法代码示例。如果您正苦于以下问题:Python ReportColumnFactory类的具体用法?Python ReportColumnFactory怎么用?Python ReportColumnFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReportColumnFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wrong_field_type
def test_wrong_field_type(self):
# can't put a percent in another percent
field_spec = {"aggregation": "simple", "field": "is_pregnant", "type": "percent"}
with self.assertRaises(BadValueError):
ReportColumnFactory.from_spec(
{"type": "percent", "column_id": "pct", "numerator": field_spec, "denominator": field_spec}
)
示例2: testBadAggregation
def testBadAggregation(self):
with self.assertRaises(BadSpecError):
ReportColumnFactory.from_spec({
"aggregation": "simple_",
"field": "doc_id",
"type": "field",
})
示例3: testBadFormat
def testBadFormat(self):
with self.assertRaises(BadValueError):
ReportColumnFactory.from_spec({
"aggregation": "simple",
"field": "doc_id",
"format": "default_",
"type": "field",
})
示例4: test_wrong_field_type
def test_wrong_field_type(self):
# can't put a percent in another percent
field_spec = {
"aggregation": "simple",
"field": "is_pregnant",
"type": "percent",
}
with self.assertRaises(BadSpecError):
ReportColumnFactory.from_spec({
'type': 'percent',
'column_id': 'pct',
'numerator': field_spec,
'denominator': field_spec,
})
示例5: validate
def validate(self, required=True):
def _check_for_duplicates(supposedly_unique_list, error_msg):
# http://stackoverflow.com/questions/9835762/find-and-list-duplicates-in-python-list
duplicate_items = set(
[item for item in supposedly_unique_list if supposedly_unique_list.count(item) > 1]
)
if len(duplicate_items) > 0:
raise BadSpecError(
_(error_msg).format(', '.join(sorted(duplicate_items)))
)
super(ReportConfiguration, self).validate(required)
# check duplicates before passing to factory since it chokes on them
_check_for_duplicates(
[FilterSpec.wrap(f).slug for f in self.filters],
'Filters cannot contain duplicate slugs: {}',
)
_check_for_duplicates(
[ReportColumnFactory.from_spec(c).column_id for c in self.columns],
'Columns cannot contain duplicate column_ids: {}',
)
# these calls all implicitly do validation
ReportFactory.from_spec(self)
self.ui_filters
self.charts
示例6: testColumnDefaultsToField
def testColumnDefaultsToField(self):
field = ReportColumnFactory.from_spec({
"aggregation": "simple",
"field": "doc_id",
"type": "field",
})
self.assertEqual('doc_id', field.column_id)
示例7: test_format_pct_non_numeric
def test_format_pct_non_numeric(self):
spec = self._test_spec()
spec['format'] = 'percent'
wrapped = ReportColumnFactory.from_spec(spec)
for unexpected_value in ['hello', object()]:
self.assertEqual('?', wrapped.get_format_fn()({'num': 1, 'denom': unexpected_value}),
'non-numeric value failed for denominator {}'. format(unexpected_value))
self.assertEqual('?', wrapped.get_format_fn()({'num': unexpected_value, 'denom': 1}))
示例8: testColumnSetFromAlias
def testColumnSetFromAlias(self):
field = ReportColumnFactory.from_spec({
"aggregation": "simple",
"field": "doc_id",
"alias": "the_right_answer",
"type": "field",
})
self.assertTrue(isinstance(field, FieldColumn))
self.assertEqual('the_right_answer', field.column_id)
示例9: test_expansion
def test_expansion(self):
column = ReportColumnFactory.from_spec(
dict(type="expanded", field="lab_result", display="Lab Result", format="default", description="foo")
)
cols = _expand_column(column, ["positive", "negative"], "en")
self.assertEqual(len(cols), 2)
self.assertEqual(type(cols[0].view), SumWhen)
self.assertEqual(cols[1].view.whens, {"negative": 1})
示例10: testGoodFormat
def testGoodFormat(self):
for format in ["default", "percent_of_total"]:
self.assertEquals(
FieldColumn,
type(
ReportColumnFactory.from_spec(
{"aggregation": "simple", "field": "doc_id", "format": format, "type": "field"}
)
),
)
示例11: test_format_pct_non_numeric
def test_format_pct_non_numeric(self):
spec = self._test_spec()
spec["format"] = "percent"
wrapped = ReportColumnFactory.from_spec(spec)
for unexpected_value in ["hello", object()]:
self.assertEqual(
"?",
wrapped.get_format_fn()({"num": 1, "denom": unexpected_value}),
"non-numeric value failed for denominator {}".format(unexpected_value),
)
self.assertEqual("?", wrapped.get_format_fn()({"num": unexpected_value, "denom": 1}))
示例12: testGoodFormat
def testGoodFormat(self):
for format in [
'default',
'percent_of_total',
]:
self.assertEquals(FieldColumn, type(
ReportColumnFactory.from_spec({
"aggregation": "simple",
"field": "doc_id",
"format": format,
"type": "field",
}, is_static=False)
))
示例13: test_missing_fields
def test_missing_fields(self):
field_spec = {"aggregation": "simple", "field": "is_pregnant", "type": "field"}
with self.assertRaises(BadValueError):
ReportColumnFactory.from_spec({"type": "percent", "column_id": "pct"})
with self.assertRaises(BadValueError):
ReportColumnFactory.from_spec({"type": "percent", "column_id": "pct", "numerator": field_spec})
with self.assertRaises(BadValueError):
ReportColumnFactory.from_spec({"type": "percent", "column_id": "pct", "denominator": field_spec})
示例14: test_wrap
def test_wrap(self):
wrapped = ReportColumnFactory.from_spec(
{
"type": "percent",
"column_id": "pct",
"numerator": {"aggregation": "sum", "field": "has_danger_signs", "type": "field"},
"denominator": {"aggregation": "sum", "field": "is_pregnant", "type": "field"},
}
)
self.assertTrue(isinstance(wrapped, PercentageColumn))
self.assertEqual("pct", wrapped.column_id)
self.assertEqual("has_danger_signs", wrapped.numerator.field)
self.assertEqual("is_pregnant", wrapped.denominator.field)
self.assertEqual("percent", wrapped.format)
示例15: test_wrap
def test_wrap(self):
wrapped = ReportColumnFactory.from_spec({
'type': 'percent',
'column_id': 'pct',
'numerator': {
"aggregation": "sum",
"field": "has_danger_signs",
"type": "field",
},
'denominator': {
"aggregation": "sum",
"field": "is_pregnant",
"type": "field",
},
})
self.assertTrue(isinstance(wrapped, PercentageColumn))
self.assertEqual('pct', wrapped.column_id)
self.assertEqual('has_danger_signs', wrapped.numerator.field)
self.assertEqual('is_pregnant', wrapped.denominator.field)
self.assertEqual('percent', wrapped.format)