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
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
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
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
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
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
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), }
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']), }, }