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 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 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 _create_schema(self, items): return CaseExportDataSchema( domain=self.domain, case_type=self.case_type, group_schemas=[ExportGroupSchema( path=[], items=items, )])
def setUpClass(cls): super(TestExportDBAccessors, cls).setUpClass() cls.form_schema = FormExportDataSchema( domain=cls.domain, app_id=cls.app_id, xmlns=cls.xmlns, ) cls.form_schema_other = FormExportDataSchema( domain='other', app_id=cls.app_id, xmlns=cls.xmlns, ) cls.form_schema_before = FormExportDataSchema( domain=cls.domain, app_id=cls.app_id, xmlns=cls.xmlns, created_on=datetime.utcnow() - timedelta(1) ) cls.case_schema = CaseExportDataSchema( domain=cls.domain, case_type=cls.case_type, ) cls.case_schema_other = CaseExportDataSchema( domain=cls.domain, case_type='other', ) cls.case_schema_before = CaseExportDataSchema( domain=cls.domain, case_type=cls.case_type, created_on=datetime.utcnow() - timedelta(1) ) cls.schemas = [ cls.form_schema, cls.form_schema_before, cls.form_schema_other, cls.case_schema_before, cls.case_schema, cls.case_schema_other, ] for schema in cls.schemas: schema.save()
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(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}, ), ], )