client+server: fix linter issues due to updated pre-commit hooks

This commit is contained in:
Shyam Sunder 2020-09-01 14:06:22 -04:00
parent 67a5dd7c18
commit 0dd427755b
43 changed files with 422 additions and 143 deletions

View file

@ -2,10 +2,10 @@
# Integrate environment variables
sed -i "s|__BACKEND__|${BACKEND_HOST}|" \
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf
sed -i "s|__BASEURL__|${BASE_URL:-/}|g" \
/var/www/index.htm \
/var/www/manifest.json
/var/www/index.htm \
/var/www/manifest.json
# Start server
exec nginx

View file

@ -2,15 +2,15 @@
CLOSEST_VER=$(git describe --tags --abbrev=0 ${SOURCE_COMMIT})
if git describe --exact-match --abbrev=0 ${SOURCE_COMMIT} 2> /dev/null; then
BUILD_INFO="v${CLOSEST_VER}"
BUILD_INFO="v${CLOSEST_VER}"
else
BUILD_INFO="v${CLOSEST_VER}-edge-$(git rev-parse --short ${SOURCE_COMMIT})"
BUILD_INFO="v${CLOSEST_VER}-edge-$(git rev-parse --short ${SOURCE_COMMIT})"
fi
echo "Using BUILD_INFO=${BUILD_INFO}"
docker build \
--build-arg BUILD_INFO=${BUILD_INFO} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg SOURCE_COMMIT \
--build-arg DOCKER_REPO \
-f $DOCKERFILE_PATH -t $IMAGE_NAME .
--build-arg BUILD_INFO=${BUILD_INFO} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg SOURCE_COMMIT \
--build-arg DOCKER_REPO \
-f $DOCKERFILE_PATH -t $IMAGE_NAME .

View file

@ -14,6 +14,6 @@ add_tag "${CLOSEST_MAJOR_VER}-edge"
add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}-edge"
if git describe --exact-match --abbrev=0 2> /dev/null; then
add_tag "${CLOSEST_MAJOR_VER}"
add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}"
add_tag "${CLOSEST_MAJOR_VER}"
add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}"
fi

View file

@ -14,15 +14,15 @@ CONTAINER=$(docker run -d ${IMAGE} tail -f /dev/null)
# Create the migration script
docker exec -i \
-e PYTHONPATH='/opt/app' \
-e POSTGRES_HOST='x' \
-e POSTGRES_USER='x' \
-e POSTGRES_PASSWORD='x' \
${CONTAINER} alembic revision -m "$1"
-e PYTHONPATH='/opt/app' \
-e POSTGRES_HOST='x' \
-e POSTGRES_USER='x' \
-e POSTGRES_PASSWORD='x' \
${CONTAINER} alembic revision -m "$1"
# Copy the file over from the container
docker cp ${CONTAINER}:/opt/app/szurubooru/migrations/versions/ \
"${WORKDIR}/szurubooru/migrations/"
"${WORKDIR}/szurubooru/migrations/"
# Destroy the dummy container
docker rm -f ${CONTAINER} > /dev/null

View file

@ -32,13 +32,13 @@ FROM prereqs as testing
WORKDIR /opt/app
RUN apk --no-cache add \
py3-pip \
py3-pytest \
py3-pip \
py3-pytest \
py3-pytest-cov \
postgresql \
&& pip3 install --no-cache-dir --disable-pip-version-check \
pytest-pgsql \
freezegun \
pytest-pgsql \
freezegun \
&& apk --no-cache del py3-pip \
&& addgroup app \
&& adduser -SDH -h /opt/app -g '' -G app app \
@ -59,9 +59,9 @@ ARG PUID=1000
ARG PGID=1000
RUN apk --no-cache add \
dumb-init \
py3-setuptools \
py3-waitress \
dumb-init \
py3-setuptools \
py3-waitress \
&& mkdir -p /opt/app /data \
&& addgroup -g ${PGID} app \
&& adduser -SDH -h /opt/app -g '' -G app -u ${PUID} app \

View file

@ -1,7 +1,7 @@
#!/bin/sh
docker build \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg SOURCE_COMMIT \
--build-arg DOCKER_REPO \
-f $DOCKERFILE_PATH -t $IMAGE_NAME .
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg SOURCE_COMMIT \
--build-arg DOCKER_REPO \
-f $DOCKERFILE_PATH -t $IMAGE_NAME .

View file

@ -14,6 +14,6 @@ add_tag "${CLOSEST_MAJOR_VER}-edge"
add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}-edge"
if git describe --exact-match --abbrev=0 2> /dev/null; then
add_tag "${CLOSEST_MAJOR_VER}"
add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}"
add_tag "${CLOSEST_MAJOR_VER}"
add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}"
fi

View file

@ -2,7 +2,7 @@
set -e
docker run --rm \
-t $(docker build --target testing -q .) \
--color=no szurubooru/
-t $(docker build --target testing -q .) \
--color=no szurubooru/
exit $?

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python3
'''
"""
Collection of CLI commands for an administrator to use
'''
"""
import logging
import os
@ -21,43 +21,46 @@ from szurubooru.func import users as userfuncs
def reset_password(username: str) -> None:
user = userfuncs.get_user_by_name_or_email(username)
new_password = getpass('Enter new password for \'%s\': ' % user.name)
check_password = getpass('Re-enter password: ')
new_password = getpass("Enter new password for '%s': " % user.name)
check_password = getpass("Re-enter password: ")
if check_password != new_password:
raise errors.ValidationError('Passwords do not match')
raise errors.ValidationError("Passwords do not match")
userfuncs.update_user_password(user, new_password)
db.get_session().commit()
print('Sucessfully changed password for \'%s\'' % user.name)
print("Sucessfully changed password for '%s'" % user.name)
def check_audio() -> None:
post_list = (db.session
.query(model.Post)
.filter(model.Post.type == model.Post.TYPE_VIDEO)
.order_by(model.Post.post_id)
.all())
post_list = (
db.session.query(model.Post)
.filter(model.Post.type == model.Post.TYPE_VIDEO)
.order_by(model.Post.post_id)
.all()
)
for post in post_list:
print('Checking post %d ...' % post.post_id, end='\r')
print("Checking post %d ..." % post.post_id, end="\r", file=stderr)
content = files.get(postfuncs.get_post_content_path(post))
has_existing_flag = model.Post.FLAG_SOUND in post.flags
try:
has_sound_data = images.Image(content).check_for_sound()
except errors.ProcessingError:
print('Post %d caused an error when checking for sound' %
post.post_id)
print(
"Post %d caused an error when checking for sound"
% post.post_id
)
if has_sound_data and not has_existing_flag:
print('Post %d has sound data but is not flagged' % post.post_id)
print("Post %d has sound data but is not flagged" % post.post_id)
if not has_sound_data and has_existing_flag:
print('Post %d has no sound data but is flagged' % post.post_id)
print("Post %d has no sound data but is flagged" % post.post_id)
def reset_filenames() -> None:
regex = re.compile(r'(\d+)_[0-9a-f]{16}\.(\S+)')
regex = re.compile(r"(\d+)_[0-9a-f]{16}\.(\S+)")
def convert_to_new_filename(old_name: str) -> str:
matches = regex.match(old_name)
@ -65,37 +68,52 @@ def reset_filenames() -> None:
return None
post_id = int(matches.group(1))
post_ext = matches.group(2)
return '%d_%s.%s' % \
(post_id, postfuncs.get_post_security_hash(post_id), post_ext)
return "%d_%s.%s" % (
post_id,
postfuncs.get_post_security_hash(post_id),
post_ext,
)
def rename_in_dir(dir: str) -> None:
for old_path in os.listdir(config.config['data_dir'] + dir):
for old_path in os.listdir(config.config["data_dir"] + dir):
new_path = convert_to_new_filename(old_path)
if not new_path:
continue
if old_path != new_path:
print('%s -> %s' % (dir + old_path, dir + new_path))
os.rename(config.config['data_dir'] + dir + old_path,
config.config['data_dir'] + dir + new_path)
print("%s -> %s" % (dir + old_path, dir + new_path))
os.rename(
config.config["data_dir"] + dir + old_path,
config.config["data_dir"] + dir + new_path,
)
rename_in_dir('posts/')
rename_in_dir('generated-thumbnails/')
rename_in_dir('posts/custom-thumbnails/')
rename_in_dir("posts/")
rename_in_dir("generated-thumbnails/")
rename_in_dir("posts/custom-thumbnails/")
def main() -> None:
parser_top = ArgumentParser(
description='Collection of CLI commands for an administrator to use',
epilog='Look at README.md for more info')
description="Collection of CLI commands for an administrator to use",
epilog="Look at README.md for more info",
)
parser = parser_top.add_mutually_exclusive_group(required=True)
parser.add_argument('--change-password', metavar='<username>',
help='change the password of specified user')
parser.add_argument('--check-all-audio', action='store_true',
help='check the audio flags of all posts, '
'noting discrepancies, without modifying posts')
parser.add_argument('--reset-filenames', action='store_true',
help='reset and rename the content and thumbnail '
'filenames in case of a lost/changed secret key')
parser.add_argument(
"--change-password",
metavar="<username>",
help="change the password of specified user",
)
parser.add_argument(
"--check-all-audio",
action="store_true",
help="check the audio flags of all posts, "
"noting discrepancies, without modifying posts",
)
parser.add_argument(
"--reset-filenames",
action="store_true",
help="reset and rename the content and thumbnail "
"filenames in case of a lost/changed secret key",
)
command = parser_top.parse_args()
try:
@ -109,5 +127,5 @@ def main() -> None:
print(e, file=stderr)
if __name__ == '__main__':
if __name__ == "__main__":
main()

View file

@ -301,7 +301,10 @@ def get_posts_by_image(
ctx, posts.search_by_image_exact(content)
),
"similarPosts": [
{"distance": distance, "post": _serialize_post(ctx, post),}
{
"distance": distance,
"post": _serialize_post(ctx, post),
}
for distance, post in lookalikes
],
}

View file

@ -54,7 +54,10 @@ class Image:
):
duration = float(self.info["format"]["duration"])
if duration > 3:
cli = ["-ss", "%d" % math.floor(duration * 0.3),] + cli
cli = [
"-ss",
"%d" % math.floor(duration * 0.3),
] + cli
content = self._execute(cli, ignore_error_if_data=True)
if not content:
raise errors.ProcessingError("Error while resizing image.")

View file

@ -68,7 +68,8 @@ def post_to_webhooks(payload: Dict[str, Any]) -> List[int]:
for webhook in config.config["webhooks"] or []:
req = urllib.request.Request(webhook)
req.data = json.dumps(
payload, default=lambda x: x.isoformat("T") + "Z",
payload,
default=lambda x: x.isoformat("T") + "Z",
).encode("utf-8")
req.add_header("Content-Type", "application/json")
try:

View file

@ -40,7 +40,13 @@ def test_creating_comment(
@pytest.mark.parametrize(
"params", [{"text": None}, {"text": ""}, {"text": [None]}, {"text": [""]},]
"params",
[
{"text": None},
{"text": ""},
{"text": [None]},
{"text": [""]},
],
)
def test_trying_to_pass_invalid_params(
user_factory, post_factory, context_factory, params

View file

@ -31,7 +31,9 @@ def test_info_api(
"test_key2": "test_value2",
"posts:view:featured": "regular",
},
"smtp": {"host": "example.com",},
"smtp": {
"host": "example.com",
},
}
)
db.session.add_all([post_factory(), post_factory()])

View file

@ -13,7 +13,9 @@ def inject_config(config_injector):
"secret": "x",
"domain": "http://example.com",
"name": "Test instance",
"smtp": {"from": "noreply@example.com",},
"smtp": {
"from": "noreply@example.com",
},
}
)

View file

@ -13,7 +13,9 @@ def _update_category_name(category, name):
@pytest.fixture(autouse=True)
def inject_config(config_injector):
config_injector(
{"privileges": {"pool_categories:create": model.User.RANK_REGULAR},}
{
"privileges": {"pool_categories:create": model.User.RANK_REGULAR},
}
)

View file

@ -9,7 +9,9 @@ from szurubooru.func import pool_categories, snapshots
@pytest.fixture(autouse=True)
def inject_config(config_injector):
config_injector(
{"privileges": {"pool_categories:delete": model.User.RANK_REGULAR},}
{
"privileges": {"pool_categories:delete": model.User.RANK_REGULAR},
}
)

View file

@ -20,7 +20,10 @@ def test_retrieving_multiple(
user_factory, pool_category_factory, context_factory
):
db.session.add_all(
[pool_category_factory(name="c1"), pool_category_factory(name="c2"),]
[
pool_category_factory(name="c1"),
pool_category_factory(name="c2"),
]
)
db.session.flush()
result = api.pool_category_api.get_pool_categories(

View file

@ -89,7 +89,11 @@ def test_trying_to_update_non_existing(user_factory, context_factory):
@pytest.mark.parametrize(
"params", [{"name": "whatever"}, {"color": "whatever"},]
"params",
[
{"name": "whatever"},
{"color": "whatever"},
],
)
def test_trying_to_update_without_privileges(
user_factory, pool_category_factory, context_factory, params
@ -119,7 +123,11 @@ def test_set_as_default(user_factory, pool_category_factory, context_factory):
pool_categories.serialize_category.return_value = "serialized category"
result = api.pool_category_api.set_pool_category_as_default(
context_factory(
params={"name": "changed", "color": "white", "version": 1,},
params={
"name": "changed",
"color": "white",
"version": 1,
},
user=user_factory(rank=model.User.RANK_REGULAR),
),
{"category_name": "name"},

View file

@ -52,7 +52,10 @@ def test_trying_to_omit_mandatory_field(
user_factory, pool_factory, context_factory, field
):
db.session.add_all(
[pool_factory(id=1), pool_factory(id=2),]
[
pool_factory(id=1),
pool_factory(id=2),
]
)
db.session.commit()
params = {
@ -95,7 +98,10 @@ def test_trying_to_merge_without_privileges(
user_factory, pool_factory, context_factory
):
db.session.add_all(
[pool_factory(id=1), pool_factory(id=2),]
[
pool_factory(id=1),
pool_factory(id=2),
]
)
db.session.commit()
with pytest.raises(errors.AuthError):

View file

@ -65,7 +65,13 @@ def test_simple_updating(user_factory, pool_factory, context_factory):
@pytest.mark.parametrize(
"field", ["names", "category", "description", "posts",]
"field",
[
"names",
"category",
"description",
"posts",
],
)
def test_omitting_optional_field(
user_factory, pool_factory, context_factory, field
@ -106,7 +112,11 @@ def test_trying_to_update_non_existing(user_factory, context_factory):
@pytest.mark.parametrize(
"params",
[{"names": ["whatever"]}, {"category": "whatever"}, {"posts": [1]},],
[
{"names": ["whatever"]},
{"category": "whatever"},
{"posts": [1]},
],
)
def test_trying_to_update_without_privileges(
user_factory, pool_factory, context_factory, params

View file

@ -47,7 +47,10 @@ def test_creating_minimal_posts(context_factory, post_factory, user_factory):
result = api.post_api.create_post(
context_factory(
params={"safety": "safe", "tags": ["tag1", "tag2"],},
params={
"safety": "safe",
"tags": ["tag1", "tag2"],
},
files={
"content": "post-content",
"thumbnail": "post-thumbnail",
@ -109,7 +112,9 @@ def test_creating_full_posts(context_factory, post_factory, user_factory):
"notes": ["note1", "note2"],
"flags": ["flag1", "flag2"],
},
files={"content": "post-content",},
files={
"content": "post-content",
},
user=auth_user,
)
)
@ -162,7 +167,9 @@ def test_anonymous_uploads(
"tags": ["tag1", "tag2"],
"anonymous": "True",
},
files={"content": "post-content",},
files={
"content": "post-content",
},
user=auth_user,
)
)
@ -327,7 +334,10 @@ def test_errors_not_spending_ids(
{
"data_dir": str(tmpdir.mkdir("data")),
"data_url": "example.com",
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"privileges": {
"posts:create:identified": model.User.RANK_REGULAR,
"uploads:use_downloader": model.User.RANK_POWER,
@ -382,7 +392,10 @@ def test_trying_to_omit_content(context_factory, user_factory):
with pytest.raises(errors.MissingRequiredFileError):
api.post_api.create_post(
context_factory(
params={"safety": "safe", "tags": ["tag1", "tag2"],},
params={
"safety": "safe",
"tags": ["tag1", "tag2"],
},
user=user_factory(rank=model.User.RANK_REGULAR),
)
)
@ -419,8 +432,13 @@ def test_trying_to_create_tags_without_privileges(
posts.update_post_tags.return_value = ["new-tag"]
api.post_api.create_post(
context_factory(
params={"safety": "safe", "tags": ["tag1", "tag2"],},
files={"content": posts.EMPTY_PIXEL,},
params={
"safety": "safe",
"tags": ["tag1", "tag2"],
},
files={
"content": posts.EMPTY_PIXEL,
},
user=user_factory(rank=model.User.RANK_REGULAR),
)
)

View file

@ -72,7 +72,9 @@ def test_trying_to_use_special_tokens_without_logging_in(
user_factory, context_factory, config_injector
):
config_injector(
{"privileges": {"posts:list": "anonymous"},}
{
"privileges": {"posts:list": "anonymous"},
}
)
with pytest.raises(errors.SearchError):
api.post_api.get_posts(

View file

@ -19,7 +19,9 @@ def snapshot_factory():
@pytest.fixture(autouse=True)
def inject_config(config_injector):
config_injector(
{"privileges": {"snapshots:list": model.User.RANK_REGULAR},}
{
"privileges": {"snapshots:list": model.User.RANK_REGULAR},
}
)

View file

@ -13,7 +13,9 @@ def _update_category_name(category, name):
@pytest.fixture(autouse=True)
def inject_config(config_injector):
config_injector(
{"privileges": {"tag_categories:create": model.User.RANK_REGULAR},}
{
"privileges": {"tag_categories:create": model.User.RANK_REGULAR},
}
)

View file

@ -9,7 +9,9 @@ from szurubooru.func import snapshots, tag_categories, tags
@pytest.fixture(autouse=True)
def inject_config(config_injector):
config_injector(
{"privileges": {"tag_categories:delete": model.User.RANK_REGULAR},}
{
"privileges": {"tag_categories:delete": model.User.RANK_REGULAR},
}
)

View file

@ -20,7 +20,10 @@ def test_retrieving_multiple(
user_factory, tag_category_factory, context_factory
):
db.session.add_all(
[tag_category_factory(name="c1"), tag_category_factory(name="c2"),]
[
tag_category_factory(name="c1"),
tag_category_factory(name="c2"),
]
)
db.session.flush()
result = api.tag_category_api.get_tag_categories(

View file

@ -87,7 +87,11 @@ def test_trying_to_update_non_existing(user_factory, context_factory):
@pytest.mark.parametrize(
"params", [{"name": "whatever"}, {"color": "whatever"},]
"params",
[
{"name": "whatever"},
{"color": "whatever"},
],
)
def test_trying_to_update_without_privileges(
user_factory, tag_category_factory, context_factory, params
@ -115,7 +119,11 @@ def test_set_as_default(user_factory, tag_category_factory, context_factory):
tag_categories.serialize_category.return_value = "serialized category"
result = api.tag_category_api.set_tag_category_as_default(
context_factory(
params={"name": "changed", "color": "white", "version": 1,},
params={
"name": "changed",
"color": "white",
"version": 1,
},
user=user_factory(rank=model.User.RANK_REGULAR),
),
{"category_name": "name"},

View file

@ -52,7 +52,10 @@ def test_trying_to_omit_mandatory_field(
user_factory, tag_factory, context_factory, field
):
db.session.add_all(
[tag_factory(names=["source"]), tag_factory(names=["target"]),]
[
tag_factory(names=["source"]),
tag_factory(names=["target"]),
]
)
db.session.commit()
params = {
@ -95,7 +98,10 @@ def test_trying_to_merge_without_privileges(
user_factory, tag_factory, context_factory
):
db.session.add_all(
[tag_factory(names=["source"]), tag_factory(names=["target"]),]
[
tag_factory(names=["source"]),
tag_factory(names=["target"]),
]
)
db.session.commit()
with pytest.raises(errors.AuthError):

View file

@ -31,8 +31,14 @@ def test_get_tag_siblings(user_factory, tag_factory, context_factory):
)
assert result == {
"results": [
{"tag": "serialized tag sib1", "occurrences": 1,},
{"tag": "serialized tag sib2", "occurrences": 3,},
{
"tag": "serialized tag sib1",
"occurrences": 1,
},
{
"tag": "serialized tag sib2",
"occurrences": 3,
},
],
}

View file

@ -75,7 +75,13 @@ def test_simple_updating(user_factory, tag_factory, context_factory):
@pytest.mark.parametrize(
"field",
["names", "category", "description", "implications", "suggestions",],
[
"names",
"category",
"description",
"implications",
"suggestions",
],
)
def test_omitting_optional_field(
user_factory, tag_factory, context_factory, field

View file

@ -29,7 +29,10 @@ def test_edit_user_token(user_token_factory, context_factory, fake_datetime):
user_tokens.get_by_user_and_token.return_value = user_token
result = api.user_token_api.update_user_token(
context_factory(
params={"version": user_token.version, "enabled": False,},
params={
"version": user_token.version,
"enabled": False,
},
user=user_token.user,
),
{

View file

@ -55,7 +55,9 @@ def test_updating_user(context_factory, user_factory):
"rank": "moderator",
"avatarStyle": "manual",
},
files={"avatar": b"...",},
files={
"avatar": b"...",
},
user=auth_user,
),
{"user_name": "u1"},

View file

@ -33,6 +33,7 @@ def fake_datetime():
def query_logger(pytestconfig):
if pytestconfig.option.verbose > 0:
import logging
import coloredlogs
coloredlogs.install(

View file

@ -6,7 +6,11 @@ from szurubooru.func import diff
@pytest.mark.parametrize(
"old,new,expected",
[
([], [], None,),
(
[],
[],
None,
),
(
[],
["added"],
@ -17,7 +21,11 @@ from szurubooru.func import diff
[],
{"type": "list change", "added": [], "removed": ["removed"]},
),
(["untouched"], ["untouched"], None,),
(
["untouched"],
["untouched"],
None,
),
(
["untouched"],
["untouched", "added"],
@ -37,7 +45,11 @@ def test_get_list_diff(old, new, expected):
@pytest.mark.parametrize(
"old,new,expected",
[
({}, {}, None,),
(
{},
{},
None,
),
(
{"removed key": "removed value"},
{},
@ -78,7 +90,11 @@ def test_get_list_diff(old, new, expected):
},
},
),
({"key": "untouched"}, {"key": "untouched"}, None,),
(
{"key": "untouched"},
{"key": "untouched"},
None,
),
(
{"key": "untouched", "removed key": "removed value"},
{"key": "untouched"},

View file

@ -88,7 +88,10 @@ def test_is_image(input_mime_type, expected_state):
@pytest.mark.parametrize(
"input_path,expected_state",
[("gif.gif", False), ("gif-animated.gif", True),],
[
("gif.gif", False),
("gif-animated.gif", True),
],
)
def test_is_animated_gif(read_asset, input_path, expected_state):
assert mime.is_animated_gif(read_asset(input_path)) == expected_state

View file

@ -66,7 +66,10 @@ def test_download():
@pytest.mark.parametrize(
"url", ["https://samples.ffmpeg.org/MPEG-4/video.mp4",]
"url",
[
"https://samples.ffmpeg.org/MPEG-4/video.mp4",
],
)
def test_too_large_download(url):
pytest.xfail("Download limit not implemented yet")

View file

@ -232,7 +232,11 @@ def test_serialize_post(
"category": "test-cat1",
"usages": 1,
},
{"names": ["tag3"], "category": "test-cat2", "usages": 1,},
{
"names": ["tag3"],
"category": "test-cat2",
"usages": 1,
},
],
"relations": [],
"notes": [],
@ -452,7 +456,10 @@ def test_update_post_content_for_new_post(
config_injector(
{
"data_dir": str(tmpdir.mkdir("data")),
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
"allow_broken_uploads": False,
}
@ -485,7 +492,10 @@ def test_update_post_content_to_existing_content(
{
"data_dir": str(tmpdir.mkdir("data")),
"data_url": "example.com",
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
"allow_broken_uploads": False,
}
@ -509,7 +519,10 @@ def test_update_post_content_with_broken_content(
config_injector(
{
"data_dir": str(tmpdir.mkdir("data")),
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
"allow_broken_uploads": allow_broken_uploads,
}
@ -533,7 +546,9 @@ def test_update_post_content_with_invalid_content(
config_injector, input_content
):
config_injector(
{"allow_broken_uploads": True,}
{
"allow_broken_uploads": True,
}
)
post = model.Post()
with pytest.raises(posts.InvalidPostContentError):
@ -547,7 +562,10 @@ def test_update_post_thumbnail_to_new_one(
config_injector(
{
"data_dir": str(tmpdir.mkdir("data")),
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
"allow_broken_uploads": False,
}
@ -585,7 +603,10 @@ def test_update_post_thumbnail_to_default(
config_injector(
{
"data_dir": str(tmpdir.mkdir("data")),
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
"allow_broken_uploads": False,
}
@ -622,7 +643,10 @@ def test_update_post_thumbnail_with_broken_thumbnail(
config_injector(
{
"data_dir": str(tmpdir.mkdir("data")),
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
"allow_broken_uploads": False,
}
@ -663,7 +687,10 @@ def test_update_post_content_leaving_custom_thumbnail(
config_injector(
{
"data_dir": str(tmpdir.mkdir("data")),
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
"allow_broken_uploads": False,
}
@ -1084,7 +1111,10 @@ def test_merge_posts_replaces_content(
"data_dir": str(tmpdir.mkdir("data")),
"data_url": "example.com",
"delete_source_files": False,
"thumbnails": {"post_width": 300, "post_height": 300,},
"thumbnails": {
"post_width": 300,
"post_height": 300,
},
"secret": "test",
}
)

View file

@ -45,7 +45,10 @@ def test_comment_count(user_factory, comment_factory):
db.session.flush()
assert user.comment_count == 0
db.session.add_all(
[comment_factory(user=user), comment_factory(),]
[
comment_factory(user=user),
comment_factory(),
]
)
db.session.flush()
db.session.refresh(user)

View file

@ -65,7 +65,11 @@ def test_filter_by_text(
@pytest.mark.parametrize(
"input,expected_comment_text",
[("user:u1", ["t1"]), ("user:u2", ["t2"]), ("user:u1,u2", ["t2", "t1"]),],
[
("user:u1", ["t1"]),
("user:u2", ["t2"]),
("user:u1,u2", ["t2", "t1"]),
],
)
def test_filter_by_user(
verify_unpaged, comment_factory, user_factory, input, expected_comment_text
@ -78,7 +82,11 @@ def test_filter_by_user(
@pytest.mark.parametrize(
"input,expected_comment_text",
[("post:1", ["t1"]), ("post:2", ["t2"]), ("post:1,2", ["t1", "t2"]),],
[
("post:1", ["t1"]),
("post:2", ["t2"]),
("post:1,2", ["t1", "t2"]),
],
)
def test_filter_by_post(
verify_unpaged, comment_factory, post_factory, input, expected_comment_text
@ -108,7 +116,10 @@ def test_anonymous(
@pytest.mark.parametrize(
"input,expected_comment_text", [("sort:user", ["t1", "t2"]),]
"input,expected_comment_text",
[
("sort:user", ["t1", "t2"]),
],
)
def test_sort_by_user(
verify_unpaged, comment_factory, user_factory, input, expected_comment_text
@ -120,7 +131,10 @@ def test_sort_by_user(
@pytest.mark.parametrize(
"input,expected_comment_text", [("sort:post", ["t2", "t1"]),]
"input,expected_comment_text",
[
("sort:post", ["t2", "t1"]),
],
)
def test_sort_by_post(
verify_unpaged, comment_factory, post_factory, input, expected_comment_text

View file

@ -58,13 +58,33 @@ def test_filter_anonymous(
(
None,
"--",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",],
[
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
),
(None, "\\--", []),
(
None,
"-\\-",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",],
[
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
),
(None, "-*", []),
(None, "\\-*", ["-", "-asd"]),
@ -370,7 +390,10 @@ def test_sort_by_last_edit_time(
@pytest.mark.parametrize(
"input,expected_pool_names", [("sort:post-count", ["t2", "t1"]),]
"input,expected_pool_names",
[
("sort:post-count", ["t2", "t1"]),
],
)
def test_sort_by_post_count(
verify_unpaged, pool_factory, post_factory, input, expected_pool_names
@ -388,7 +411,10 @@ def test_sort_by_post_count(
@pytest.mark.parametrize(
"input,expected_pool_names", [("sort:category", ["t3", "t1", "t2"]),]
"input,expected_pool_names",
[
("sort:category", ["t3", "t1", "t2"]),
],
)
def test_sort_by_category(
verify_unpaged,

View file

@ -83,7 +83,11 @@ def verify_unpaged(executor):
@pytest.mark.parametrize(
"input,expected_post_ids",
[("id:1", [1]), ("id:3", [3]), ("id:1,3", [1, 3]),],
[
("id:1", [1]),
("id:3", [3]),
("id:1,3", [1, 3]),
],
)
def test_filter_by_id(verify_unpaged, post_factory, input, expected_post_ids):
post1 = post_factory(id=1)
@ -122,7 +126,11 @@ def test_filter_by_tag(
@pytest.mark.parametrize(
"input,expected_post_ids",
[("score:1", [1]), ("score:3", [3]), ("score:1,3", [1, 3]),],
[
("score:1", [1]),
("score:3", [3]),
("score:1,3", [1, 3]),
],
)
def test_filter_by_score(
verify_unpaged, post_factory, user_factory, input, expected_post_ids
@ -178,7 +186,11 @@ def test_filter_by_uploader(
@pytest.mark.parametrize(
"input,expected_post_ids",
[("comment:u1", [1]), ("comment:u3", [3]), ("comment:u1,u3", [1, 3]),],
[
("comment:u1", [1]),
("comment:u3", [3]),
("comment:u1,u3", [1, 3]),
],
)
def test_filter_by_commenter(
verify_unpaged,
@ -207,7 +219,11 @@ def test_filter_by_commenter(
@pytest.mark.parametrize(
"input,expected_post_ids",
[("fav:u1", [1]), ("fav:u3", [3]), ("fav:u1,u3", [1, 3]),],
[
("fav:u1", [1]),
("fav:u3", [3]),
("fav:u1,u3", [1, 3]),
],
)
def test_filter_by_favorite(
verify_unpaged,
@ -236,7 +252,11 @@ def test_filter_by_favorite(
@pytest.mark.parametrize(
"input,expected_post_ids",
[("tag-count:1", [1]), ("tag-count:3", [3]), ("tag-count:1,3", [1, 3]),],
[
("tag-count:1", [1]),
("tag-count:3", [3]),
("tag-count:1,3", [1, 3]),
],
)
def test_filter_by_tag_count(
verify_unpaged, post_factory, tag_factory, input, expected_post_ids
@ -285,7 +305,11 @@ def test_filter_by_comment_count(
@pytest.mark.parametrize(
"input,expected_post_ids",
[("fav-count:1", [1]), ("fav-count:3", [3]), ("fav-count:1,3", [1, 3]),],
[
("fav-count:1", [1]),
("fav-count:3", [3]),
("fav-count:1,3", [1, 3]),
],
)
def test_filter_by_favorite_count(
verify_unpaged, post_factory, fav_factory, input, expected_post_ids
@ -787,7 +811,13 @@ def test_own_disliked(
verify_unpaged("-special:disliked", [2, 3])
@pytest.mark.parametrize("input", ["liked:x", "disliked:x",])
@pytest.mark.parametrize(
"input",
[
"liked:x",
"disliked:x",
],
)
def test_someones_score(executor, input):
with pytest.raises(errors.SearchError):
executor.execute(input, offset=0, limit=100)

View file

@ -58,13 +58,33 @@ def test_filter_anonymous(
(
None,
"--",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",],
[
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
),
(None, "\\--", []),
(
None,
"-\\-",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",],
[
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
),
(None, "-*", []),
(None, "\\-*", ["-", "-asd"]),
@ -442,7 +462,9 @@ def test_sort_by_post_count(
@pytest.mark.parametrize(
"input,expected_tag_names",
[("sort:suggestion-count", ["t1", "t2", "sug1", "sug2", "sug3"]),],
[
("sort:suggestion-count", ["t1", "t2", "sug1", "sug2", "sug3"]),
],
)
def test_sort_by_suggestion_count(
verify_unpaged, tag_factory, input, expected_tag_names
@ -462,7 +484,9 @@ def test_sort_by_suggestion_count(
@pytest.mark.parametrize(
"input,expected_tag_names",
[("sort:implication-count", ["t1", "t2", "sug1", "sug2", "sug3"]),],
[
("sort:implication-count", ["t1", "t2", "sug1", "sug2", "sug3"]),
],
)
def test_sort_by_implication_count(
verify_unpaged, tag_factory, input, expected_tag_names
@ -481,7 +505,10 @@ def test_sort_by_implication_count(
@pytest.mark.parametrize(
"input,expected_tag_names", [("sort:category", ["t3", "t1", "t2"]),]
"input,expected_tag_names",
[
("sort:category", ["t3", "t1", "t2"]),
],
)
def test_sort_by_category(
verify_unpaged,