예제 #1
0
def create_category(name: str, color: str) -> model.PoolCategory:
    category = model.PoolCategory()
    update_category_name(category, name)
    update_category_color(category, color)
    if not get_all_categories():
        category.default = True
    return category
예제 #2
0
 def factory(
     id=None, names=None, description=None, category=None, time=None
 ):
     if not category:
         category = model.PoolCategory(get_unique_name())
         db.session.add(category)
     pool = model.Pool()
     pool.pool_id = id
     pool.names = []
     for i, name in enumerate(names or [get_unique_name()]):
         pool.names.append(model.PoolName(name, i))
     pool.description = description
     pool.category = category
     pool.creation_time = time or datetime(1996, 1, 1)
     return pool
예제 #3
0
def test_cascade_deletions(pool_factory, post_factory):
    post1 = post_factory()
    post2 = post_factory()
    pool = model.Pool()
    pool.names = [model.PoolName("alias1", 0), model.PoolName("alias2", 1)]
    pool.posts = []
    pool.category = model.PoolCategory("category")
    pool.creation_time = datetime(1997, 1, 1)
    pool.last_edit_time = datetime(1998, 1, 1)
    db.session.add_all([pool, post1, post2])
    db.session.commit()

    assert pool.pool_id is not None
    pool.posts.append(post1)
    pool.posts.append(post2)
    db.session.commit()

    db.session.delete(pool)
    db.session.commit()
    assert db.session.query(model.Pool).count() == 0
    assert db.session.query(model.PoolName).count() == 0
    assert db.session.query(model.PoolPost).count() == 0
    assert db.session.query(model.PoolCategory).count() == 1
    assert db.session.query(model.Post).count() == 2
예제 #4
0
def test_saving_pool(pool_factory, post_factory):
    post1 = post_factory()
    post2 = post_factory()
    pool = model.Pool()
    pool.names = [model.PoolName("alias1", 0), model.PoolName("alias2", 1)]
    pool.posts = []
    pool.category = model.PoolCategory("category")
    pool.creation_time = datetime(1997, 1, 1)
    pool.last_edit_time = datetime(1998, 1, 1)
    db.session.add_all([pool, post1, post2])
    db.session.commit()

    assert pool.pool_id is not None
    pool.posts.append(post1)
    pool.posts.append(post2)
    db.session.commit()

    pool = (db.session.query(model.Pool).join(
        model.PoolName).filter(model.PoolName.name == "alias1").one())
    assert [pool_name.name for pool_name in pool.names] == ["alias1", "alias2"]
    assert pool.category.name == "category"
    assert pool.creation_time == datetime(1997, 1, 1)
    assert pool.last_edit_time == datetime(1998, 1, 1)
    assert [post.post_id for post in pool.posts] == [1, 2]
예제 #5
0
 def factory(name=None, color="dummy", default=False):
     category = model.PoolCategory()
     category.name = name or get_unique_name()
     category.color = color
     category.default = default
     return category