def test_get_conversion_type_linked_identity(self): column_specification = ColumnSpecification(self.schema_template, "someschema.uuid", "someotherschema") self.assertEqual(ConversionType.LINKED_EXTERNAL_REFERENCE, column_specification.get_conversion_type())
def test_get_conversion_type_linked_external_reference_identity(self): column_specification = ColumnSpecification( self.schema_template, "someschema.external_reference_property", "someotherschema") self.assertEqual(ConversionType.LINKING_DETAIL, column_specification.get_conversion_type())
def test_get_conversion_type_linking_detail(self): # given: column_spec = ColumnSpecification('item.description', 'record', 'invoice_detail', DataType.STRING) # expect: self.assertEqual(ConversionType.LINKING_DETAIL, column_spec.get_conversion_type())
def test_get_conversion_type_member_field(self): # given: column_spec = ColumnSpecification('user.name', 'user', 'user_data', DataType.STRING) # expect: self.assertEqual(ConversionType.MEMBER_FIELD, column_spec.get_conversion_type())
def test_look_up_linked_object_field(self): column_specification = ColumnSpecification(self.schema_template, "someschema.value", "some_linked_field") self.assertEqual('somedomain', column_specification.domain_type) self.assertEqual('some_linked_field', column_specification.context_concrete_type) self.assertEqual(ConversionType.LINKING_DETAIL, column_specification.get_conversion_type())
def test_get_conversion_type_linked_identity(self): # given: column_spec = ColumnSpecification('account.number', 'user', 'profile_type', DataType.STRING, identity=True) # expect: self.assertEqual(ConversionType.LINKED_IDENTITY, column_spec.get_conversion_type())
def test_get_conversion_type_identity(self): # given: column_spec = ColumnSpecification('product.product_id', 'product', 'store_entry', DataType.STRING, identity=True) # expect: self.assertEqual(ConversionType.IDENTITY, column_spec.get_conversion_type())
def test_get_conversion_type_field_of_list_element(self): # given: column_spec = ColumnSpecification('product.product_name', 'product', 'store_entity', DataType.STRING, multivalue_parent=True) # expect: self.assertEqual(ConversionType.FIELD_OF_LIST_ELEMENT, column_spec.get_conversion_type())
def test_get_conversion_type_external_reference_identity(self): # given: column_spec = ColumnSpecification('account.uuid', 'user', 'profile_type', DataType.STRING, identity=True, external_reference=True) # expect: self.assertEqual(ConversionType.EXTERNAL_REFERENCE, column_spec.get_conversion_type())
def test__column_specification_creation_identifiable__succeeds(self): column_specification = ColumnSpecification(self.schema_template, "someschema.protocol_id", "someschema") self.assertTrue(column_specification.is_identity()) self.assertEqual('someschema', column_specification.context_concrete_type) self.assertEqual('somedomain', column_specification.domain_type) self.assertEqual('someschema.protocol_id', column_specification.field_name) self.assertEqual(DataType.INTEGER, column_specification.data_type) self.assertEqual(ConversionType.IDENTITY, column_specification.get_conversion_type())
def determine_strategy(column_spec: ColumnSpecification): strategy = DO_NOTHING if column_spec is not None: field_name = column_spec.field_name converter = column_spec.determine_converter() conversion_type = column_spec.get_conversion_type() if ConversionType.MEMBER_FIELD == conversion_type: strategy = DirectCellConversion(field_name, converter) elif ConversionType.FIELD_OF_LIST_ELEMENT == conversion_type: strategy = ListElementCellConversion(field_name, converter) elif ConversionType.LINKING_DETAIL == conversion_type: strategy = LinkingDetailCellConversion(field_name, converter) elif ConversionType.IDENTITY == conversion_type: strategy = IdentityCellConversion(field_name, converter) elif ConversionType.LINKED_IDENTITY == conversion_type: strategy = LinkedIdentityCellConversion(field_name, column_spec.main_category) elif ConversionType.EXTERNAL_REFERENCE == conversion_type: strategy = ExternalReferenceCellConversion(field_name, column_spec.main_category) return strategy
def test_look_up_nested_object_field(self): nested_sample_metadata_schema_json = { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://schema.humancellatlas.org/module/somedomain/2.0.2/someschema", "description": "Just a plain old test schema", "required": [], "type": "object", "properties": { "some_parent_property": { "description": "A parent property", "type": "array", "multivalue": True, "items": { "type": "integer" }, "properties": { "some_child_property": { "description": "A child property", "type": "string", } } } } } schema_template = SchemaTemplate( json_schema_docs=[nested_sample_metadata_schema_json]) column_specification = ColumnSpecification( schema_template, "someschema.some_parent_property.some_child_property", "someschema") self.assertFalse(column_specification.multivalue) self.assertTrue(column_specification.is_field_of_list_element()) self.assertEqual(ConversionType.FIELD_OF_LIST_ELEMENT, column_specification.get_conversion_type())
def test_determine_converter_for_single_value(self): data_types_to_test = [ DataType.BOOLEAN, DataType.INTEGER, DataType.STRING, DataType.UNDEFINED ] expected_respective_converter = [ BooleanConverter, IntegerConverter, StringConverter, DefaultConverter ] for data_type, expected_converter in zip( data_types_to_test, expected_respective_converter): sample_metadata_schema_json = { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://schema.humancellatlas.org/module/protocol/2.0.2/someschema", "description": "Just a plain old test schema", "type": "object", "properties": { "some_property": { "description": "Some generic property", "type": data_type.value, "multivalue": False, } } } schema_template = SchemaTemplate( json_schema_docs=[sample_metadata_schema_json]) column_specification = ColumnSpecification( schema_template, "someschema.some_property", "someschema") self.assertIsInstance(column_specification.determine_converter(), expected_converter) self.assertEqual(column_specification.get_conversion_type(), ConversionType.MEMBER_FIELD)