예제 #1
0
def test_deposit_load_task(dummy_location, deposit_dump, deposit_user,
                           deposit_record_pid):
    """Test the deposit loading task."""

    # Create a user and a record with PID corresponding with test deposit data
    assert RecordMetadata.query.count() == 1
    for dep in deposit_dump:
        load_deposit(dep)
    assert RecordMetadata.query.count() == 2
    res = Resolver(pid_type='depid',
                   object_type='rec',
                   getter=Record.get_record)
    dep_pid, dep_rec = res.resolve('1')
    assert '_deposit' in dep_rec
    assert '_files' in dep_rec
    sip = SIP.query.one()
    assert sip.user_id == deposit_user.id
    rsip = RecordSIP.query.one()
    assert rsip.pid_id == deposit_record_pid.id
    assert rsip.sip_id == sip.id

    # Test RecordsFiles API
    res = Resolver(pid_type='depid',
                   object_type='rec',
                   getter=RecordFiles.get_record)
    dep_pid, dep_recbucket = res.resolve('1')
    files = list(dep_recbucket.files)
    assert files[0]['key'] == 'bazbar.pdf'
    assert files[0]['size'] == 12345
    assert files[0]['checksum'] == "md5:00000000000000000000000000000000"
    assert files[0]['bucket']
    assert SIPFile.query.count() == 1
def test_deposit_load_task(dummy_location, deposit_dump, deposit_user, deposit_record_pid):
    """Test the deposit loading task."""

    # Create a user and a record with PID corresponding with test deposit data
    assert RecordMetadata.query.count() == 1
    for dep in deposit_dump:
        load_deposit(dep)
    assert RecordMetadata.query.count() == 2
    res = Resolver(pid_type="depid", object_type="rec", getter=Record.get_record)
    dep_pid, dep_rec = res.resolve("1")
    assert "_deposit" in dep_rec
    assert "_files" in dep_rec
    sip = SIP.query.one()
    assert sip.user_id == deposit_user.id
    rsip = RecordSIP.query.one()
    assert rsip.pid_id == deposit_record_pid.id
    assert rsip.sip_id == sip.id

    # Test RecordsFiles API
    res = Resolver(pid_type="depid", object_type="rec", getter=RecordFiles.get_record)
    dep_pid, dep_recbucket = res.resolve("1")
    files = list(dep_recbucket.files)
    assert files[0]["key"] == "bazbar.pdf"
    assert files[0]["size"] == 12345
    assert files[0]["checksum"] == "md5:00000000000000000000000000000000"
    assert files[0]["bucket"]
    assert SIPFile.query.count() == 1
def test_deposit_load(dummy_location, deposit_user, deposit_record_pid):
    """Test the deposit loading function."""
    dep1 = dict(
        sips=[dict(metadata=dict(recid="10"), agents=[dict(user_id=1)], package="Content1")],
        _p=dict(id="1", created="2016-08-25T20:20:18+00:00"),
    )
    dep2 = dict(
        sips=[dict(metadata=dict(recid="50"), agents=[dict(user_id=1)], package="Content2")],
        _p=dict(id="2", submitted=True, created="2016-08-25T20:20:18+00:00"),
    )
    dep3 = dict(
        sips=[dict(metadata=dict(recid="10"), agents=[dict(user_id=5)], package="Content3")],
        _p=dict(id="3", created="2016-08-25T20:20:18+00:00"),
    )
    dep4 = dict(
        sips=[
            dict(metadata=dict(recid="10"), agents=[dict(user_id=5)], package="Content4"),
            dict(metadata=dict(recid="11"), agents=[dict(user_id=5)], package="Content5"),
        ],
        _p=dict(id="4", created="2016-08-25T20:20:18+00:00"),
    )
    load_deposit(dep1)
    pytest.raises(DepositMultipleRecids, load_deposit, dep4)

    # Should set user to null because user_id does not exist
    load_deposit(dep3)
    assert SIP.query.filter_by(content="Content3").one().user_id is None
def test_deposit_load(dummy_location, deposit_user, deposit_record_pid):
    """Test the deposit loading function."""
    dep1 = dict(sips=[dict(metadata=dict(recid='10'),
                           agents=[dict(user_id=1), ],
                           package='Foobar'), ],
                _p=dict(id='1'))
    dep2 = dict(sips=[dict(metadata=dict(recid='50'),
                           agents=[dict(user_id=1), ],
                           package='Foobar'), ],
                _p=dict(id='2'))
    dep3 = dict(sips=[dict(metadata=dict(recid='10'),
                           agents=[dict(user_id=5), ],
                           package='Foobar'), ],
                _p=dict(id='3'))
    dep4 = dict(sips=[dict(metadata=dict(recid='10'),
                           agents=[dict(user_id=5), ],
                           package='Foobar'),
                      dict(metadata=dict(recid='11'),
                           agents=[dict(user_id=5), ],
                           package='Foobar'), ],
                _p=dict(id='4'))
    load_deposit(dep1)
    pytest.raises(DepositRecidDoesNotExist, load_deposit, dep2)
    pytest.raises(DepositSIPUserDoesNotExist, load_deposit, dep3)
    pytest.raises(DepositMultipleRecids, load_deposit, dep4)
예제 #5
0
def test_deposit_load(dummy_location, deposit_user, deposit_record_pid):
    """Test the deposit loading function."""
    dep1 = dict(sips=[
        dict(metadata=dict(recid='10'),
             agents=[
                 dict(user_id=1),
             ],
             package='Content1'),
    ],
                _p=dict(id='1', created='2016-08-25T20:20:18+00:00'))
    dep2 = dict(sips=[
        dict(metadata=dict(recid='50'),
             agents=[
                 dict(user_id=1),
             ],
             package='Content2'),
    ],
                _p=dict(id='2',
                        submitted=True,
                        created='2016-08-25T20:20:18+00:00'))
    dep3 = dict(sips=[
        dict(metadata=dict(recid='10'),
             agents=[
                 dict(user_id=5),
             ],
             package='Content3'),
    ],
                _p=dict(id='3', created='2016-08-25T20:20:18+00:00'))
    dep4 = dict(sips=[
        dict(metadata=dict(recid='10'),
             agents=[
                 dict(user_id=5),
             ],
             package='Content4'),
        dict(metadata=dict(recid='11'),
             agents=[
                 dict(user_id=5),
             ],
             package='Content5'),
    ],
                _p=dict(id='4', created='2016-08-25T20:20:18+00:00'))
    load_deposit(dep1)
    pytest.raises(DepositMultipleRecids, load_deposit, dep4)

    # Should set user to null because user_id does not exist
    load_deposit(dep3)
    assert SIP.query.filter_by(content="Content3").one().user_id is None
예제 #6
0
def test_deposit_load(dummy_location, deposit_user, deposit_record_pid):
    """Test the deposit loading function."""
    dep1 = dict(sips=[
        dict(metadata=dict(recid='10'),
             agents=[
                 dict(user_id=1),
             ],
             package='Foobar'),
    ],
                _p=dict(id='1'))
    dep2 = dict(sips=[
        dict(metadata=dict(recid='50'),
             agents=[
                 dict(user_id=1),
             ],
             package='Foobar'),
    ],
                _p=dict(id='2'))
    dep3 = dict(sips=[
        dict(metadata=dict(recid='10'),
             agents=[
                 dict(user_id=5),
             ],
             package='Foobar'),
    ],
                _p=dict(id='3'))
    dep4 = dict(sips=[
        dict(metadata=dict(recid='10'),
             agents=[
                 dict(user_id=5),
             ],
             package='Foobar'),
        dict(metadata=dict(recid='11'),
             agents=[
                 dict(user_id=5),
             ],
             package='Foobar'),
    ],
                _p=dict(id='4'))
    load_deposit(dep1)
    pytest.raises(DepositRecidDoesNotExist, load_deposit, dep2)
    pytest.raises(DepositSIPUserDoesNotExist, load_deposit, dep3)
    pytest.raises(DepositMultipleRecids, load_deposit, dep4)