def test_edit_archival_object():
    client = ArchivesSpaceClient(**AUTH)
    original = client.get_record('/repositories/2/archival_objects/3')
    assert original['title'] == 'Test subseries'
    assert original['dates'][0]['end'] == '2015-01-01'
    assert not original['notes']
    new_record = {
        'id': '/repositories/2/archival_objects/3',
        'title': 'Test edited subseries',
        'start_date': '2014-11-01',
        'end_date': '2015-11-01',
        'date_expression': 'November, 2014 to November, 2015',
        'notes': [{
            'type': 'odd',
            'content': 'This is a test note'
        }],
    }
    client.edit_record(new_record)
    updated = client.get_record('/repositories/2/archival_objects/3')
    assert updated['title'] == new_record['title']
    assert updated['dates'][0]['begin'] == new_record['start_date']
    assert updated['dates'][0]['end'] == new_record['end_date']
    assert updated['dates'][0]['expression'] == new_record['date_expression']
    assert updated['notes'][0]['type'] == new_record['notes'][0]['type']
    assert updated['notes'][0]['subnotes'][0]['content'] == new_record['notes'][0]['content']
Пример #2
0
def test_adding_child_with_note():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/resources/5',
                           title='Test child',
                           level='item',
                           notes=[{'type': 'odd', 'content': 'This is a test note'}])
    assert uri == '/repositories/2/archival_objects/24'
def test_posting_contentless_note():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/resources/1',
                           title='Test child',
                           level='recordgrp',
                           notes=[{'type': 'odd', 'content': ''}])
    assert client.get_record(uri)['notes'] == []
Пример #4
0
def test_adding_a_digital_object_to_a_record_with_a_singlepart_note():
    client = ArchivesSpaceClient(**AUTH)
    do = client.add_digital_object('/repositories/2/archival_objects/21',
                                   identifier='5f464db2-9365-492f-b7c7-7958baeb0388',
                                   title='Test digital object whose parent has a singlepart note')
    note = client.get_record(do['id'])['notes'][0]
    assert len(note['content']) == 1
Пример #5
0
def test_posting_contentless_note():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/resources/1',
                           title='Test child',
                           level='recordgrp',
                           notes=[{'type': 'odd', 'content': ''}])
    assert client.get_record(uri)['notes'] == []
def test_adding_a_digital_object_to_a_record_with_a_singlepart_note():
    client = ArchivesSpaceClient(**AUTH)
    do = client.add_digital_object('/repositories/2/archival_objects/21',
                                   identifier='5f464db2-9365-492f-b7c7-7958baeb0388',
                                   title='Test digital object whose parent has a singlepart note')
    note = client.get_record(do['id'])['notes'][0]
    assert len(note['content']) == 1
def test_adding_child_with_note():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/resources/5',
                           title='Test child',
                           level='item',
                           notes=[{'type': 'odd', 'content': 'This is a test note'}])
    assert uri == '/repositories/2/archival_objects/24'
def test_add_digital_object_component():
    client = ArchivesSpaceClient(**AUTH)
    doc = client.add_digital_object_component('/repositories/2/digital_objects/1',
                                              label='Test DOC',
                                              title='This is a test DOC')
    assert doc['id'] == '/repositories/2/digital_object_components/3'
    assert doc['label'] == 'Test DOC'
    assert doc['title'] == 'This is a test DOC'
def test_add_nested_digital_object_component():
    client = ArchivesSpaceClient(**AUTH)
    parent = '/repositories/2/digital_object_components/3'
    doc = client.add_digital_object_component('/repositories/2/digital_objects/1',
                                              parent_digital_object_component=parent,
                                              label='Child DOC',
                                              title='This is a child DOC')
    assert client.get_record(doc['id'])['parent']['ref'] == parent
Пример #10
0
def test_augment_ids():
    client = ArchivesSpaceClient(**AUTH)
    data = client.augment_resource_ids(['/repositories/2/resources/1', '/repositories/2/resources/2'])
    assert len(data) == 2
    assert data[0]['title'] == 'Test fonds'
    assert data[0]['type'] == 'resource'
    assert data[1]['title'] == 'Some other fonds'
    assert data[1]['type'] == 'resource'
def test_augment_ids():
    client = ArchivesSpaceClient(**AUTH)
    data = client.augment_resource_ids(['/repositories/2/resources/1', '/repositories/2/resources/2'])
    assert len(data) == 2
    assert data[0]['title'] == 'Test fonds'
    assert data[0]['type'] == 'resource'
    assert data[1]['title'] == 'Some other fonds'
    assert data[1]['type'] == 'resource'
Пример #12
0
def test_add_digital_object_component():
    client = ArchivesSpaceClient(**AUTH)
    doc = client.add_digital_object_component('/repositories/2/digital_objects/1',
                                              label='Test DOC',
                                              title='This is a test DOC')
    assert doc['id'] == '/repositories/2/digital_object_components/3'
    assert doc['label'] == 'Test DOC'
    assert doc['title'] == 'This is a test DOC'
Пример #13
0
def test_add_nested_digital_object_component():
    client = ArchivesSpaceClient(**AUTH)
    parent = '/repositories/2/digital_object_components/3'
    doc = client.add_digital_object_component('/repositories/2/digital_objects/1',
                                              parent_digital_object_component=parent,
                                              label='Child DOC',
                                              title='This is a child DOC')
    assert client.get_record(doc['id'])['parent']['ref'] == parent
def test_delete_record_archival_object():
    client = ArchivesSpaceClient(**AUTH)
    record_id = '/repositories/2/archival_objects/4'
    assert client.get_record(record_id)
    r = client.delete_record(record_id)
    assert r['status'] == 'Deleted'
    with pytest.raises(CommunicationError):
        client.get_record(record_id)
Пример #15
0
def test_find_resource_children():
    client = ArchivesSpaceClient(**AUTH)
    data = client.get_resource_component_and_children('/repositories/2/resources/1')

    assert type(data) == dict
    assert len(data['children']) == 2
    assert data['has_children'] is True
    assert data['title'] == 'Test fonds'
    assert data['type'] == 'resource'
def test_listing_collections_search():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections(search_pattern='Test fonds')
    assert len(collections) == 1
    assert collections[0]['title'] == 'Test fonds'
    assert collections[0]['type'] == 'resource'

    no_results = client.find_collections(search_pattern='No such fonds')
    assert len(no_results) == 0
def test_find_resource_children():
    client = ArchivesSpaceClient(**AUTH)
    data = client.get_resource_component_and_children('/repositories/2/resources/1')

    assert type(data) == dict
    assert len(data['children']) == 2
    assert data['has_children'] is True
    assert data['title'] == 'Test fonds'
    assert data['type'] == 'resource'
Пример #18
0
def test_digital_object_with_location_of_originals_note():
    client = ArchivesSpaceClient(**AUTH)
    do = client.add_digital_object('/repositories/2/archival_objects/3',
                                   identifier='925bfc8a-d6f8-4479-9b6a-d811a4e7f6bf',
                                   title='Test digital object with note',
                                   location_of_originals='The ether')
    note = client.get_record(do['id'])['notes'][0]
    assert note['content'][0] == 'The ether'
    assert note['type'] == 'originalsloc'
Пример #19
0
def test_listing_collections_search():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections(search_pattern='Test fonds')
    assert len(collections) == 1
    assert collections[0]['title'] == 'Test fonds'
    assert collections[0]['type'] == 'resource'

    no_results = client.find_collections(search_pattern='No such fonds')
    assert len(no_results) == 0
def test_digital_object_with_location_of_originals_note():
    client = ArchivesSpaceClient(**AUTH)
    do = client.add_digital_object('/repositories/2/archival_objects/3',
                                   identifier='925bfc8a-d6f8-4479-9b6a-d811a4e7f6bf',
                                   title='Test digital object with note',
                                   location_of_originals='The ether')
    note = client.get_record(do['id'])['notes'][0]
    assert note['content'][0] == 'The ether'
    assert note['type'] == 'originalsloc'
Пример #21
0
def test_find_by_id_refid():
    client = ArchivesSpaceClient(**AUTH)
    data = client.find_by_id('archival_objects', 'ref_id', 'a118514fab1b2ee6a7e9ad259e1de355')
    assert len(data) == 1
    item = data[0]
    assert item['identifier'] == 'a118514fab1b2ee6a7e9ad259e1de355'
    assert item['id'] == '/repositories/2/archival_objects/752250'
    assert item['type'] == 'resource_component'
    assert item['title'] == 'Test AO'
    assert item['levelOfDescription'] == 'file'
Пример #22
0
def test_find_component_parent():
    client = ArchivesSpaceClient(**AUTH)
    type, id = client.find_parent_id_for_component('/repositories/2/archival_objects/3')

    assert type == ArchivesSpaceClient.RESOURCE_COMPONENT
    assert id == '/repositories/2/archival_objects/1'

    type, id = client.find_parent_id_for_component('/repositories/2/archival_objects/1')
    assert type == ArchivesSpaceClient.RESOURCE
    assert id == '/repositories/2/resources/1'
def test_find_component_parent():
    client = ArchivesSpaceClient(**AUTH)
    type, id = client.find_parent_id_for_component('/repositories/2/archival_objects/3')

    assert type == ArchivesSpaceClient.RESOURCE_COMPONENT
    assert id == '/repositories/2/archival_objects/1'

    type, id = client.find_parent_id_for_component('/repositories/2/archival_objects/1')
    assert type == ArchivesSpaceClient.RESOURCE
    assert id == '/repositories/2/resources/1'
def test_find_by_id_refid():
    client = ArchivesSpaceClient(**AUTH)
    data = client.find_by_id('archival_objects', 'ref_id', 'a118514fab1b2ee6a7e9ad259e1de355')
    assert len(data) == 1
    item = data[0]
    assert item['identifier'] == 'a118514fab1b2ee6a7e9ad259e1de355'
    assert item['id'] == '/repositories/2/archival_objects/752250'
    assert item['type'] == 'resource_component'
    assert item['title'] == 'Test AO'
    assert item['levelOfDescription'] == 'file'
def test_listing_collections_sort():
    client = ArchivesSpaceClient(**AUTH)
    asc = client.find_collections(sort_by='asc')
    assert len(asc) == 2
    assert asc[0]['title'] == 'Some other fonds'
    assert asc[0]['type'] == 'resource'

    desc = client.find_collections(sort_by='desc')
    assert len(desc) == 2
    assert desc[0]['title'] == 'Test fonds'
    assert desc[0]['type'] == 'resource'
def test_empty_dates():
    client = ArchivesSpaceClient(**AUTH)
    record = client.get_resource_component_children('/repositories/2/archival_objects/2')
    assert record['dates'] == ''
    assert record['date_expression'] == ''
    record = client.get_resource_component_and_children('/repositories/2/resources/2',
                                                        recurse_max_level=1)
    # dates are mandatory for resources, so this record does have a date but no expression
    assert record['date_expression'] == ''
    collections = client.find_collections()
    assert collections[0]['date_expression'] == ''
Пример #27
0
def test_find_resource_children_recursion_level():
    client = ArchivesSpaceClient(**AUTH)
    data = client.get_resource_component_and_children('/repositories/2/resources/1',
                                                      recurse_max_level=1)
    assert data['children'] == []
    assert data['has_children'] is True

    data = client.get_resource_component_and_children('/repositories/2/resources/1',
                                                      recurse_max_level=2)
    assert len(data['children']) == 2
    assert data['has_children'] is True
def test_posting_multiple_notes():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/resources/1',
                           title='Test child',
                           level='recordgrp',
                           notes=[{'type': 'odd', 'content': 'General'}, {'type': 'accessrestrict', 'content': 'Access'}])
    record = client.get_record(uri)
    assert record['notes'][0]['type'] == 'odd'
    assert record['notes'][0]['subnotes'][0]['content'] == 'General'
    assert record['notes'][1]['type'] == 'accessrestrict'
    assert record['notes'][1]['subnotes'][0]['content'] == 'Access'
Пример #29
0
def test_listing_collections_sort():
    client = ArchivesSpaceClient(**AUTH)
    asc = client.find_collections(sort_by='asc')
    assert len(asc) == 2
    assert asc[0]['title'] == 'Some other fonds'
    assert asc[0]['type'] == 'resource'

    desc = client.find_collections(sort_by='desc')
    assert len(desc) == 2
    assert desc[0]['title'] == 'Test fonds'
    assert desc[0]['type'] == 'resource'
Пример #30
0
def test_empty_dates():
    client = ArchivesSpaceClient(**AUTH)
    record = client.get_resource_component_children('/repositories/2/archival_objects/2')
    assert record['dates'] == ''
    assert record['date_expression'] == ''
    record = client.get_resource_component_and_children('/repositories/2/resources/2',
                                                        recurse_max_level=1)
    # dates are mandatory for resources, so this record does have a date but no expression
    assert record['date_expression'] == ''
    collections = client.find_collections()
    assert collections[0]['date_expression'] == ''
def test_find_resource_children_recursion_level():
    client = ArchivesSpaceClient(**AUTH)
    data = client.get_resource_component_and_children('/repositories/2/resources/1',
                                                      recurse_max_level=1)
    assert data['children'] == []
    assert data['has_children'] is True

    data = client.get_resource_component_and_children('/repositories/2/resources/1',
                                                      recurse_max_level=2)
    assert len(data['children']) == 2
    assert data['has_children'] is True
Пример #32
0
def test_posting_multiple_notes():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/resources/1',
                           title='Test child',
                           level='recordgrp',
                           notes=[{'type': 'odd', 'content': 'General'}, {'type': 'accessrestrict', 'content': 'Access'}])
    record = client.get_record(uri)
    assert record['notes'][0]['type'] == 'odd'
    assert record['notes'][0]['subnotes'][0]['content'] == 'General'
    assert record['notes'][1]['type'] == 'accessrestrict'
    assert record['notes'][1]['subnotes'][0]['content'] == 'Access'
Пример #33
0
def test_identifier_search_wildcard():
    client = ArchivesSpaceClient(**AUTH)
    # Searching for an identifier prefix with no wildcard returns nothing
    assert client.find_collection_ids(identifier='F') == []
    assert client.count_collections(identifier='F') == 0
    assert len(client.find_collections(identifier='F')) == 0

    assert client.find_collection_ids(identifier='F*') == ['/repositories/2/resources/1', '/repositories/2/resources/2']
    assert client.count_collections(identifier='F*') == 2
    assert len(client.find_collections(identifier='F*')) == 2
def test_edit_record_empty_note():
    client = ArchivesSpaceClient(**AUTH)
    original = client.get_record('/repositories/2/archival_objects/3')
    assert original['notes']
    new_record = {
        'id': '/repositories/2/archival_objects/3',
        'title': 'Test edited subseries w/ empty note',
        'start_date': '2014-11-01',
        'end_date': '2015-11-01',
        'date_expression': 'November, 2014 to November, 2015',
        'notes': [{
            'type': 'odd',
            'content': ''
        }],
    }
    client.edit_record(new_record)
    updated = client.get_record('/repositories/2/archival_objects/3')
    assert not updated['notes']
def test_identifier_search_wildcard():
    client = ArchivesSpaceClient(**AUTH)
    # Searching for an identifier prefix with no wildcard returns nothing
    assert client.find_collection_ids(identifier='F') == []
    assert client.count_collections(identifier='F') == 0
    assert len(client.find_collections(identifier='F')) == 0

    assert client.find_collection_ids(identifier='F*') == ['/repositories/2/resources/1', '/repositories/2/resources/2']
    assert client.count_collections(identifier='F*') == 2
    assert len(client.find_collections(identifier='F*')) == 2
Пример #36
0
def test_edit_archival_object():
    client = ArchivesSpaceClient(**AUTH)
    original = client.get_record('/repositories/2/archival_objects/3')
    assert original['title'] == 'Test subseries'
    assert original['dates'][0]['end'] == '2015-01-01'
    assert not original['notes']
    new_record = {
        'id': '/repositories/2/archival_objects/3',
        'title': 'Test edited subseries',
        'start_date': '2014-11-01',
        'end_date': '2015-11-01',
        'date_expression': 'November, 2014 to November, 2015',
        'notes': [{
            'type': 'odd',
            'content': 'This is a test note'
        }],
    }
    client.edit_record(new_record)
    updated = client.get_record('/repositories/2/archival_objects/3')
    assert updated['title'] == new_record['title']
    assert updated['dates'][0]['begin'] == new_record['start_date']
    assert updated['dates'][0]['end'] == new_record['end_date']
    assert updated['dates'][0]['expression'] == new_record['date_expression']
    assert updated['notes'][0]['type'] == new_record['notes'][0]['type']
    assert updated['notes'][0]['subnotes'][0]['content'] == new_record['notes'][0]['content']
Пример #37
0
def test_edit_record_multiple_notes():
    client = ArchivesSpaceClient(**AUTH)
    new_record = {
        'id': '/repositories/2/archival_objects/9253',
        'notes': [
            {
                'type': 'odd',
                'content': 'General note content'
            },
            {
                'type': 'accessrestrict',
                'content': 'Access restriction note',
            }
        ],
    }
    client.edit_record(new_record)
    updated = client.get_record('/repositories/2/archival_objects/9253')
    assert updated['notes'][0]['type'] == new_record['notes'][0]['type']
    assert updated['notes'][0]['subnotes'][0]['content'] == new_record['notes'][0]['content']

    assert updated['notes'][1]['type'] == new_record['notes'][1]['type']
    assert updated['notes'][1]['subnotes'][0]['content'] == new_record['notes'][1]['content']
Пример #38
0
def test_delete_record_archival_object():
    client = ArchivesSpaceClient(**AUTH)
    record_id = '/repositories/2/archival_objects/4'
    assert client.get_record(record_id)
    r = client.delete_record(record_id)
    assert r['status'] == 'Deleted'
    with pytest.raises(CommunicationError):
        client.get_record(record_id)
Пример #39
0
def test_edit_record_empty_note():
    client = ArchivesSpaceClient(**AUTH)
    original = client.get_record('/repositories/2/archival_objects/3')
    assert original['notes']
    new_record = {
        'id': '/repositories/2/archival_objects/3',
        'title': 'Test edited subseries w/ empty note',
        'start_date': '2014-11-01',
        'end_date': '2015-11-01',
        'date_expression': 'November, 2014 to November, 2015',
        'notes': [{
            'type': 'odd',
            'content': ''
        }],
    }
    client.edit_record(new_record)
    updated = client.get_record('/repositories/2/archival_objects/3')
    assert not updated['notes']
def test_get_resource_type():
    client = ArchivesSpaceClient(**AUTH)
    assert client.resource_type('/repositories/2/resources/2') == 'resource'
    assert client.resource_type('/repositories/2/archival_objects/3') == 'resource_component'
Пример #41
0
def test_contentless_notes():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections()
    assert collections[-1]['notes'][0]['type'] == 'bioghist'
    assert collections[-1]['notes'][0]['content'] == ''
def test_rendering_record_containing_a_singlepart_note():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections()
    assert len(collections) == 2
    assert collections[1]['notes'][0]['content'] == 'Singlepart note'
Пример #43
0
def test_date_expression():
    client = ArchivesSpaceClient(**AUTH)
    record = client.get_resource_component_and_children('/repositories/2/archival_objects/3',
                                                        recurse_max_level=1)
    assert record['date_expression'] == 'November, 2014 to November, 2015'
def test_listing_collections():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections()
    assert len(collections) == 2
    assert collections[0]['title'] == 'Test fonds'
    assert collections[0]['type'] == 'resource'
def test_get_resource_type_raises_on_invalid_input():
    client = ArchivesSpaceClient(**AUTH)
    with pytest.raises(ArchivesSpaceError):
        client.resource_type('invalid')
def test_identifier_search_exact_match():
    client = ArchivesSpaceClient(**AUTH)
    assert client.find_collection_ids(identifier='F1') == ['/repositories/2/resources/1']
    assert client.count_collections(identifier='F1') == 1
    assert len(client.find_collections(identifier='F1')) == 1
Пример #47
0
def test_add_child_resource_component():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/archival_objects/1', title='Test child', level='item')
    assert uri == '/repositories/2/archival_objects/5'
Пример #48
0
def test_identifier_search_exact_match():
    client = ArchivesSpaceClient(**AUTH)
    assert client.find_collection_ids(identifier='F1') == ['/repositories/2/resources/1']
    assert client.count_collections(identifier='F1') == 1
    assert len(client.find_collections(identifier='F1')) == 1
Пример #49
0
def test_add_digital_object():
    client = ArchivesSpaceClient(**AUTH)
    do = client.add_digital_object('/repositories/2/archival_objects/3',
                                   identifier='38c99e89-20a1-4831-ba57-813fb6420e59',
                                   title='Test digital object')
    assert do['id'] == '/repositories/2/digital_objects/8'
def test_date_expression():
    client = ArchivesSpaceClient(**AUTH)
    record = client.get_resource_component_and_children('/repositories/2/archival_objects/3',
                                                        recurse_max_level=1)
    assert record['date_expression'] == 'November, 2014 to November, 2015'
def test_add_digital_object():
    client = ArchivesSpaceClient(**AUTH)
    do = client.add_digital_object('/repositories/2/archival_objects/3',
                                   identifier='38c99e89-20a1-4831-ba57-813fb6420e59',
                                   title='Test digital object')
    assert do['id'] == '/repositories/2/digital_objects/8'
Пример #52
0
def test_listing_collections():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections()
    assert len(collections) == 2
    assert collections[0]['title'] == 'Test fonds'
    assert collections[0]['type'] == 'resource'
Пример #53
0
 def escape(s, **kwargs):
     return ArchivesSpaceClient._escape_solr_query(s, **kwargs)
def test_count_collection_ids():
    client = ArchivesSpaceClient(**AUTH)
    ids = client.count_collections()
    assert ids == 2
Пример #55
0
def test_listing_collections_search_spaces():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections(identifier="2015044 Aa Ac")
    assert len(collections) == 1
    assert collections[0]['title'] == 'Resource with spaces in the identifier'
    assert collections[0]['levelOfDescription'] == 'collection'
def test_count_collection_ids_search():
    client = ArchivesSpaceClient(**AUTH)
    ids = client.count_collections(search_pattern='Some')
    assert ids == 1
Пример #57
0
def test_find_resource_id():
    client = ArchivesSpaceClient(**AUTH)
    assert client.find_resource_id_for_component('/repositories/2/archival_objects/3') == '/repositories/2/resources/1'
Пример #58
0
def test_rendering_record_containing_a_singlepart_note():
    client = ArchivesSpaceClient(**AUTH)
    collections = client.find_collections()
    assert len(collections) == 2
    assert collections[1]['notes'][0]['content'] == 'Singlepart note'
def test_add_child_resource_component():
    client = ArchivesSpaceClient(**AUTH)
    uri = client.add_child('/repositories/2/archival_objects/1', title='Test child', level='item')
    assert uri == '/repositories/2/archival_objects/5'
def test_find_resource_id():
    client = ArchivesSpaceClient(**AUTH)
    assert client.find_resource_id_for_component('/repositories/2/archival_objects/3') == '/repositories/2/resources/1'