示例#1
0
def test_inherit():
    # TODO this test depends on particular repo_models modules and fields
    collection = models.Collection(path_abs='/var/www/media/ddr/ddr-test-123')
    entity = models.Entity(
        path_abs='/var/www/media/ddr/ddr-test-123/files/ddr-test-123-456')
    file_ = models.File(
        path_abs=
        '/var/www/media/ddr/ddr-test-123/files/ddr-test-123-456/files/ddr-test-123-456-master-abc123'
    )

    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
示例#2
0
def test_Entity_locking():
    collection_id = 'ddr-testing-123'
    entity_id = 'ddr-testing-123-456'
    collection_path = os.path.join(MEDIA_BASE, 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)
示例#3
0
def test_Entity_changelog():
    collection_id = 'ddr-testing-123'
    entity_id = 'ddr-testing-123-456'
    collection_path = os.path.join(MEDIA_BASE, 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
示例#4
0
def test_Entity__init__():
    collection_id = 'ddr-testing-123'
    entity_id = 'ddr-testing-123-456'
    collection_path = os.path.join(MEDIA_BASE, 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 == MEDIA_BASE
    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'
示例#5
0
    def resolve_entities(self, chunks):
        if chunks is None:
            return []

        # walk NP subtrees for each chunk tree
        entities = []
        for chunk in chunks:
            for np_tree in chunk.subtrees(
                    lambda subtree: subtree.label() == 'NP'):
                # pick out only nouns
                nns = [leaf for leaf in np_tree.leaves() if 'NN' in leaf[1]]

                # if there are nouns in this subtree, create an entity
                if 0 != len(nns):
                    entity = models.Entity(
                        # use the last noun in the NP subtree
                        nns[-1][0],
                        np_tree)
                    entities.append(entity)

        return entities
示例#6
0
    async def post(self, uid, fmt=None):
        """Create or modify an object
        """
        response = {'json_response': 'json response data'}
        self.set_json_headers()

        if uid is not None:
            entity = models.Entity.objects(id=uid).get()
        else:
            entity = models.Entity()

        form = models.EntityForm(self.request.arguments, id=uid)

        if self.request.arguments and form.validate():
            # form.populate_obj(entity)
            entity.save()
            response['errors'] = False
        else:
            self.set_status(400)
            response['errors'] = form.errors
        self.write(response)
        self.finish()