diff options
| author | Shyam Sunder | 2020-08-13 19:14:14 -0400 |
|---|---|---|
| committer | Shyam Sunder | 2020-08-13 22:41:43 -0400 |
| commit | 4595f9a2aa1d39f815a62cff2328bc61b0f1a9ed (patch) | |
| tree | 05e38146d72863d75e20b91e4588d55f54a446a6 /server/szurubooru/tests/api | |
| parent | b74492974df42cc40be0221b7d08ffa0819dba46 (diff) | |
server: API support for webhooks
Closes #339
Diffstat (limited to 'server/szurubooru/tests/api')
8 files changed, 42 insertions, 30 deletions
diff --git a/server/szurubooru/tests/api/test_pool_category_updating.py b/server/szurubooru/tests/api/test_pool_category_updating.py index d934e60..c13112f 100644 --- a/server/szurubooru/tests/api/test_pool_category_updating.py +++ b/server/szurubooru/tests/api/test_pool_category_updating.py @@ -67,7 +67,7 @@ def test_omitting_optional_field( del params[field] with patch("szurubooru.func.pool_categories.serialize_category"), patch( "szurubooru.func.pool_categories.update_category_name" - ): + ), patch("szurubooru.func.snapshots._post_to_webhooks"): api.pool_category_api.update_pool_category( context_factory( params={**params, **{"version": 1}}, diff --git a/server/szurubooru/tests/api/test_pool_creating.py b/server/szurubooru/tests/api/test_pool_creating.py index a9f1473..4fd8939 100644 --- a/server/szurubooru/tests/api/test_pool_creating.py +++ b/server/szurubooru/tests/api/test_pool_creating.py @@ -70,7 +70,7 @@ def test_omitting_optional_field( del params[field] with patch("szurubooru.func.pools.create_pool"), patch( "szurubooru.func.pools.serialize_pool" - ): + ), patch("szurubooru.func.snapshots._post_to_webhooks"): pools.create_pool.return_value = pool_factory() api.pool_api.create_pool( context_factory( diff --git a/server/szurubooru/tests/api/test_pool_deleting.py b/server/szurubooru/tests/api/test_pool_deleting.py index 387aca1..5c5adcc 100644 --- a/server/szurubooru/tests/api/test_pool_deleting.py +++ b/server/szurubooru/tests/api/test_pool_deleting.py @@ -34,17 +34,18 @@ def test_deleting_used( pool.posts.append(post) db.session.add_all([pool, post]) db.session.commit() - api.pool_api.delete_pool( - context_factory( - params={"version": 1}, - user=user_factory(rank=model.User.RANK_REGULAR), - ), - {"pool_id": 1}, - ) - db.session.refresh(post) - assert db.session.query(model.Pool).count() == 0 - assert db.session.query(model.PoolPost).count() == 0 - assert post.pools == [] + with patch("szurubooru.func.snapshots._post_to_webhooks"): + api.pool_api.delete_pool( + context_factory( + params={"version": 1}, + user=user_factory(rank=model.User.RANK_REGULAR), + ), + {"pool_id": 1}, + ) + db.session.refresh(post) + assert db.session.query(model.Pool).count() == 0 + assert db.session.query(model.PoolPost).count() == 0 + assert post.pools == [] def test_trying_to_delete_non_existing(user_factory, context_factory): diff --git a/server/szurubooru/tests/api/test_post_creating.py b/server/szurubooru/tests/api/test_post_creating.py index 4e05cf1..e2db0eb 100644 --- a/server/szurubooru/tests/api/test_post_creating.py +++ b/server/szurubooru/tests/api/test_post_creating.py @@ -143,7 +143,9 @@ def test_anonymous_uploads( with patch("szurubooru.func.posts.serialize_post"), patch( "szurubooru.func.posts.create_post" - ), patch("szurubooru.func.posts.update_post_source"): + ), patch("szurubooru.func.posts.update_post_source"), patch( + "szurubooru.func.snapshots._post_to_webhooks" + ): config_injector( { "privileges": { @@ -181,6 +183,8 @@ def test_creating_from_url_saves_source( "szurubooru.func.posts.serialize_post" ), patch("szurubooru.func.posts.create_post"), patch( "szurubooru.func.posts.update_post_source" + ), patch( + "szurubooru.func.snapshots._post_to_webhooks" ): config_injector( { @@ -223,6 +227,8 @@ def test_creating_from_url_with_source_specified( "szurubooru.func.posts.serialize_post" ), patch("szurubooru.func.posts.create_post"), patch( "szurubooru.func.posts.update_post_source" + ), patch( + "szurubooru.func.snapshots._post_to_webhooks" ): config_injector( { @@ -334,7 +340,7 @@ def test_errors_not_spending_ids( # successful request with patch("szurubooru.func.posts.serialize_post"), patch( "szurubooru.func.posts.update_post_tags" - ): + ), patch("szurubooru.func.snapshots._post_to_webhooks"): posts.serialize_post.side_effect = lambda post, *_, **__: post.post_id post1_id = api.post_api.create_post( context_factory( @@ -357,7 +363,7 @@ def test_errors_not_spending_ids( # successful request with patch("szurubooru.func.posts.serialize_post"), patch( "szurubooru.func.posts.update_post_tags" - ): + ), patch("szurubooru.func.snapshots._post_to_webhooks"): posts.serialize_post.side_effect = lambda post, *_, **__: post.post_id post2_id = api.post_api.create_post( context_factory( diff --git a/server/szurubooru/tests/api/test_post_featuring.py b/server/szurubooru/tests/api/test_post_featuring.py index e1f8cef..d83d4b6 100644 --- a/server/szurubooru/tests/api/test_post_featuring.py +++ b/server/szurubooru/tests/api/test_post_featuring.py @@ -55,7 +55,9 @@ def test_trying_to_feature_the_same_post_twice( ): db.session.add(post_factory(id=1)) db.session.commit() - with patch("szurubooru.func.posts.serialize_post"): + with patch("szurubooru.func.posts.serialize_post"), patch( + "szurubooru.func.snapshots._post_to_webhooks" + ): api.post_api.set_featured_post( context_factory( params={"id": 1}, @@ -80,7 +82,9 @@ def test_featuring_one_post_after_another( assert posts.try_get_featured_post() is None assert not posts.get_post_by_id(1).is_featured assert not posts.get_post_by_id(2).is_featured - with patch("szurubooru.func.posts.serialize_post"): + with patch("szurubooru.func.posts.serialize_post"), patch( + "szurubooru.func.snapshots._post_to_webhooks" + ): with fake_datetime("1997"): api.post_api.set_featured_post( context_factory( diff --git a/server/szurubooru/tests/api/test_tag_category_updating.py b/server/szurubooru/tests/api/test_tag_category_updating.py index 0d59390..6c32737 100644 --- a/server/szurubooru/tests/api/test_tag_category_updating.py +++ b/server/szurubooru/tests/api/test_tag_category_updating.py @@ -65,7 +65,7 @@ def test_omitting_optional_field( del params[field] with patch("szurubooru.func.tag_categories.serialize_category"), patch( "szurubooru.func.tag_categories.update_category_name" - ): + ), patch("szurubooru.func.snapshots._post_to_webhooks"): api.tag_category_api.update_tag_category( context_factory( params={**params, **{"version": 1}}, diff --git a/server/szurubooru/tests/api/test_tag_creating.py b/server/szurubooru/tests/api/test_tag_creating.py index 648b317..2f4264d 100644 --- a/server/szurubooru/tests/api/test_tag_creating.py +++ b/server/szurubooru/tests/api/test_tag_creating.py @@ -71,7 +71,7 @@ def test_omitting_optional_field( del params[field] with patch("szurubooru.func.tags.create_tag"), patch( "szurubooru.func.tags.serialize_tag" - ): + ), patch("szurubooru.func.snapshots._post_to_webhooks"): tags.create_tag.return_value = tag_factory() api.tag_api.create_tag( context_factory( diff --git a/server/szurubooru/tests/api/test_tag_deleting.py b/server/szurubooru/tests/api/test_tag_deleting.py index b45ef55..59a19f8 100644 --- a/server/szurubooru/tests/api/test_tag_deleting.py +++ b/server/szurubooru/tests/api/test_tag_deleting.py @@ -34,16 +34,17 @@ def test_deleting_used( post.tags.append(tag) db.session.add_all([tag, post]) db.session.commit() - api.tag_api.delete_tag( - context_factory( - params={"version": 1}, - user=user_factory(rank=model.User.RANK_REGULAR), - ), - {"tag_name": "tag"}, - ) - db.session.refresh(post) - assert db.session.query(model.Tag).count() == 0 - assert post.tags == [] + with patch("szurubooru.func.snapshots._post_to_webhooks"): + api.tag_api.delete_tag( + context_factory( + params={"version": 1}, + user=user_factory(rank=model.User.RANK_REGULAR), + ), + {"tag_name": "tag"}, + ) + db.session.refresh(post) + assert db.session.query(model.Tag).count() == 0 + assert post.tags == [] def test_trying_to_delete_non_existing(user_factory, context_factory): |