diff --git a/client/docker-start.sh b/client/docker-start.sh index ff72da2..0b2bec8 100755 --- a/client/docker-start.sh +++ b/client/docker-start.sh @@ -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 diff --git a/client/hooks/build b/client/hooks/build index ee588f6..46443f4 100755 --- a/client/hooks/build +++ b/client/hooks/build @@ -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 . diff --git a/client/hooks/post_push b/client/hooks/post_push index 81fc86c..1b1e0ad 100755 --- a/client/hooks/post_push +++ b/client/hooks/post_push @@ -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 diff --git a/doc/developer-utils/create-alembic-migration.sh b/doc/developer-utils/create-alembic-migration.sh index 1e884a3..df7a29e 100755 --- a/doc/developer-utils/create-alembic-migration.sh +++ b/doc/developer-utils/create-alembic-migration.sh @@ -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 diff --git a/server/Dockerfile b/server/Dockerfile index 17c174c..9a597a1 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -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 \ diff --git a/server/hooks/build b/server/hooks/build index fea6b42..b5e914b 100755 --- a/server/hooks/build +++ b/server/hooks/build @@ -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 . diff --git a/server/hooks/post_push b/server/hooks/post_push index 81fc86c..1b1e0ad 100755 --- a/server/hooks/post_push +++ b/server/hooks/post_push @@ -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 diff --git a/server/hooks/test b/server/hooks/test index 377139c..b325186 100755 --- a/server/hooks/test +++ b/server/hooks/test @@ -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 $? diff --git a/server/szuru-admin b/server/szuru-admin index 7abc69c..004a751 100755 --- a/server/szuru-admin +++ b/server/szuru-admin @@ -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='', - 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="", + 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() diff --git a/server/szurubooru/api/post_api.py b/server/szurubooru/api/post_api.py index bf40bc0..daba7f7 100644 --- a/server/szurubooru/api/post_api.py +++ b/server/szurubooru/api/post_api.py @@ -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 ], } diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py index 440fc06..6413ac8 100644 --- a/server/szurubooru/func/images.py +++ b/server/szurubooru/func/images.py @@ -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.") diff --git a/server/szurubooru/func/net.py b/server/szurubooru/func/net.py index bb43ddd..caa3fba 100644 --- a/server/szurubooru/func/net.py +++ b/server/szurubooru/func/net.py @@ -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: diff --git a/server/szurubooru/tests/api/test_comment_creating.py b/server/szurubooru/tests/api/test_comment_creating.py index 3f9479b..b16ce65 100644 --- a/server/szurubooru/tests/api/test_comment_creating.py +++ b/server/szurubooru/tests/api/test_comment_creating.py @@ -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 diff --git a/server/szurubooru/tests/api/test_info.py b/server/szurubooru/tests/api/test_info.py index 57bf7a3..37099e8 100644 --- a/server/szurubooru/tests/api/test_info.py +++ b/server/szurubooru/tests/api/test_info.py @@ -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()]) diff --git a/server/szurubooru/tests/api/test_password_reset.py b/server/szurubooru/tests/api/test_password_reset.py index 28e4c12..bf1ab5c 100644 --- a/server/szurubooru/tests/api/test_password_reset.py +++ b/server/szurubooru/tests/api/test_password_reset.py @@ -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", + }, } ) diff --git a/server/szurubooru/tests/api/test_pool_category_creating.py b/server/szurubooru/tests/api/test_pool_category_creating.py index c13c1ec..b9235d0 100644 --- a/server/szurubooru/tests/api/test_pool_category_creating.py +++ b/server/szurubooru/tests/api/test_pool_category_creating.py @@ -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}, + } ) diff --git a/server/szurubooru/tests/api/test_pool_category_deleting.py b/server/szurubooru/tests/api/test_pool_category_deleting.py index cdbdcfe..b50f961 100644 --- a/server/szurubooru/tests/api/test_pool_category_deleting.py +++ b/server/szurubooru/tests/api/test_pool_category_deleting.py @@ -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}, + } ) diff --git a/server/szurubooru/tests/api/test_pool_category_retrieving.py b/server/szurubooru/tests/api/test_pool_category_retrieving.py index ea837c4..7820567 100644 --- a/server/szurubooru/tests/api/test_pool_category_retrieving.py +++ b/server/szurubooru/tests/api/test_pool_category_retrieving.py @@ -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( diff --git a/server/szurubooru/tests/api/test_pool_category_updating.py b/server/szurubooru/tests/api/test_pool_category_updating.py index c13112f..5e26209 100644 --- a/server/szurubooru/tests/api/test_pool_category_updating.py +++ b/server/szurubooru/tests/api/test_pool_category_updating.py @@ -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"}, diff --git a/server/szurubooru/tests/api/test_pool_merging.py b/server/szurubooru/tests/api/test_pool_merging.py index d0e5532..3357780 100644 --- a/server/szurubooru/tests/api/test_pool_merging.py +++ b/server/szurubooru/tests/api/test_pool_merging.py @@ -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): diff --git a/server/szurubooru/tests/api/test_pool_updating.py b/server/szurubooru/tests/api/test_pool_updating.py index aa2c09a..507289f 100644 --- a/server/szurubooru/tests/api/test_pool_updating.py +++ b/server/szurubooru/tests/api/test_pool_updating.py @@ -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 diff --git a/server/szurubooru/tests/api/test_post_creating.py b/server/szurubooru/tests/api/test_post_creating.py index e2db0eb..a1ad4de 100644 --- a/server/szurubooru/tests/api/test_post_creating.py +++ b/server/szurubooru/tests/api/test_post_creating.py @@ -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), ) ) diff --git a/server/szurubooru/tests/api/test_post_retrieving.py b/server/szurubooru/tests/api/test_post_retrieving.py index 8f2c371..ac984c2 100644 --- a/server/szurubooru/tests/api/test_post_retrieving.py +++ b/server/szurubooru/tests/api/test_post_retrieving.py @@ -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( diff --git a/server/szurubooru/tests/api/test_snapshot_retrieving.py b/server/szurubooru/tests/api/test_snapshot_retrieving.py index ec24e82..ea59d77 100644 --- a/server/szurubooru/tests/api/test_snapshot_retrieving.py +++ b/server/szurubooru/tests/api/test_snapshot_retrieving.py @@ -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}, + } ) diff --git a/server/szurubooru/tests/api/test_tag_category_creating.py b/server/szurubooru/tests/api/test_tag_category_creating.py index 78f3068..2370cb8 100644 --- a/server/szurubooru/tests/api/test_tag_category_creating.py +++ b/server/szurubooru/tests/api/test_tag_category_creating.py @@ -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}, + } ) diff --git a/server/szurubooru/tests/api/test_tag_category_deleting.py b/server/szurubooru/tests/api/test_tag_category_deleting.py index 2e6be64..23a3a42 100644 --- a/server/szurubooru/tests/api/test_tag_category_deleting.py +++ b/server/szurubooru/tests/api/test_tag_category_deleting.py @@ -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}, + } ) diff --git a/server/szurubooru/tests/api/test_tag_category_retrieving.py b/server/szurubooru/tests/api/test_tag_category_retrieving.py index 9c2c6fb..40d9059 100644 --- a/server/szurubooru/tests/api/test_tag_category_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_category_retrieving.py @@ -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( diff --git a/server/szurubooru/tests/api/test_tag_category_updating.py b/server/szurubooru/tests/api/test_tag_category_updating.py index 6c32737..4134613 100644 --- a/server/szurubooru/tests/api/test_tag_category_updating.py +++ b/server/szurubooru/tests/api/test_tag_category_updating.py @@ -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"}, diff --git a/server/szurubooru/tests/api/test_tag_merging.py b/server/szurubooru/tests/api/test_tag_merging.py index be7e887..84c13d3 100644 --- a/server/szurubooru/tests/api/test_tag_merging.py +++ b/server/szurubooru/tests/api/test_tag_merging.py @@ -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): diff --git a/server/szurubooru/tests/api/test_tag_siblings_retrieving.py b/server/szurubooru/tests/api/test_tag_siblings_retrieving.py index 26f6666..7453b98 100644 --- a/server/szurubooru/tests/api/test_tag_siblings_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_siblings_retrieving.py @@ -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, + }, ], } diff --git a/server/szurubooru/tests/api/test_tag_updating.py b/server/szurubooru/tests/api/test_tag_updating.py index e2b0e00..729734d 100644 --- a/server/szurubooru/tests/api/test_tag_updating.py +++ b/server/szurubooru/tests/api/test_tag_updating.py @@ -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 diff --git a/server/szurubooru/tests/api/test_user_token_updating.py b/server/szurubooru/tests/api/test_user_token_updating.py index 6bc5e11..3f66041 100644 --- a/server/szurubooru/tests/api/test_user_token_updating.py +++ b/server/szurubooru/tests/api/test_user_token_updating.py @@ -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, ), { diff --git a/server/szurubooru/tests/api/test_user_updating.py b/server/szurubooru/tests/api/test_user_updating.py index 08ccc78..304e489 100644 --- a/server/szurubooru/tests/api/test_user_updating.py +++ b/server/szurubooru/tests/api/test_user_updating.py @@ -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"}, diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index 6e127bc..481d884 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -33,6 +33,7 @@ def fake_datetime(): def query_logger(pytestconfig): if pytestconfig.option.verbose > 0: import logging + import coloredlogs coloredlogs.install( diff --git a/server/szurubooru/tests/func/test_diff.py b/server/szurubooru/tests/func/test_diff.py index 5ea5780..5e415b5 100644 --- a/server/szurubooru/tests/func/test_diff.py +++ b/server/szurubooru/tests/func/test_diff.py @@ -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"}, diff --git a/server/szurubooru/tests/func/test_mime.py b/server/szurubooru/tests/func/test_mime.py index 4eb9b16..0d8f645 100644 --- a/server/szurubooru/tests/func/test_mime.py +++ b/server/szurubooru/tests/func/test_mime.py @@ -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 diff --git a/server/szurubooru/tests/func/test_net.py b/server/szurubooru/tests/func/test_net.py index 8539a34..af53521 100644 --- a/server/szurubooru/tests/func/test_net.py +++ b/server/szurubooru/tests/func/test_net.py @@ -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") diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index acedf6f..d088b9b 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -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", } ) diff --git a/server/szurubooru/tests/model/test_user.py b/server/szurubooru/tests/model/test_user.py index 20279a0..adc9dd7 100644 --- a/server/szurubooru/tests/model/test_user.py +++ b/server/szurubooru/tests/model/test_user.py @@ -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) diff --git a/server/szurubooru/tests/search/configs/test_comment_search_config.py b/server/szurubooru/tests/search/configs/test_comment_search_config.py index a592b30..d986c22 100644 --- a/server/szurubooru/tests/search/configs/test_comment_search_config.py +++ b/server/szurubooru/tests/search/configs/test_comment_search_config.py @@ -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 diff --git a/server/szurubooru/tests/search/configs/test_pool_search_config.py b/server/szurubooru/tests/search/configs/test_pool_search_config.py index 201bf79..202635c 100644 --- a/server/szurubooru/tests/search/configs/test_pool_search_config.py +++ b/server/szurubooru/tests/search/configs/test_pool_search_config.py @@ -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, diff --git a/server/szurubooru/tests/search/configs/test_post_search_config.py b/server/szurubooru/tests/search/configs/test_post_search_config.py index 172d1ff..4fb8191 100644 --- a/server/szurubooru/tests/search/configs/test_post_search_config.py +++ b/server/szurubooru/tests/search/configs/test_post_search_config.py @@ -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) diff --git a/server/szurubooru/tests/search/configs/test_tag_search_config.py b/server/szurubooru/tests/search/configs/test_tag_search_config.py index 2ba1b9b..8175b73 100644 --- a/server/szurubooru/tests/search/configs/test_tag_search_config.py +++ b/server/szurubooru/tests/search/configs/test_tag_search_config.py @@ -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,