Esempio n. 1
0
def test_record_transition(record: ExampleRecord):
    # Test state is changed when transition conditions are met
    assert record['oarepo:recordStatus'] == 'closed'
    record.open(id='ccc')
    assert record['oarepo:recordStatus'] == 'open'

    # Test state is not changed when transition conditions are not met
    with pytest.raises(InvalidSourceStateError):
        record.open(id='aaa')
    assert record['oarepo:recordStatus'] == 'open'
Esempio n. 2
0
def create_record(data):
    """Create a test record."""
    with db.session.begin_nested():
        data = copy.deepcopy(data)
        rec_uuid = uuid.uuid4()
        pid = record_pid_minter(rec_uuid, data)
        record = ExampleRecord.create(data, id_=rec_uuid)
        return pid, record
Esempio n. 3
0
def record(app):
    """Minimal Record object."""
    record_uuid = uuid.uuid4()
    new_record = {'title': 'example', 'oarepo:recordStatus': 'closed'}

    pid = record_pid_minter(record_uuid, data=new_record)
    record = ExampleRecord.create(data=new_record, id_=record_uuid)

    db.session.commit()
    yield record
Esempio n. 4
0
def test_record_user_transitions(record: ExampleRecord, users):
    login_user(users['user'])
    ut = record.available_user_transitions()
    assert len(ut.items()) == 2
    assert 'open' in ut.keys()

    login_user(users['editor'])
    ut = record.all_user_transitions()
    assert set(ut.keys()) == {'close', 'delete', 'open', 'publish'}

    ut = record.available_user_transitions()
    assert set(ut.keys()) == {'open', 'delete'}

    login_user(users['admin'])
    ut = record.all_user_transitions()
    assert set(ut.keys()) == {'delete', 'archive', 'close', 'open', 'publish'}

    ut = record.available_user_transitions()
    assert set(ut.keys()) == {'delete', 'archive', 'open'}
Esempio n. 5
0
def test_transition_permissions(record: ExampleRecord, users):
    # Regular user can neither publish, nor archive
    login_user(users['user'])
    assert record['oarepo:recordStatus'] == 'closed'
    with pytest.raises(InvalidPermissionError):
        record.archive()

    record.open(id='abc')
    with pytest.raises(InvalidPermissionError):
        record.publish()
    record.close(id=4)

    # User editor can publish, but not archive record
    login_user(users['editor'])
    assert record['oarepo:recordStatus'] == 'closed'
    record.open(id='bca')
    record.publish()
    assert record['oarepo:recordStatus'] == 'published'

    with pytest.raises(InvalidPermissionError):
        record.archive()
    assert record['oarepo:recordStatus'] == 'published'

    # User with admin role can both archive and publish
    login_user(users['admin'])
    record.archive()
    assert record['oarepo:recordStatus'] == 'archived'
    record.publish()
    assert record['oarepo:recordStatus'] == 'published'
Esempio n. 6
0
def test_clear(record: ExampleRecord):
    state = record['oarepo:recordStatus']
    record.clear()
    assert record['oarepo:recordStatus'] == state
Esempio n. 7
0
def test_record_transitions(record: ExampleRecord):
    assert len(record.all_transitions()) == 5
    assert 'publish' in record.all_transitions().keys()
    for trans in record.all_transitions().values():
        assert isinstance(trans, Transition)