コード例 #1
0
def test_get_post_count(post_factory):
    previous_count = posts.get_post_count()
    db.session.add_all([post_factory(), post_factory()])
    db.session.flush()
    new_count = posts.get_post_count()
    assert previous_count == 0
    assert new_count == 2
コード例 #2
0
def test_get_post_count(post_factory):
    previous_count = posts.get_post_count()
    db.session.add_all([post_factory(), post_factory()])
    db.session.flush()
    new_count = posts.get_post_count()
    assert previous_count == 0
    assert new_count == 2
コード例 #3
0
def test_delete(post_factory):
    post = post_factory()
    db.session.add(post)
    db.session.flush()
    assert posts.get_post_count() == 1
    posts.delete(post)
    db.session.flush()
    assert posts.get_post_count() == 0
コード例 #4
0
def test_delete(post_factory):
    post = post_factory()
    db.session.add(post)
    db.session.flush()
    assert posts.get_post_count() == 1
    posts.delete(post)
    db.session.flush()
    assert posts.get_post_count() == 0
コード例 #5
0
def test_delete(post_factory, config_injector):
    config_injector({"delete_source_files": False})
    post = post_factory()
    db.session.add(post)
    db.session.flush()
    assert posts.get_post_count() == 1
    posts.delete(post)
    db.session.flush()
    assert posts.get_post_count() == 0
コード例 #6
0
def get_info(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
    post_feature = posts.try_get_current_post_feature()
    ret = {
        'postCount': posts.get_post_count(),
        'diskUsage': _get_disk_usage(),
        'serverTime': datetime.utcnow(),
        'config': {
            'userNameRegex':
            config.config['user_name_regex'],
            'passwordRegex':
            config.config['password_regex'],
            'tagNameRegex':
            config.config['tag_name_regex'],
            'tagCategoryNameRegex':
            config.config['tag_category_name_regex'],
            'defaultUserRank':
            config.config['default_rank'],
            'privileges':
            util.snake_case_to_lower_camel_case_keys(
                config.config['privileges']),
        },
    }
    if auth.has_privilege(ctx.user, 'posts:view:featured'):
        ret['featuredPost'] = (posts.serialize_post(
            post_feature.post, ctx.user) if post_feature else None)
        ret['featuringUser'] = (users.serialize_user(
            post_feature.user, ctx.user) if post_feature else None)
        ret['featuringTime'] = post_feature.time if post_feature else None
    return ret
コード例 #7
0
ファイル: info_api.py プロジェクト: stopsquarks/quarkman
def get_info(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
    post_feature = posts.try_get_current_post_feature()
    ret = {
        "postCount": posts.get_post_count(),
        "diskUsage": _get_disk_usage(),
        "serverTime": datetime.utcnow(),
        "config": {
            "name": config.config["name"],
            "userNameRegex": config.config["user_name_regex"],
            "passwordRegex": config.config["password_regex"],
            "tagNameRegex": config.config["tag_name_regex"],
            "tagCategoryNameRegex": config.config["tag_category_name_regex"],
            "defaultUserRank": config.config["default_rank"],
            "enableSafety": config.config["enable_safety"],
            "contactEmail": config.config["contact_email"],
            "canSendMails": bool(config.config["smtp"]["host"]),
            "privileges": util.snake_case_to_lower_camel_case_keys(
                config.config["privileges"]
            ),
        },
    }
    if auth.has_privilege(ctx.user, "posts:view:featured"):
        ret["featuredPost"] = (
            posts.serialize_post(post_feature.post, ctx.user)
            if post_feature
            else None
        )
        ret["featuringUser"] = (
            users.serialize_user(post_feature.user, ctx.user)
            if post_feature
            else None
        )
        ret["featuringTime"] = post_feature.time if post_feature else None
    return ret
コード例 #8
0
ファイル: info_api.py プロジェクト: rr-/szurubooru
def get_info(
        ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
    post_feature = posts.try_get_current_post_feature()
    ret = {
        'postCount': posts.get_post_count(),
        'diskUsage': _get_disk_usage(),
        'serverTime': datetime.utcnow(),
        'config': {
            'name': config.config['name'],
            'userNameRegex': config.config['user_name_regex'],
            'passwordRegex': config.config['password_regex'],
            'tagNameRegex': config.config['tag_name_regex'],
            'tagCategoryNameRegex': config.config['tag_category_name_regex'],
            'defaultUserRank': config.config['default_rank'],
            'enableSafety': config.config['enable_safety'],
            'contactEmail': config.config['contact_email'],
            'canSendMails': bool(config.config['smtp']['host']),
            'privileges':
                util.snake_case_to_lower_camel_case_keys(
                    config.config['privileges']),
        },
    }
    if auth.has_privilege(ctx.user, 'posts:view:featured'):
        ret['featuredPost'] = (
            posts.serialize_post(post_feature.post, ctx.user)
            if post_feature else None)
        ret['featuringUser'] = (
            users.serialize_user(post_feature.user, ctx.user)
            if post_feature else None)
        ret['featuringTime'] = post_feature.time if post_feature else None
    return ret
コード例 #9
0
 def get(self, ctx):
     featured_post = posts.try_get_featured_post()
     return {
         'postCount': posts.get_post_count(),
         'diskUsage': self._get_disk_usage(),
         'featuredPost': posts.serialize_post(featured_post, ctx.user),
     }
コード例 #10
0
def get_info(ctx, _params=None):
    post_feature = posts.try_get_current_post_feature()
    return {
        'postCount': posts.get_post_count(),
        'diskUsage': _get_disk_usage(),
        'featuredPost':
            posts.serialize_post(post_feature.post, ctx.user)
                if post_feature else None,
        'featuringTime': post_feature.time if post_feature else None,
        'featuringUser':
            users.serialize_user(post_feature.user, ctx.user)
                if post_feature else None,
        'serverTime': datetime.datetime.utcnow(),
        'config': {
            'userNameRegex': config.config['user_name_regex'],
            'passwordRegex': config.config['password_regex'],
            'tagNameRegex': config.config['tag_name_regex'],
            'tagCategoryNameRegex': config.config['tag_category_name_regex'],
            'defaultUserRank': config.config['default_rank'],
            'privileges':
                util.snake_case_to_lower_camel_case_keys(
                    config.config['privileges']),
        },
    }