summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorShyam Sunder <sgsunder1@gmail.com>2020-06-03 11:55:50 -0400
committerShyam Sunder <sgsunder1@gmail.com>2020-06-03 11:55:50 -0400
commitb0f1b8c2309277a7b170972d463b4e8d16a79ecc (patch)
tree564f6f7dd1a2d78f3a00bb4372fb4ca2b95bb6c5 /server
parent1be947e9462edf3bb0a8d15172e0c6e0190e0482 (diff)
fix python lint issues
Diffstat (limited to 'server')
-rw-r--r--server/szurubooru/api/pool_api.py3
-rw-r--r--server/szurubooru/func/pools.py11
-rw-r--r--server/szurubooru/func/posts.py1
-rw-r--r--server/szurubooru/migrations/versions/54de8acc6cef_add_default_pool_category.py1
-rw-r--r--server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py2
-rw-r--r--server/szurubooru/model/pool.py3
-rw-r--r--server/szurubooru/model/pool_category.py3
-rw-r--r--server/szurubooru/tests/api/test_pool_category_creating.py6
-rw-r--r--server/szurubooru/tests/api/test_pool_category_updating.py6
-rw-r--r--server/szurubooru/tests/api/test_pool_updating.py33
-rw-r--r--server/szurubooru/tests/conftest.py3
-rw-r--r--server/szurubooru/tests/func/test_posts.py8
-rw-r--r--server/szurubooru/tests/search/configs/test_pool_search_config.py18
13 files changed, 66 insertions, 32 deletions
diff --git a/server/szurubooru/api/pool_api.py b/server/szurubooru/api/pool_api.py
index 3d4f74c..9627ed2 100644
--- a/server/szurubooru/api/pool_api.py
+++ b/server/szurubooru/api/pool_api.py
@@ -17,7 +17,8 @@ def _get_pool(params: Dict[str, str]) -> model.Pool:
@rest.routes.get('/pools/?')
-def get_pools(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
+def get_pools(
+ ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
auth.verify_privilege(ctx.user, 'pools:list')
return _search_executor.execute_and_serialize(
ctx, lambda pool: _serialize(ctx, pool))
diff --git a/server/szurubooru/func/pools.py b/server/szurubooru/func/pools.py
index 90dede2..4acf9df 100644
--- a/server/szurubooru/func/pools.py
+++ b/server/szurubooru/func/pools.py
@@ -131,8 +131,12 @@ class PoolSerializer(serialization.BaseSerializer):
return self.pool.post_count
def serialize_posts(self) -> Any:
- return [post for post in
- [posts.serialize_micro_post(rel, None) for rel in self.pool.posts]]
+ return [
+ post for post in [
+ posts.serialize_micro_post(rel, None)
+ for rel in self.pool.posts
+ ]
+ ]
def serialize_pool(
@@ -310,7 +314,8 @@ def update_pool_posts(pool: model.Pool, post_ids: List[int]) -> None:
if len(post_ids) != len(ret):
missing = set(post_ids) - set(post.post_id for post in ret)
missing = ', '.join(list(str(x) for x in missing))
- raise InvalidPoolNonexistentPostError('The following posts do not exist: ' + missing)
+ raise InvalidPoolNonexistentPostError(
+ 'The following posts do not exist: ' + missing)
pool.posts.clear()
for post in ret:
pool.posts.append(post)
diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py
index 62458d8..d8e984b 100644
--- a/server/szurubooru/func/posts.py
+++ b/server/szurubooru/func/posts.py
@@ -308,7 +308,6 @@ class PostSerializer(serialization.BaseSerializer):
key=lambda pool: pool.creation_time)]
-
def serialize_post(
post: Optional[model.Post],
auth_user: model.User,
diff --git a/server/szurubooru/migrations/versions/54de8acc6cef_add_default_pool_category.py b/server/szurubooru/migrations/versions/54de8acc6cef_add_default_pool_category.py
index 782833c..eaa68f2 100644
--- a/server/szurubooru/migrations/versions/54de8acc6cef_add_default_pool_category.py
+++ b/server/szurubooru/migrations/versions/54de8acc6cef_add_default_pool_category.py
@@ -33,6 +33,7 @@ class PoolCategory(Base):
'version_id_generator': False,
}
+
def upgrade():
session = sa.orm.session.Session(bind=op.get_bind())
if session.query(PoolCategory).count() == 0:
diff --git a/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py b/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py
index 88472e3..18a0d7a 100644
--- a/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py
+++ b/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py
@@ -14,6 +14,7 @@ down_revision = '1e280b5d5df1'
branch_labels = None
depends_on = None
+
def upgrade():
op.create_table(
'pool_category',
@@ -54,6 +55,7 @@ def upgrade():
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('pool_id', 'post_id'))
+
def downgrade():
op.drop_index(op.f('ix_pool_name_ord'), table_name='pool_name')
op.drop_table('pool_post')
diff --git a/server/szurubooru/model/pool.py b/server/szurubooru/model/pool.py
index 70595d9..6fc8361 100644
--- a/server/szurubooru/model/pool.py
+++ b/server/szurubooru/model/pool.py
@@ -20,7 +20,7 @@ class PoolName(Base):
def __init__(self, name: str, order: int) -> None:
self.name = name
self.order = order
-
+
class PoolPost(Base):
__tablename__ = 'pool_post'
@@ -47,6 +47,7 @@ class PoolPost(Base):
def __init__(self, post) -> None:
self.post_id = post.post_id
+
class Pool(Base):
__tablename__ = 'pool'
diff --git a/server/szurubooru/model/pool_category.py b/server/szurubooru/model/pool_category.py
index 5af0b11..a54e5a6 100644
--- a/server/szurubooru/model/pool_category.py
+++ b/server/szurubooru/model/pool_category.py
@@ -18,7 +18,8 @@ class PoolCategory(Base):
self.name = name
pool_count = sa.orm.column_property(
- sa.sql.expression.select([sa.sql.expression.func.count('Pool.pool_id')])
+ sa.sql.expression.select(
+ [sa.sql.expression.func.count('Pool.pool_id')])
.where(Pool.category_id == pool_category_id)
.correlate_except(sa.table('Pool')))
diff --git a/server/szurubooru/tests/api/test_pool_category_creating.py b/server/szurubooru/tests/api/test_pool_category_creating.py
index 4accb92..5e932a6 100644
--- a/server/szurubooru/tests/api/test_pool_category_creating.py
+++ b/server/szurubooru/tests/api/test_pool_category_creating.py
@@ -26,13 +26,15 @@ def test_creating_category(
patch('szurubooru.func.pool_categories.update_category_name'), \
patch('szurubooru.func.snapshots.create'):
pool_categories.create_category.return_value = category
- pool_categories.update_category_name.side_effect = _update_category_name
+ pool_categories.update_category_name.side_effect = \
+ _update_category_name
pool_categories.serialize_category.return_value = 'serialized category'
result = api.pool_category_api.create_pool_category(
context_factory(
params={'name': 'meta', 'color': 'black'}, user=auth_user))
assert result == 'serialized category'
- pool_categories.create_category.assert_called_once_with('meta', 'black')
+ pool_categories.create_category.assert_called_once_with(
+ 'meta', 'black')
snapshots.create.assert_called_once_with(category, auth_user)
diff --git a/server/szurubooru/tests/api/test_pool_category_updating.py b/server/szurubooru/tests/api/test_pool_category_updating.py
index 9c9f743..028c520 100644
--- a/server/szurubooru/tests/api/test_pool_category_updating.py
+++ b/server/szurubooru/tests/api/test_pool_category_updating.py
@@ -28,7 +28,8 @@ def test_simple_updating(user_factory, pool_category_factory, context_factory):
patch('szurubooru.func.pool_categories.update_category_name'), \
patch('szurubooru.func.pool_categories.update_category_color'), \
patch('szurubooru.func.snapshots.modify'):
- pool_categories.update_category_name.side_effect = _update_category_name
+ pool_categories.update_category_name.side_effect = \
+ _update_category_name
pool_categories.serialize_category.return_value = 'serialized category'
result = api.pool_category_api.update_pool_category(
context_factory(
@@ -93,7 +94,8 @@ def test_set_as_default(user_factory, pool_category_factory, context_factory):
db.session.commit()
with patch('szurubooru.func.pool_categories.serialize_category'), \
patch('szurubooru.func.pool_categories.set_default_category'):
- pool_categories.update_category_name.side_effect = _update_category_name
+ pool_categories.update_category_name.side_effect = \
+ _update_category_name
pool_categories.serialize_category.return_value = 'serialized category'
result = api.pool_category_api.set_pool_category_as_default(
context_factory(
diff --git a/server/szurubooru/tests/api/test_pool_updating.py b/server/szurubooru/tests/api/test_pool_updating.py
index 52eddc9..bd6b71c 100644
--- a/server/szurubooru/tests/api/test_pool_updating.py
+++ b/server/szurubooru/tests/api/test_pool_updating.py
@@ -23,13 +23,13 @@ def test_simple_updating(user_factory, pool_factory, context_factory):
db.session.add(pool)
db.session.commit()
with patch('szurubooru.func.pools.create_pool'), \
- patch('szurubooru.func.posts.get_posts_by_ids'), \
- patch('szurubooru.func.pools.update_pool_names'), \
- patch('szurubooru.func.pools.update_pool_category_name'), \
- patch('szurubooru.func.pools.update_pool_description'), \
- patch('szurubooru.func.pools.update_pool_posts'), \
- patch('szurubooru.func.pools.serialize_pool'), \
- patch('szurubooru.func.snapshots.modify'):
+ patch('szurubooru.func.posts.get_posts_by_ids'), \
+ patch('szurubooru.func.pools.update_pool_names'), \
+ patch('szurubooru.func.pools.update_pool_category_name'), \
+ patch('szurubooru.func.pools.update_pool_description'), \
+ patch('szurubooru.func.pools.update_pool_posts'), \
+ patch('szurubooru.func.pools.serialize_pool'), \
+ patch('szurubooru.func.snapshots.modify'):
posts.get_posts_by_ids.return_value = ([], [])
pools.serialize_pool.return_value = 'serialized pool'
result = api.pool_api.update_pool(
@@ -72,9 +72,9 @@ def test_omitting_optional_field(
}
del params[field]
with patch('szurubooru.func.pools.create_pool'), \
- patch('szurubooru.func.pools.update_pool_names'), \
- patch('szurubooru.func.pools.update_pool_category_name'), \
- patch('szurubooru.func.pools.serialize_pool'):
+ patch('szurubooru.func.pools.update_pool_names'), \
+ patch('szurubooru.func.pools.update_pool_category_name'), \
+ patch('szurubooru.func.pools.serialize_pool'):
api.pool_api.update_pool(
context_factory(
params={**params, **{'version': 1}},
@@ -113,11 +113,14 @@ def test_trying_to_create_pools_without_privileges(
pool = pool_factory(id=1)
db.session.add(pool)
db.session.commit()
- config_injector({'privileges': {
- 'pools:create': model.User.RANK_ADMINISTRATOR,
- 'pools:edit:posts': model.User.RANK_REGULAR,
- },
- 'delete_source_files': False})
+ config_injector(
+ {
+ 'privileges': {
+ 'pools:create': model.User.RANK_ADMINISTRATOR,
+ 'pools:edit:posts': model.User.RANK_REGULAR,
+ },
+ 'delete_source_files': False,
+ })
with patch('szurubooru.func.posts.get_posts_by_ids'):
posts.get_posts_by_ids.return_value = ([], ['new-post'])
with pytest.raises(errors.AuthError):
diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py
index 249df1a..13b1c00 100644
--- a/server/szurubooru/tests/conftest.py
+++ b/server/szurubooru/tests/conftest.py
@@ -214,7 +214,8 @@ def pool_category_factory():
@pytest.fixture
def pool_factory():
- def factory(id=None, names=None, description=None, category=None, time=None):
+ def factory(
+ id=None, names=None, description=None, category=None, time=None):
if not category:
category = model.PoolCategory(get_unique_name())
db.session.add(category)
diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py
index b429491..1fc6d4b 100644
--- a/server/szurubooru/tests/func/test_posts.py
+++ b/server/szurubooru/tests/func/test_posts.py
@@ -212,7 +212,9 @@ def test_serialize_post(
'posts': [
{
'id': 1,
- 'thumbnailUrl': 'http://example.com/generated-thumbnails/1_244c8840887984c4.jpg',
+ 'thumbnailUrl':
+ 'http://example.com/'
+ 'generated-thumbnails/1_244c8840887984c4.jpg',
}
],
'version': 1,
@@ -228,7 +230,9 @@ def test_serialize_post(
'posts': [
{
'id': 1,
- 'thumbnailUrl': 'http://example.com/generated-thumbnails/1_244c8840887984c4.jpg',
+ 'thumbnailUrl':
+ 'http://example.com/'
+ 'generated-thumbnails/1_244c8840887984c4.jpg',
}
],
'version': 1,
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 e013363..730511a 100644
--- a/server/szurubooru/tests/search/configs/test_pool_search_config.py
+++ b/server/szurubooru/tests/search/configs/test_pool_search_config.py
@@ -222,7 +222,11 @@ def test_filter_by_edit_time(
('post-count-max:1', ['t2']),
])
def test_filter_by_post_count(
- verify_unpaged, pool_factory, post_factory, input, expected_pool_names):
+ verify_unpaged,
+ pool_factory,
+ post_factory,
+ input,
+ expected_pool_names):
post1 = post_factory(id=1)
post2 = post_factory(id=2)
pool1 = pool_factory(id=1, names=['t1'])
@@ -257,7 +261,11 @@ def test_filter_by_invalid_input(executor, input):
('-sort:name,asc', ['t2', 't1']),
('-sort:name,desc', ['t1', 't2']),
])
-def test_sort_by_name(verify_unpaged, pool_factory, input, expected_pool_names):
+def test_sort_by_name(
+ verify_unpaged,
+ pool_factory,
+ input,
+ expected_pool_names):
db.session.add(pool_factory(id=2, names=['t2']))
db.session.add(pool_factory(id=1, names=['t1']))
db.session.flush()
@@ -306,7 +314,11 @@ def test_sort_by_last_edit_time(
('sort:post-count', ['t2', 't1']),
])
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):
post1 = post_factory(id=1)
post2 = post_factory(id=2)
pool1 = pool_factory(id=1, names=['t1'])