def test_inferred_schema_merge(self): schema = CaseExportDataSchema( domain='my-domain', group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ExportItem(path=[PathNode(name='case_property')])], ) ]) inferred_schema = CaseExportDataSchema( domain='my-domain', group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[PathNode(name='case_property')], inferred=True, ) ], inferred=True, ) ]) merged = ExportDataSchema._merge_schemas(schema, inferred_schema) self.assertEqual(len(merged.group_schemas), 1) self.assertTrue(merged.group_schemas[0].inferred) group_schema = merged.group_schemas[0] self.assertEqual(len(group_schema.items), 1) self.assertTrue(group_schema.items[0].inferred)
def setUpClass(cls): super(TestConvertSavedExportSchemaToCaseExportInstance, cls).setUpClass() cls.project = create_domain(cls.domain) cls.project.commtrack_enabled = True cls.project.save() cls.schema = CaseExportDataSchema( domain=cls.domain, case_type='wonderwoman', group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[PathNode(name='DOB')], label='Case Propery DOB', last_occurrences={cls.app_id: 3}, ), ], last_occurrences={cls.app_id: 3}, ), ExportGroupSchema( path=CASE_HISTORY_TABLE, last_occurrences={cls.app_id: 3}, ), ExportGroupSchema( path=PARENT_CASE_TABLE, last_occurrences={cls.app_id: 3}, ), ], )
def setUpClass(cls): super(TestSingleNodeRepeatConversion, cls).setUpClass() cls.schema = FormExportDataSchema( domain=cls.domain, group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[], last_occurrences={cls.app_id: 2}, ), ExportGroupSchema( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True) ], items=[ ExportItem( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True), PathNode(name='single_answer') ], label='Single Answer', last_occurrences={cls.app_id: 2}, ) ], last_occurrences={cls.app_id: 2}, ), ])
def setUpClass(cls): super(TestCaseExportInstanceGeneration, cls).setUpClass() cls.app_id = '1234' cls.schema = CaseExportDataSchema(group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ScalarItem( path=[PathNode(name='p1')], label='p1', last_occurrences={}, ), ], last_occurrences={cls.app_id: 3}, ), ], ) cls.new_schema = CaseExportDataSchema(group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ScalarItem( path=[PathNode(name='p1')], label='p1', last_occurrences={}, ), ScalarItem( path=[PathNode(name='name')], label='name', last_occurrences={cls.app_id: 3}, ), ], last_occurrences={cls.app_id: 3}, ), ], )
def setUpClass(cls): super(TestExportInstanceGenerationMultipleApps, cls).setUpClass() cls.app_id = '1234' cls.second_app_id = '5678' cls.schema = FormExportDataSchema(group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[ PathNode(name='data'), PathNode(name='question1') ], label='Question 1', last_occurrences={ cls.app_id: 2, cls.second_app_id: 4 }, ) ], last_occurrences={ cls.app_id: 2, cls.second_app_id: 4, }, ), ExportGroupSchema( path=[ PathNode(name='data'), PathNode(name='repeat', is_repeat=True) ], items=[ ExportItem( path=[ PathNode(name='data'), PathNode(name='repeat', is_repeat=True), PathNode(name='q2') ], label='Question 2', last_occurrences={ cls.app_id: 3, }, ) ], last_occurrences={ cls.app_id: 3, }, ), ], )
def test_get_case_properties_for_case_type(self): schema = CaseExportDataSchema( group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[PathNode(name='name')], label='name', last_occurrences={}, ), ExportItem( path=[PathNode(name='color')], label='color', last_occurrences={}, ), ], last_occurrences={}, ), ], ) with mock.patch( 'corehq.apps.export.models.new.CaseExportDataSchema.generate_schema_from_builds', return_value=schema): case_types = get_case_properties_for_case_type('test-domain', 'case-type') self.assertEqual(sorted(case_types), ['color', 'name'])
def setUpClass(cls): super(TestConversionOrdering, cls).setUpClass() cls.schema = FormExportDataSchema( domain=cls.domain, group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[PathNode(name='form'), PathNode(name='question1')], label='q1', ), ExportItem( path=[PathNode(name='form'), PathNode(name='question2')], label='q2', ), ExportItem( path=[PathNode(name='form'), PathNode(name='other')], label='other', ), ExportItem( path=[PathNode(name='form'), PathNode(name='question3')], label='q3', ), ], last_occurrences={cls.app_id: 2}, ), ] )
def setUpClass(cls): super(TestFormExportInstanceGeneration, cls).setUpClass() cls.app_id = '1234' cls.schema = FormExportDataSchema(group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ MultipleChoiceItem( path=[ PathNode(name='data'), PathNode(name='question1') ], label='Question 1', last_occurrences={cls.app_id: 3}, ), StockItem( path=[ PathNode(name='data'), PathNode(name='balance:question-id'), PathNode(name='@type'), ], label='Stock 1', last_occurrences={cls.app_id: 3}, ) ], last_occurrences={cls.app_id: 3}, ), ExportGroupSchema( path=[ PathNode(name='data'), PathNode(name='repeat', is_repeat=True) ], items=[ ExportItem( path=[ PathNode(name='data'), PathNode(name='repeat', is_repeat=True), PathNode(name='q2') ], label='Question 2', last_occurrences={cls.app_id: 2}, ), ], last_occurrences={cls.app_id: 2}, ), ], )
def _create_schema(self, items): return CaseExportDataSchema( domain=self.domain, case_type=self.case_type, group_schemas=[ExportGroupSchema( path=[], items=items, )])
def setUpClass(cls): super(TestConvertStockFormExport, cls).setUpClass() cls.schema = FormExportDataSchema( domain=cls.domain, group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ StockItem( path=[ PathNode(name='form'), PathNode(name='transfer:questionid'), PathNode(name='entry'), PathNode(name='@id'), ], label='Question 1', last_occurrences={cls.app_id: 3}, ), ], last_occurrences={cls.app_id: 2}, ), ExportGroupSchema( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True) ], items=[ StockItem( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True), PathNode(name='transfer:questionid'), PathNode(name='entry'), PathNode(name='@id'), ], label='Question 1', last_occurrences={cls.app_id: 3}, ), ], last_occurrences={cls.app_id: 2}, ), ])
def setUpClass(cls): super(TestForceConvertFormExport, cls).setUpClass() cls.project = create_domain(cls.domain) cls.project.commtrack_enabled = True cls.project.save() cls.schema = FormExportDataSchema( domain=cls.domain, app_id='123', xmlns='myxmlns', group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[], ), ], )
def test_repeat_subcases_schema_generation(self): module = Module(case_type='child', _parent=Application()) form = Form().with_id(0, module) form.actions.subcases = [ OpenSubCaseAction( repeat_context='/data/repeat', case_properties={ 'weight': ConditionalCaseUpdate( question_path='/data/repeat/group/weight'), }, subcase_index=0, _nest=True).with_id(0, None), OpenSubCaseAction( repeat_context='/data/repeat', case_properties={ 'height': ConditionalCaseUpdate(question_path='/data/repeat/height'), }, subcase_index=1, _nest=True).with_id(1, None), OpenSubCaseAction( repeat_context='/data/repeat/nested_repeat', case_properties={ 'age': ConditionalCaseUpdate( question_path='/data/repeat/nested_repeat/age'), }, subcase_index=2, _nest=False).with_id(2, None), ] schema = FormExportDataSchema._add_export_items_for_cases( ExportGroupSchema(path=MAIN_TABLE), [form], ['/data/repeat', '/data/nested_repeat'], )[0] self.assertEqual(len(schema.group_schemas), len(form.actions.subcases)) for group_schema, action in zip(schema.group_schemas, form.actions.subcases): base_path = 'form.{}'.format(action.repeat_context[6:].replace( '/', '.')) if action._nest: base_path += '.{}'.format(action.form_element_name) self._check_subcase_repeat_group_schema( group_schema, list(action.case_properties), base_path)
def setUpClass(cls): super(TestExportInstanceGenerationWithInferredSchema, cls).setUpClass() cls.schema = CaseExportDataSchema( app_id=cls.app_id, case_type=cls.case_type, group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[ PathNode(name='data'), PathNode(name='case_property') ], label='Question 1', last_occurrences={cls.app_id: 3}, ), ], last_occurrences={cls.app_id: 3}, ), ], ) cls.inferred_schema = InferredSchema( case_type=cls.case_type, group_schemas=[ InferredExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem(path=[ PathNode(name='data'), PathNode(name='case_property') ], label='Inferred 1', inferred=True), ExportItem(path=[ PathNode(name='data'), PathNode(name='case_property_2') ], label='Inferred 1', inferred=True), ], inferred=True), ])
def setUpClass(cls): super(TestConvertMissingAppID, cls).setUpClass() factory = AppFactory(cls.domain) m1, m1f1 = factory.new_basic_module('open_case', 'house') m1f1.xmlns = 'missing-xmlns' cls.app = factory.app cls.app.save() cls.project = create_domain(cls.domain) cls.schema = FormExportDataSchema( domain=cls.domain, app_id='123', xmlns='myxmlns', group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[], ), ], )
def setUpClass(cls): super(TestForceConvertExport, cls).setUpClass() cls.project = create_domain(cls.domain) cls.project.commtrack_enabled = True cls.project.save() cls.schema = CaseExportDataSchema( domain=cls.domain, group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[PathNode(name='DOB')], label='Case Property DOB', last_occurrences={cls.app_id: 3}, ), ], last_occurrences={cls.app_id: 3}, ), ], )
def setUpClass(cls): super(TestConvertSavedExportSchemaToFormExportInstance, cls).setUpClass() cls.schema = FormExportDataSchema( domain=cls.domain, group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[ PathNode(name='form'), PathNode(name='question1') ], label='Question 1 Not updated', last_occurrences={cls.app_id: 3}, ), ExportItem( path=[ PathNode(name='form'), PathNode(name='deid_id') ], label='Question 1', last_occurrences={cls.app_id: 3}, ), ExportItem( path=[ PathNode(name='form'), PathNode(name='deid_date') ], label='Question 1', last_occurrences={cls.app_id: 3}, ), ], last_occurrences={cls.app_id: 3}, ), ExportGroupSchema( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True) ], items=[ ExportItem( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True), PathNode(name='question2') ], label='Question 2', last_occurrences={cls.app_id: 2}, ) ], last_occurrences={cls.app_id: 2}, ), ExportGroupSchema( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True), PathNode(name='repeat_nested', is_repeat=True), ], items=[ ExportItem( path=[ PathNode(name='form'), PathNode(name='repeat', is_repeat=True), PathNode(name='repeat_nested', is_repeat=True), PathNode(name='nested'), ], label='Nested Repeat', last_occurrences={cls.app_id: 2}, ) ], last_occurrences={cls.app_id: 2}, ), ], )
def setUpClass(cls): super(TestExportInstanceFromSavedInstance, cls).setUpClass() cls.app_id = '1234' cls.schema = FormExportDataSchema(group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[ PathNode(name='data'), PathNode(name='question1') ], label='Question 1', last_occurrences={ cls.app_id: 3, }, ), ExportItem( path=[ PathNode(name='data'), PathNode(name='@case_id') ], label='@case_id', tag=PROPERTY_TAG_CASE, last_occurrences={ cls.app_id: 3, }, ) ], last_occurrences={ cls.app_id: 3, }, ), ], ) cls.new_schema = FormExportDataSchema(group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[ PathNode(name='data'), PathNode(name='question1') ], label='Question 1', last_occurrences={ cls.app_id: 3, }, ), ExportItem( path=[ PathNode(name='data'), PathNode(name='@case_id') ], label='@case_id', tag=PROPERTY_TAG_CASE, last_occurrences={ cls.app_id: 3, }, ), ExportItem( path=[ PathNode(name='data'), PathNode(name='question3') ], label='Question 3', last_occurrences={ cls.app_id: 3, }, ) ], last_occurrences={ cls.app_id: 3, }, ), ExportGroupSchema( path=[ PathNode(name='data'), PathNode(name='repeat', is_repeat=True) ], items=[ ExportItem( path=[ PathNode(name='data'), PathNode(name='repeat', is_repeat=True), PathNode(name='q2') ], label='Question 2', last_occurrences={ cls.app_id: 3, }, ) ], last_occurrences={ cls.app_id: 3, }, ), ], )