Exemplo n.º 1
0
def test_inherit():
    # TODO this test depends on particular repo_models modules and fields
    ci = identifier.Identifier('/var/www/media/ddr/ddr-testing-123')
    ei = identifier.Identifier(
        '/var/www/media/ddr/ddr-testing-123/files/ddr-testing-123-456')
    fi = identifier.Identifier(
        '/var/www/media/ddr/ddr-testing-123/files/ddr-testing-123-456/files/ddr-testing-123-456-master-abc123'
    )
    collection = models.Collection(ci.path_abs(), identifier=ci)
    entity = models.Entity(ei.path_abs(), identifier=ei)
    file_ = models.File(fi.path_abs(), identifier=fi)

    collection.public = True
    entity.public = False
    assert collection.public == True
    assert entity.public == False
    inheritance.inherit(collection, entity)
    assert collection.public == True
    assert entity.public == True

    entity.public = True
    file_.public = False
    assert entity.public == True
    assert file_.public == False
    inheritance.inherit(entity, file_)
    assert entity.public == True
    assert file_.public == True

    collection.public = True
    file_.public = False
    assert collection.public == True
    assert file_.public == False
    inheritance.inherit(collection, file_)
    assert collection.public == True
    assert file_.public == True
Exemplo n.º 2
0
def test_Entity_locking(tmpdir):
    collection_id = 'ddr-testing-123'
    entity_id = 'ddr-testing-123-456'
    collection_path = str(tmpdir / collection_id)
    path_abs = os.path.join(collection_path, 'files', entity_id)
    e = models.Entity(path_abs)
    text = 'testing'
    # prep
    if os.path.exists(path_abs):
        shutil.rmtree(path_abs)
    os.makedirs(e.path)
    # before locking
    assert e.locked() == False
    assert not os.path.exists(e.lock_path)
    # locking
    assert e.lock(text) == 'ok'
    # locked
    assert e.locked() == text
    assert os.path.exists(e.lock_path)
    # unlocking
    assert e.unlock(text) == 'ok'
    assert e.locked() == False
    assert not os.path.exists(e.lock_path)
    # clean up
    if os.path.exists(path_abs):
        shutil.rmtree(path_abs)
Exemplo n.º 3
0
def test_Entity_changelog(tmpdir):
    collection_id = 'ddr-testing-123'
    entity_id = 'ddr-testing-123-456'
    collection_path = str(tmpdir / collection_id)
    path_abs = os.path.join(collection_path, 'files', entity_id)
    e = models.Entity(path_abs)
    changelog_path = os.path.join(path_abs, 'changelog')
    assert e.changelog() == '%s is empty or missing' % changelog_path
Exemplo n.º 4
0
def test_Entity__init__(tmpdir):
    collection_id = 'ddr-testing-123'
    entity_id = 'ddr-testing-123-456'
    collection_path = str(tmpdir / collection_id)
    path_abs = os.path.join(collection_path, 'files', entity_id)
    e = models.Entity(path_abs)
    assert e.parent_path == collection_path
    assert e.parent_id == collection_id
    assert e.root == str(tmpdir)
    assert e.id == 'ddr-testing-123-456'
    assert e.path == path_abs
    assert e.path_abs == path_abs
    assert e.files_path == os.path.join(path_abs, 'files')
    assert e.lock_path == os.path.join(path_abs, 'lock')
    assert e.control_path == os.path.join(path_abs, 'control')
    assert e.changelog_path == os.path.join(path_abs, 'changelog')
    assert e.path_rel == 'files/ddr-testing-123-456'
    assert e.files_path_rel == 'files/ddr-testing-123-456/files'
    assert e.control_path_rel == 'files/ddr-testing-123-456/control'
    assert e.changelog_path_rel == 'files/ddr-testing-123-456/changelog'
Exemplo n.º 5
0
def test_Entity_is_modified(tmpdir):
    collection_id = 'ddr-testing-123'
    entity_id = 'ddr-testing-123-456'
    collection_path = str(tmpdir / collection_id)
    path_abs = os.path.join(collection_path, 'files', entity_id)

    print('NEW DOCUMENT')
    o0 = models.Entity(path_abs)
    print('o0 %s' % o0)
    # nonexistent documents are considered modified
    print('o0.is_modified() %s' % o0.is_modified())
    assert o0.is_modified() == True
    now = datetime.now()
    o0.record_created = now
    o0.record_lastmod = now
    o0.title = 'TITLE'
    o0.write_json(doc_metadata=False)

    print('EXISTING DOCUMENT')
    o1 = identifier.Identifier(id=entity_id, base_path=str(tmpdir)).object()
    print('o1 %s' % o1)
    # freshly loaded object should not be modified
    out1 = o1.is_modified()
    print('out1 %s' % out1)
    assert out1 == {}

    o1.title = 'new title'
    assert o1.title == 'new title'
    print('o1.is_modified() %s' % o1.is_modified())
    assert o1.is_modified()
    assert o1.title == 'new title'
    o1.write_json(doc_metadata=False)

    # existing document
    o2 = identifier.Identifier(id=entity_id, base_path=str(tmpdir)).object()
    # freshly loaded object should not be modified
    print('o2.is_modified() %s' % o2.is_modified())
    assert not o2.is_modified()
    assert o2.title == 'new title'