def test_incomplete_records_data(app, test_communities): """Create incomplete record data and the corresponding patch.""" invalid_patches = [[ # no title { "op": "remove", "path": "/titles"} ], [ # no community_specific { "op": "remove", "path": "/community_specific" } ], [ # no study_design { "op": "remove", "path": "/community_specific/" "$BLOCK_SCHEMA_ID[MyTestSchema]/study_design" } ], [ # minItems not matched (should be >= 1) { "op": "replace", "path": "/community_specific/" "$BLOCK_SCHEMA_ID[MyTestSchema]/study_design", "value": [] } ]] IncompleteRecordData = namedtuple( 'IncompleteRecordData', ['complete_data', 'patch', 'incomplete_data'] ) with app.app_context(): unresolved_data = { 'titles': [{'title':'My Test BBMRI Record'}], 'community': '$COMMUNITY_ID[MyTestCommunity1]', "open_access": True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } } data = json.loads(resolve_block_schema_id(resolve_community_id( json.dumps(unresolved_data)))) resolved_patches = [ json.loads(resolve_block_schema_id(resolve_community_id( json.dumps(data))) ) for data in invalid_patches ] return [IncompleteRecordData(deepcopy(data), patch, apply_patch(data, patch)) for patch in resolved_patches]
def records_data_with_external_pids(app, test_communities): record_data = json.dumps({ "external_pids":[ { "key":"file1.txt", "ePIC_PID": "http://hdl.handle.net/11304/0d8dbdec-74e4-4774-954e-1a98e5c0cfa3" }, { "key":"file1_copy.txt", "ePIC_PID": "http://hdl.handle.net/11304/0d8dbdec-74e4-4774-954e-1a98e5c0cfa3" }, { "key":"file2.txt", "ePIC_PID": "http://hdl.handle.net/11304/50fafc50-4227-4464-bacc-2d85295c18a7" } ], 'titles': [{'title':'BBMRI dataset 6'}], 'community': '$COMMUNITY_ID[MyTestCommunity2]', 'open_access': True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }) with app.app_context(): return json.loads(resolve_block_schema_id(resolve_community_id( record_data)))
def records_data_with_external_pids(app, test_communities): record_data = json.dumps({ "external_pids": [{ "key": "file1.txt", "ePIC_PID": "http://hdl.handle.net/11304/0d8dbdec-74e4-4774-954e-1a98e5c0cfa3" }, { "key": "file1_copy.txt", "ePIC_PID": "http://hdl.handle.net/11304/0d8dbdec-74e4-4774-954e-1a98e5c0cfa3" }, { "key": "file2.txt", "ePIC_PID": "http://hdl.handle.net/11304/50fafc50-4227-4464-bacc-2d85295c18a7" }], 'titles': [{ 'title': 'BBMRI dataset 6' }], 'community': '$COMMUNITY_ID[MyTestCommunity2]', 'open_access': True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }) with app.app_context(): return json.loads( resolve_block_schema_id(resolve_community_id(record_data)))
def make_record_json(): record_data = { 'owner': '', 'titles': [{'title':'My Errorneous BBMRI record'}], 'community': '$COMMUNITY_ID[MyTestCommunity1]', 'open_access': True, 'creators': [{'creator_name':'Anonymous'}], 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } } record_str = json.dumps(record_data) record_str = resolve_community_id(record_str) record_str = resolve_block_schema_id(record_str) return json.loads(record_str)
def resolve_record_data(data): """Resolve community and block schema IDs in the given record data.""" return json.loads( resolve_block_schema_id(resolve_community_id(json.dumps(data))) )
def test_records_data(app, test_communities): """Generate test deposits data. Returns: :list: list of generated record data """ records_data = [{ 'titles': [{'title':'My Test BBMRI Record'}], 'descriptions': [{'description':"The long description of My Test BBMRI Record", 'description_type': "Abstract"}], 'creators': [{'creator_name': 'Glados, R.'}, {'creator_name': 'Cube, Companion'}], 'publisher': 'Aperture Science', 'publication_date': '2000-12-12', 'disciplines': ['5.14.17.10 → Weapon|Military weapons → Nuclear warfare|Nuclear'], 'keywords': ['phaser', 'laser', 'maser', 'portal gun'], 'contributors': [{'contributor_name': "Turret", "contributor_type": "ContactPerson"}], 'language': "eng", 'resource_types': [{'resource_type': "Casualities", 'resource_type_general': "Dataset"}], 'alternate_identifiers': [{'alternate_identifier': "007", 'alternate_identifier_type': "Fleming"}], 'license': {'license':"GNU Public License", 'license_uri': "http://gnu.org"}, 'community': '$COMMUNITY_ID[MyTestCommunity1]', 'open_access': True, 'contact_email': '*****@*****.**', 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }, { 'titles': [{'title':'New BBMRI dataset'}], 'community': '$COMMUNITY_ID[MyTestCommunity1]', 'open_access': True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }, { 'titles': [{'title':'BBMRI dataset 3'}], 'community': '$COMMUNITY_ID[MyTestCommunity1]', 'open_access': True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }, { 'titles': [{'title':'BBMRI dataset 4'}], # community 2 'community': '$COMMUNITY_ID[MyTestCommunity2]', 'open_access': True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }, { 'titles': [{'title':'BBMRI dataset 5'}], # community 2 'community': '$COMMUNITY_ID[MyTestCommunity2]', 'open_access': True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }, { 'titles': [{'title':'BBMRI dataset 6'}], # community 2 'community': '$COMMUNITY_ID[MyTestCommunity2]', 'open_access': True, 'community_specific': { '$BLOCK_SCHEMA_ID[MyTestSchema]': { 'study_design': ['Case-control'] } } }] with app.app_context(): return [ json.loads(resolve_block_schema_id(resolve_community_id( json.dumps(data))) ) for data in records_data ]