def test_builder_for_cases(self): builder = DataSourceBuilder(self.domain, self.app, DATA_SOURCE_TYPE_CASE, self.case_type) self.assertEqual('CommCareCase', builder.source_doc_type) expected_filter = { "operator": "eq", "expression": { "type": "property_name", "property_name": "type" }, "type": "boolean_expression", "property_value": self.case_type, } self.assertEqual(expected_filter, builder.filter) expected_property_names = [ "closed", "first_name", "last_name", "modified_on", "name", "opened_on", "owner_id", "user_id", "computed/owner_name", "computed/user_name", ] self.assertEqual(expected_property_names, list(builder.data_source_properties.keys())) owner_name_prop = builder.data_source_properties['computed/owner_name'] self.assertEqual('computed/owner_name', owner_name_prop.get_id()) self.assertEqual('Case Owner', owner_name_prop.get_text()) first_name_prop = builder.data_source_properties['first_name'] self.assertEqual('first_name', first_name_prop.get_id()) self.assertEqual('first name', first_name_prop.get_text())
def test_builder_for_forms(self): builder = DataSourceBuilder(self.domain, self.app, DATA_SOURCE_TYPE_FORM, self.form.unique_id) self.assertEqual('XFormInstance', builder.source_doc_type) expected_filter = { "type": "and", "filters": [{ "type": "boolean_expression", "operator": "eq", "expression": { "type": "property_name", "property_name": "xmlns" }, "property_value": self.form.xmlns, }, { "type": "boolean_expression", "operator": "eq", "expression": { "type": "property_name", "property_name": "app_id" }, "property_value": self.app.get_id, }] } self.assertEqual(expected_filter, builder.filter)
def test_owner_as_location(self): builder = DataSourceBuilder(self.domain, self.app, DATA_SOURCE_TYPE_CASE, self.case_type) self.assertTrue(COMPUTED_OWNER_LOCATION_PROPERTY_ID in builder.data_source_properties) self.assertTrue(COMPUTED_OWNER_LOCATION_WITH_DESENDANTS_PROPERTY_ID in builder.data_source_properties) self.assertTrue( COMPUTED_OWNER_LOCATION_ARCHIVED_WITH_DESCENDANTS_PROPERTY_ID in builder.data_source_properties) owner_location_prop = builder.data_source_properties[ COMPUTED_OWNER_LOCATION_PROPERTY_ID] self.assertEqual(COMPUTED_OWNER_LOCATION_PROPERTY_ID, owner_location_prop.get_id()) self.assertEqual('Case Owner (Location)', owner_location_prop.get_text()) owner_location_prop_w_descendants = \ builder.data_source_properties[COMPUTED_OWNER_LOCATION_WITH_DESENDANTS_PROPERTY_ID] self.assertEqual(COMPUTED_OWNER_LOCATION_WITH_DESENDANTS_PROPERTY_ID, owner_location_prop_w_descendants.get_id()) self.assertEqual('Case Owner (Location w/ Descendants)', owner_location_prop_w_descendants.get_text()) owner_location_prop_archived_w_descendants = \ builder.data_source_properties[COMPUTED_OWNER_LOCATION_ARCHIVED_WITH_DESCENDANTS_PROPERTY_ID] self.assertEqual( COMPUTED_OWNER_LOCATION_ARCHIVED_WITH_DESCENDANTS_PROPERTY_ID, owner_location_prop_archived_w_descendants.get_id()) self.assertEqual( 'Case Owner (Location w/ Descendants and Archived Locations)', owner_location_prop_archived_w_descendants.get_text())
def test_owner_as_location(self): builder = DataSourceBuilder(self.domain, self.app, DATA_SOURCE_TYPE_CASE, self.case_type) self.assertTrue(COMPUTED_OWNER_LOCATION_PROPERTY_ID in builder.data_source_properties) owner_location_prop = builder.data_source_properties[ COMPUTED_OWNER_LOCATION_PROPERTY_ID] self.assertEqual(COMPUTED_OWNER_LOCATION_PROPERTY_ID, owner_location_prop.get_id()) self.assertEqual('Case Owner (Location)', owner_location_prop.get_text())
def test_builder_for_cases(self): builder = DataSourceBuilder(self.domain, self.app, DATA_SOURCE_TYPE_CASE, self.case_type) self.assertEqual('CommCareCase', builder.source_doc_type) expected_filter = { "operator": "eq", "expression": { "type": "property_name", "property_name": "type" }, "type": "boolean_expression", "property_value": self.case_type, } self.assertEqual(expected_filter, builder.filter)
def test_builder_for_forms(self): builder = DataSourceBuilder(self.domain, self.app, DATA_SOURCE_TYPE_FORM, self.form.unique_id) self.assertEqual('XFormInstance', builder.source_doc_type) expected_filter = { "type": "and", "filters": [{ "type": "boolean_expression", "operator": "eq", "expression": { "type": "property_name", "property_name": "xmlns" }, "property_value": self.form.xmlns, }, { "type": "boolean_expression", "operator": "eq", "expression": { "type": "property_name", "property_name": "app_id" }, "property_value": self.app.get_id, }] } self.assertEqual(expected_filter, builder.filter) expected_property_names = [ 'username', 'userID', 'timeStart', 'timeEnd', 'deviceID', '/data/first_name', '/data/last_name', '/data/children', '/data/dob', '/data/state' ] self.assertEqual(expected_property_names, list(builder.data_source_properties.keys())) user_id_prop = builder.data_source_properties['userID'] self.assertEqual('userID', user_id_prop.get_id()) self.assertEqual('User ID', user_id_prop.get_text()) name_prop = builder.data_source_properties['/data/first_name'] self.assertEqual('/data/first_name', name_prop.get_id()) self.assertEqual('First Name', name_prop.get_text())
def test_builder_bad_type(self): with self.assertRaises(AssertionError): DataSourceBuilder(self.domain, self.app, 'invalid-type', self.form.unique_id)