Example #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
Example #2
0
def post_collection():
    """	URL - /api/v1.0/collection
		Method - POST

		Creates a new collection and returns a ID that represents it.
	"""
    post_json = request.get_json()
    if not post_json:
        abort(400)
    title = post_json['title']
    description = post_json['description']
    category = post_json['category']
    user_id = post_json['user_id']

    if None in [title, description, category, user_id]:
        abort(400)

    collection = models.Collection(
        user_id=user_id,
        title=title,
        description=description,
        category=category,
        published=False,
        publish_date=None,
        thumbnail=None,
    )
    db.session.add(collection)
    db.session.commit()
    return jsonify({'collection_id': collection.id}), 201
Example #3
0
    def create_collection(self, form):
        collection = models.Collection(name=form.name.data,
                                       description=form.description.data,
                                       model_name=form.model_name.data,
                                       photoshop=form.photoshop.data,
                                       filming_time=form.filming_time.data)
        for image in form.images.data:
            if image not in collection.images:
                collection.images.append(image)
        collection.user = self.current_user

        self.session.add(collection)

        return collection
Example #4
0
def create(user, name, description=None):
    public_id = uuid.uuid4().hex

    new_collection = models.Collection(name=name,
                                       user_id=user.user_id(),
                                       public_id=public_id)

    if description:
        new_collection.description = description

    new_collection.put()

    logging.info(new_collection)

    return new_collection
Example #5
0
def test_Collection__init__():
    cid = 'ddr-testing-123'
    path_abs = os.path.join(MEDIA_BASE, cid)
    c = models.Collection(path_abs)
    assert c.root == MEDIA_BASE
    assert c.id == 'ddr-testing-123'
    assert c.path == path_abs
    assert c.path_abs == path_abs
    assert c.gitignore_path == os.path.join(path_abs, '.gitignore')
    assert c.annex_path == os.path.join(path_abs, '.git/annex')
    assert c.files_path == os.path.join(path_abs, 'files')
    assert c.lock_path == os.path.join(path_abs, 'lock')
    assert c.control_path == os.path.join(path_abs, 'control')
    assert c.changelog_path == os.path.join(path_abs, 'changelog')
    assert (c.path_rel == None) or (c.path_rel == '')
    assert c.gitignore_path_rel == '.gitignore'
    assert c.annex_path_rel == '.git/annex'
    assert c.files_path_rel == 'files'
    assert c.control_path_rel == 'control'
    assert c.changelog_path_rel == 'changelog'
Example #6
0
def test_Collection_locking():
    cid = 'ddr-testing-123'
    path_abs = os.path.join(MEDIA_BASE, cid)
    c = models.Collection(path_abs)
    text = 'testing'
    # prep
    if os.path.exists(path_abs):
        shutil.rmtree(path_abs)
    os.makedirs(c.path)
    # before locking
    assert c.locked() == False
    assert not os.path.exists(c.lock_path)
    # locking
    assert c.lock(text) == 'ok'
    # locked
    assert c.locked() == text
    assert os.path.exists(c.lock_path)
    # unlocking
    assert c.unlock(text) == 'ok'
    assert c.locked() == False
    assert not os.path.exists(c.lock_path)
    # clean up
    if os.path.exists(path_abs):
        shutil.rmtree(path_abs)
Example #7
0
File: app.py Project: Peiiii/sun
async def do_root():
    # await blman.rebuild()
    blogs=await man.blog_tb.findAll(visible='true')
    blogs=models.Collection(blogs).sortBy('created_at')
    return pageResponse(template=config.page_templates.root,blogs=blogs,config=config.site)
Example #8
0
File: app.py Project: Peiiii/sun
 async def handler():
     blogs=await man.blog_tb.findAll(visible='true')
     blogs=models.Collection(blogs).sortBy('created_at')
     return pageResponse(template=v,config=config,blogs=blogs)
Example #9
0
    def create_collection(self):
        collection = models.Collection(name='cover')
        self.session.add(collection)

        return collection
Example #10
0
# if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
#     api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
#     api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
# else:
#     api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))

import models
from read import ParsedArticle

#For Testing

u = models.User(username="******", email="*****@*****.**", password='******')
db.session.add(u)
db.session.commit()

c = models.Collection(user_id=u.id, title="A test collection", description="A short description for testing.")
db.session.add(c)
db.session.commit()

parsedArticle = ParsedArticle('http://www.nytimes.com/2014/09/20/world/africa/ebola-outbreak.html')
a1 = models.Article(
	url = parsedArticle.get_url(),
	title = parsedArticle.get_title(),
	content = parsedArticle.get_content(),
	author = parsedArticle.get_author(),
	excerpt = parsedArticle.get_excerpt(),
	date = parsedArticle.get_date(),
	dek = parsedArticle.get_dek(),
	lead_image = parsedArticle.get_lead_image(),
)