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

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

View file

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

View file

@ -54,7 +54,10 @@ class Image:
): ):
duration = float(self.info["format"]["duration"]) duration = float(self.info["format"]["duration"])
if duration > 3: 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) content = self._execute(cli, ignore_error_if_data=True)
if not content: if not content:
raise errors.ProcessingError("Error while resizing image.") 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 []: for webhook in config.config["webhooks"] or []:
req = urllib.request.Request(webhook) req = urllib.request.Request(webhook)
req.data = json.dumps( req.data = json.dumps(
payload, default=lambda x: x.isoformat("T") + "Z", payload,
default=lambda x: x.isoformat("T") + "Z",
).encode("utf-8") ).encode("utf-8")
req.add_header("Content-Type", "application/json") req.add_header("Content-Type", "application/json")
try: try:

View file

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

View file

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

View file

@ -13,7 +13,9 @@ def inject_config(config_injector):
"secret": "x", "secret": "x",
"domain": "http://example.com", "domain": "http://example.com",
"name": "Test instance", "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) @pytest.fixture(autouse=True)
def inject_config(config_injector): def inject_config(config_injector):
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) @pytest.fixture(autouse=True)
def inject_config(config_injector): def inject_config(config_injector):
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 user_factory, pool_category_factory, context_factory
): ):
db.session.add_all( 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() db.session.flush()
result = api.pool_category_api.get_pool_categories( 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( @pytest.mark.parametrize(
"params", [{"name": "whatever"}, {"color": "whatever"},] "params",
[
{"name": "whatever"},
{"color": "whatever"},
],
) )
def test_trying_to_update_without_privileges( def test_trying_to_update_without_privileges(
user_factory, pool_category_factory, context_factory, params 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" pool_categories.serialize_category.return_value = "serialized category"
result = api.pool_category_api.set_pool_category_as_default( result = api.pool_category_api.set_pool_category_as_default(
context_factory( context_factory(
params={"name": "changed", "color": "white", "version": 1,}, params={
"name": "changed",
"color": "white",
"version": 1,
},
user=user_factory(rank=model.User.RANK_REGULAR), user=user_factory(rank=model.User.RANK_REGULAR),
), ),
{"category_name": "name"}, {"category_name": "name"},

View file

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

View file

@ -65,7 +65,13 @@ def test_simple_updating(user_factory, pool_factory, context_factory):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"field", ["names", "category", "description", "posts",] "field",
[
"names",
"category",
"description",
"posts",
],
) )
def test_omitting_optional_field( def test_omitting_optional_field(
user_factory, pool_factory, context_factory, 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( @pytest.mark.parametrize(
"params", "params",
[{"names": ["whatever"]}, {"category": "whatever"}, {"posts": [1]},], [
{"names": ["whatever"]},
{"category": "whatever"},
{"posts": [1]},
],
) )
def test_trying_to_update_without_privileges( def test_trying_to_update_without_privileges(
user_factory, pool_factory, context_factory, params 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( result = api.post_api.create_post(
context_factory( context_factory(
params={"safety": "safe", "tags": ["tag1", "tag2"],}, params={
"safety": "safe",
"tags": ["tag1", "tag2"],
},
files={ files={
"content": "post-content", "content": "post-content",
"thumbnail": "post-thumbnail", "thumbnail": "post-thumbnail",
@ -109,7 +112,9 @@ def test_creating_full_posts(context_factory, post_factory, user_factory):
"notes": ["note1", "note2"], "notes": ["note1", "note2"],
"flags": ["flag1", "flag2"], "flags": ["flag1", "flag2"],
}, },
files={"content": "post-content",}, files={
"content": "post-content",
},
user=auth_user, user=auth_user,
) )
) )
@ -162,7 +167,9 @@ def test_anonymous_uploads(
"tags": ["tag1", "tag2"], "tags": ["tag1", "tag2"],
"anonymous": "True", "anonymous": "True",
}, },
files={"content": "post-content",}, files={
"content": "post-content",
},
user=auth_user, user=auth_user,
) )
) )
@ -327,7 +334,10 @@ def test_errors_not_spending_ids(
{ {
"data_dir": str(tmpdir.mkdir("data")), "data_dir": str(tmpdir.mkdir("data")),
"data_url": "example.com", "data_url": "example.com",
"thumbnails": {"post_width": 300, "post_height": 300,}, "thumbnails": {
"post_width": 300,
"post_height": 300,
},
"privileges": { "privileges": {
"posts:create:identified": model.User.RANK_REGULAR, "posts:create:identified": model.User.RANK_REGULAR,
"uploads:use_downloader": model.User.RANK_POWER, "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): with pytest.raises(errors.MissingRequiredFileError):
api.post_api.create_post( api.post_api.create_post(
context_factory( context_factory(
params={"safety": "safe", "tags": ["tag1", "tag2"],}, params={
"safety": "safe",
"tags": ["tag1", "tag2"],
},
user=user_factory(rank=model.User.RANK_REGULAR), 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"] posts.update_post_tags.return_value = ["new-tag"]
api.post_api.create_post( api.post_api.create_post(
context_factory( context_factory(
params={"safety": "safe", "tags": ["tag1", "tag2"],}, params={
files={"content": posts.EMPTY_PIXEL,}, "safety": "safe",
"tags": ["tag1", "tag2"],
},
files={
"content": posts.EMPTY_PIXEL,
},
user=user_factory(rank=model.User.RANK_REGULAR), 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 user_factory, context_factory, config_injector
): ):
config_injector( config_injector(
{"privileges": {"posts:list": "anonymous"},} {
"privileges": {"posts:list": "anonymous"},
}
) )
with pytest.raises(errors.SearchError): with pytest.raises(errors.SearchError):
api.post_api.get_posts( api.post_api.get_posts(

View file

@ -19,7 +19,9 @@ def snapshot_factory():
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def inject_config(config_injector): def inject_config(config_injector):
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) @pytest.fixture(autouse=True)
def inject_config(config_injector): def inject_config(config_injector):
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) @pytest.fixture(autouse=True)
def inject_config(config_injector): def inject_config(config_injector):
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 user_factory, tag_category_factory, context_factory
): ):
db.session.add_all( 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() db.session.flush()
result = api.tag_category_api.get_tag_categories( 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( @pytest.mark.parametrize(
"params", [{"name": "whatever"}, {"color": "whatever"},] "params",
[
{"name": "whatever"},
{"color": "whatever"},
],
) )
def test_trying_to_update_without_privileges( def test_trying_to_update_without_privileges(
user_factory, tag_category_factory, context_factory, params 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" tag_categories.serialize_category.return_value = "serialized category"
result = api.tag_category_api.set_tag_category_as_default( result = api.tag_category_api.set_tag_category_as_default(
context_factory( context_factory(
params={"name": "changed", "color": "white", "version": 1,}, params={
"name": "changed",
"color": "white",
"version": 1,
},
user=user_factory(rank=model.User.RANK_REGULAR), user=user_factory(rank=model.User.RANK_REGULAR),
), ),
{"category_name": "name"}, {"category_name": "name"},

View file

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

View file

@ -31,8 +31,14 @@ def test_get_tag_siblings(user_factory, tag_factory, context_factory):
) )
assert result == { assert result == {
"results": [ "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( @pytest.mark.parametrize(
"field", "field",
["names", "category", "description", "implications", "suggestions",], [
"names",
"category",
"description",
"implications",
"suggestions",
],
) )
def test_omitting_optional_field( def test_omitting_optional_field(
user_factory, tag_factory, context_factory, 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 user_tokens.get_by_user_and_token.return_value = user_token
result = api.user_token_api.update_user_token( result = api.user_token_api.update_user_token(
context_factory( context_factory(
params={"version": user_token.version, "enabled": False,}, params={
"version": user_token.version,
"enabled": False,
},
user=user_token.user, user=user_token.user,
), ),
{ {

View file

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

View file

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

View file

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

View file

@ -88,7 +88,10 @@ def test_is_image(input_mime_type, expected_state):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"input_path,expected_state", "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): def test_is_animated_gif(read_asset, input_path, expected_state):
assert mime.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( @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): def test_too_large_download(url):
pytest.xfail("Download limit not implemented yet") pytest.xfail("Download limit not implemented yet")

View file

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

View file

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

View file

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

View file

@ -58,13 +58,33 @@ def test_filter_anonymous(
( (
None, None,
"--", "--",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",], [
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
), ),
(None, "\\--", []), (None, "\\--", []),
( (
None, None,
"-\\-", "-\\-",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",], [
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
), ),
(None, "-*", []), (None, "-*", []),
(None, "\\-*", ["-", "-asd"]), (None, "\\-*", ["-", "-asd"]),
@ -370,7 +390,10 @@ def test_sort_by_last_edit_time(
@pytest.mark.parametrize( @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( def test_sort_by_post_count(
verify_unpaged, pool_factory, post_factory, input, expected_pool_names verify_unpaged, pool_factory, post_factory, input, expected_pool_names
@ -388,7 +411,10 @@ def test_sort_by_post_count(
@pytest.mark.parametrize( @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( def test_sort_by_category(
verify_unpaged, verify_unpaged,

View file

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

View file

@ -58,13 +58,33 @@ def test_filter_anonymous(
( (
None, None,
"--", "--",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",], [
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
), ),
(None, "\\--", []), (None, "\\--", []),
( (
None, None,
"-\\-", "-\\-",
["t1", "t2", "*", "*asd*", ":", "asd:asd", "\\", "\\asd", "-asd",], [
"t1",
"t2",
"*",
"*asd*",
":",
"asd:asd",
"\\",
"\\asd",
"-asd",
],
), ),
(None, "-*", []), (None, "-*", []),
(None, "\\-*", ["-", "-asd"]), (None, "\\-*", ["-", "-asd"]),
@ -442,7 +462,9 @@ def test_sort_by_post_count(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"input,expected_tag_names", "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( def test_sort_by_suggestion_count(
verify_unpaged, tag_factory, input, expected_tag_names verify_unpaged, tag_factory, input, expected_tag_names
@ -462,7 +484,9 @@ def test_sort_by_suggestion_count(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"input,expected_tag_names", "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( def test_sort_by_implication_count(
verify_unpaged, tag_factory, input, expected_tag_names verify_unpaged, tag_factory, input, expected_tag_names
@ -481,7 +505,10 @@ def test_sort_by_implication_count(
@pytest.mark.parametrize( @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( def test_sort_by_category(
verify_unpaged, verify_unpaged,