Esempio n. 1
0
def test_update(app, db):
    pid, rec = make_sample_record(db, 'update-community', 'A', None)
    with pytest.raises(AttributeError):
        rec.update({'oarepo:primaryCommunity': 'B'})

    rec.update({'title': 'blah'})
    assert rec['title'] == 'blah'
Esempio n. 2
0
def test_patch(app, db):
    pid, rec = make_sample_record(db, 'patch-community', 'A', None)
    with pytest.raises(AttributeError):
        rec.patch([
            {
                'op': 'replace',
                'path': '/oarepo:primaryCommunity',
                'value': 'invalid'
            }
        ])
Esempio n. 3
0
def sample_records(app, db, es_clear):
    try:
        current_search.client.indices.delete('records-record-v1.0.0')
    except:
        pass
    if 'records-record-v1.0.0' not in current_search.mappings:
        current_search.register_mappings('records', 'tests.api.mappings')
    list(current_search.delete())
    list(current_search.create())
    records = {
        'A': [
            make_sample_record(db, 'Test 1 in community A', 'A', 'published'),
            make_sample_record(db, 'Test 2 in community A', 'A'),
            make_sample_record(db, 'Test 3 in community A', 'A')
        ],
        'B': [
            make_sample_record(db, 'Test 4 in community B', 'B', 'published'),
            make_sample_record(db, 'Test 5 in community B', 'B'),
            make_sample_record(db, 'Test 6 in community B', 'B', 'published', secondary=['C']),
        ],
        'comtest': [
            make_sample_record(db, 'Test 4 in community comid', 'comtest', secondary=['B']),
            {
                STATE_EDITING: make_sample_record(db, 'Test 4 in community comid', 'comtest',
                                                  state=STATE_EDITING, secondary=['B']),
                STATE_PENDING_APPROVAL: make_sample_record(db, 'Test 4 in community comid', 'comtest',
                                                  state=STATE_PENDING_APPROVAL, secondary=['B']),
                STATE_APPROVED: make_sample_record(db, 'Test 4 in community comid', 'comtest',
                                                  state=STATE_APPROVED, secondary=['B']),
                STATE_PUBLISHED: make_sample_record(db, 'Test 4 in community comid', 'comtest',
                                                  state=STATE_PUBLISHED, secondary=['B']),
            }
        ]
    }
    current_search.flush_and_refresh('records-record-v1.0.0')
    return records
Esempio n. 4
0
def test_delete(app, db):
    pid, rec = make_sample_record(db, 'delete-community', 'A', None)
    with pytest.raises(AttributeError):
        del rec['oarepo:primaryCommunity']
Esempio n. 5
0
def test_set(app, db):
    pid, rec = make_sample_record(db, 'set-community', 'A', None)
    with pytest.raises(AttributeError):
        rec['oarepo:primaryCommunity'] = 'C'
Esempio n. 6
0
def test_clear(app, db):
    pid, rec = make_sample_record(db, 'clear-community', 'A', None)
    rec.clear()
    assert rec['oarepo:primaryCommunity'] == 'A'
Esempio n. 7
0
def test_secondary_communities(app, db):
    pid, rec = make_sample_record(db, 'secondary', 'A', None, ['B', 'C'])
    assert rec.secondary_communities == ['B', 'C']
Esempio n. 8
0
def test_primary_community(app, db):
    pid, rec = make_sample_record(db, 'primary', 'A', None)
    assert rec.primary_community == 'A'
Esempio n. 9
0
def test_schema_create(app, db):
    pid, rec = make_sample_record(db, 'no-community', 'A', None)
    assert rec['oarepo:primaryCommunity'] == 'A'

    with pytest.raises(AttributeError):
        make_sample_record(db, 'invalid-community', None, None)