def test_EntityViewSchema__ignore_annotation_column_names(): syn = synapseclient.client.Synapse(debug=True, skip_checks=True) scopeIds = ['123'] entity_view = EntityViewSchema("someName", scopes=scopeIds, parent="syn123", ignoredAnnotationColumnNames={'long1'}, addDefaultViewColumns=False, addAnnotationColumns=True) mocked_annotation_result1 = [ Column(name='long1', columnType='INTEGER'), Column(name='long2', columnType='INTEGER') ] with patch.object(syn, '_get_annotation_entity_view_columns', return_value=mocked_annotation_result1) as mocked_get_annotations,\ patch.object(syn, 'getColumns') as mocked_get_columns,\ patch.object(SchemaBase, "_before_synapse_store"): entity_view._before_synapse_store(syn) mocked_get_columns.assert_called_once_with([]) mocked_get_annotations.assert_called_once_with(scopeIds, 'file') assert_equals([Column(name='long2', columnType='INTEGER')], entity_view.columns_to_store)
def test_update_existing_view_type_mask(): properties = { 'id': 'syn123', 'parentId': 'syn456', 'viewTypeMask': 2 } view = EntityViewSchema(properties=properties) assert_equals(view['viewTypeMask'], 2) view.set_entity_types([EntityViewType.FILE]) assert_equals(view['viewTypeMask'], 1)
def test_update_existing_view_type_mask(): properties = { 'id': 'syn123', 'parentId': 'syn456', 'viewTypeMask': 2 } view = EntityViewSchema(properties=properties) assert view['viewTypeMask'] == 2 view.set_entity_types([EntityViewType.FILE]) assert view['viewTypeMask'] == 1
def test_EntityViewSchema__repeated_columnName_same_type(): syn = synapseclient.client.Synapse(debug=True, skip_checks=True) entity_view = EntityViewSchema("someName", parent="syn123") columns = [Column(name='annoName', columnType='INTEGER'), Column(name='annoName', columnType='INTEGER')] with patch.object(syn, 'getColumns') as mocked_get_columns: filtered_results = entity_view._filter_duplicate_columns(syn, columns) mocked_get_columns.assert_called_once_with([]) assert_equals(1, len(filtered_results)) assert_equals(Column(name='annoName', columnType='INTEGER'), filtered_results[0])
def test_EntityViewSchema__repeated_columnName_same_type(syn): syn = Synapse(debug=True, skip_checks=True) entity_view = EntityViewSchema("someName", parent="syn123") columns = [Column(name='annoName', columnType='INTEGER'), Column(name='annoName', columnType='INTEGER')] with patch.object(syn, 'getColumns') as mocked_get_columns: filtered_results = entity_view._filter_duplicate_columns(syn, columns) mocked_get_columns.assert_called_once_with([]) assert 1 == len(filtered_results) assert Column(name='annoName', columnType='INTEGER') == filtered_results[0]
def test_entityViewSchema__add_scope(): entity_view = EntityViewSchema(parent="idk") entity_view.add_scope(Entity(parent="also idk", id=123)) entity_view.add_scope(456) entity_view.add_scope("789") assert_equals([str(x) for x in ["123", "456", "789"]], entity_view.scopeIds)
def test_EntityViewSchema__before_synapse_store(syn): syn = Synapse(debug=True, skip_checks=True) with patch.object(syn, '_get_default_view_columns') as mocked_get_default,\ patch.object(syn, '_get_annotation_view_columns') as mocked_get_annotations,\ patch.object(SchemaBase, "_before_synapse_store"): submission_view = EntityViewSchema(scopes=['syn123'], parent="idk") submission_view._before_synapse_store(syn) mocked_get_default.assert_called_once_with("entityview", view_type_mask=1) mocked_get_annotations.assert_called_once_with(['syn123'], "entityview", view_type_mask=1)
def test_set_view_types_invalid_input(): properties = { 'id': 'syn123', 'parentId': 'syn456' } view = EntityViewSchema(type='project', properties=properties) assert view['viewTypeMask'] == 2 pytest.raises(ValueError, view.set_entity_types, None)
def test_input_is_SchemaBase(self): get_table_colums_results = [Column(name='A'), Column(name='B')] with patch.object(syn, "getTableColumns", return_value=iter(get_table_colums_results))\ as mock_get_table_coulmns: schema = EntityViewSchema(parentId="syn123") results = list(syn.getColumns(schema)) assert_equal(get_table_colums_results, results) mock_get_table_coulmns.assert_called_with(schema)
def test_entityViewSchema__add_default_columns_when_from_Synapse(): properties = { u'concreteType': u'org.sagebionetworks.repo.model.table.EntityView' } entity_view = EntityViewSchema(parent="idk", addDefaultViewColumns=True, properties=properties) assert_false(entity_view.addDefaultViewColumns)
def test_EntityViewSchema__ignore_column_names_set_info_preserved(): """ tests that ignoredAnnotationColumnNames will be preserved after creating a new EntityViewSchema from properties, local_state, and annotations """ ignored_names = {'a', 'b', 'c'} entity_view = EntityViewSchema("someName", parent="syn123", ignoredAnnotationColumnNames={'a', 'b', 'c'}) properties, annotations, local_state = split_entity_namespaces(entity_view) entity_view_copy = Entity.create(properties, annotations, local_state) assert ignored_names == entity_view.ignoredAnnotationColumnNames assert ignored_names == entity_view_copy.ignoredAnnotationColumnNames
def test_EntityViewSchema__repeated_columnName_different_type(): syn = synapseclient.client.Synapse(debug=True, skip_checks=True) scopeIds = ['123'] entity_view = EntityViewSchema("someName", scopes=scopeIds, parent="syn123") columns = [ Column(name='annoName', columnType='INTEGER'), Column(name='annoName', columnType='DOUBLE') ] with patch.object(syn, 'getColumns') as mocked_get_columns: filtered_results = entity_view._filter_duplicate_columns(syn, columns) mocked_get_columns.assert_called_once_with([]) assert_equals(2, len(filtered_results)) assert_equals(columns, filtered_results)
def test_EntityViewSchema__ignore_annotation_column_names(): syn = synapseclient.client.Synapse(debug=True, skip_checks=True) scopeIds = ['123'] entity_view = EntityViewSchema("someName", scopes=scopeIds, parent="syn123", ignoredAnnotationColumnNames={'long1'}, addDefaultViewColumns=False, addAnnotationColumns=True) mocked_annotation_result1 = [Column(name='long1', columnType='INTEGER'), Column(name='long2', columnType='INTEGER')] with patch.object(syn, '_get_annotation_entity_view_columns', return_value=mocked_annotation_result1)\ as mocked_get_annotations,\ patch.object(syn, 'getColumns') as mocked_get_columns,\ patch.object(SchemaBase, "_before_synapse_store"): entity_view._before_synapse_store(syn) mocked_get_columns.assert_called_once_with([]) mocked_get_annotations.assert_called_once_with(scopeIds, EntityViewType.FILE.value) assert_equals([Column(name='long2', columnType='INTEGER')], entity_view.columns_to_store)
def test_EntityViewSchema__repeated_columnName(): syn = synapseclient.client.Synapse(debug=True, skip_checks=True) scopeIds = ['123'] entity_view = EntityViewSchema("someName", scopes=scopeIds, parent="syn123") mocked_annotation_result1 = [ Column(name='annoName', columnType='INTEGER'), Column(name='annoName', columnType='DOUBLE') ] with patch.object(syn, '_get_annotation_entity_view_columns', return_value=mocked_annotation_result1) as mocked_get_annotations,\ patch.object(syn, 'getColumns') as mocked_get_columns: assert_raises(ValueError, entity_view._add_annotations_as_columns, syn) mocked_get_columns.assert_called_once_with([]) mocked_get_annotations.assert_called_once_with(scopeIds, 'file')
def test_entityViewSchema__specified_deprecated_type(): view_type = 'project' entity_view = EntityViewSchema(parent="idk", type=view_type) assert EntityViewType.PROJECT.value == entity_view.viewTypeMask assert entity_view.get('type') is None
def test_entityViewSchema__specified_deprecated_type_in_properties(): view_type = 'project' properties = {'type': view_type} entity_view = EntityViewSchema(parent="idk", properties=properties) assert EntityViewType.PROJECT.value == entity_view.viewTypeMask assert entity_view.get('type') is None
def test_entityViewSchema__sepcified_add_default_columns(): entity_view = EntityViewSchema(parent="idk", addDefaultViewColumns=False) assert_false(entity_view.addDefaultViewColumns)
def test_entityViewSchema__sepcified_scopeId(): scopeId = ["123"] entity_view = EntityViewSchema(parent="idk", scopeId=scopeId) assert_equals(scopeId, entity_view.scopeId)
def test_entityViewSchema__specified_type(): view_type = 'project' entity_view = EntityViewSchema(parent="idk", type=view_type) assert_equals(view_type, entity_view.type)
def test_EntityViewSchema__default_params(): entity_view = EntityViewSchema(parent="idk") assert_equals('file', entity_view.type) assert_equals([], entity_view.scopeIds) assert_equals(True, entity_view.addDefaultViewColumns)
def test_entityViewSchema__specified_both_type_and_viewTypeMask(): entity_view = EntityViewSchema(parent="idk", type='folder', includeEntityTypes=[EntityViewType.PROJECT]) assert_equals(EntityViewType.PROJECT.value, entity_view.viewTypeMask) assert_is_none(entity_view.get('type'))
def test_entityViewSchema__specified_deprecated_type_in_properties(): view_type = 'project' properties = {'type': view_type} entity_view = EntityViewSchema(parent="idk", properties=properties) assert_equals(EntityViewType.PROJECT.value, entity_view.viewTypeMask) assert_is_none(entity_view.get('type'))
def test_EntityViewSchema__default_params(): entity_view = EntityViewSchema(parent="idk") assert_equals(EntityViewType.FILE.value, entity_view.viewTypeMask) assert_equals([], entity_view.scopeIds) assert_equals(True, entity_view.addDefaultViewColumns)
def test_entityViewSchema__specified_deprecated_type(): view_type = 'project' entity_view = EntityViewSchema(parent="idk", type=view_type) assert_equals(EntityViewType.PROJECT.value, entity_view.viewTypeMask) assert_is_none(entity_view.get('type'))
def test_EntityViewSchema__default_params(): entity_view = EntityViewSchema(parent="idk") assert EntityViewType.FILE.value == entity_view.viewTypeMask assert [] == entity_view.scopeIds assert entity_view.addDefaultViewColumns is True
def test_entityViewSchema__specified_both_type_and_viewTypeMask(): entity_view = EntityViewSchema(parent="idk", type='folder', includeEntityTypes=[EntityViewType.PROJECT]) assert EntityViewType.PROJECT.value == entity_view.viewTypeMask assert entity_view.get('type') is None