aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/tests/api
diff options
context:
space:
mode:
authorrr-2016-08-14 20:06:49 +0200
committerrr-2016-08-16 21:51:25 +0200
commit80af79779d01fe949af84fdb43f6b82085cd4a9c (patch)
tree5353b010afb89292ea5ab693ead355dc2426fb65 /server/szurubooru/tests/api
parent03a7bd0d5cbf52a9de8ad6aacad5f173c2e56785 (diff)
server/snapshots: rewrite
Diffstat (limited to 'server/szurubooru/tests/api')
-rw-r--r--server/szurubooru/tests/api/test_post_creating.py11
-rw-r--r--server/szurubooru/tests/api/test_post_deleting.py15
-rw-r--r--server/szurubooru/tests/api/test_post_featuring.py15
-rw-r--r--server/szurubooru/tests/api/test_post_updating.py13
-rw-r--r--server/szurubooru/tests/api/test_snapshot_retrieving.py4
-rw-r--r--server/szurubooru/tests/api/test_tag_category_creating.py23
-rw-r--r--server/szurubooru/tests/api/test_tag_category_deleting.py15
-rw-r--r--server/szurubooru/tests/api/test_tag_category_retrieving.py1
-rw-r--r--server/szurubooru/tests/api/test_tag_category_updating.py14
-rw-r--r--server/szurubooru/tests/api/test_tag_creating.py10
-rw-r--r--server/szurubooru/tests/api/test_tag_deleting.py14
-rw-r--r--server/szurubooru/tests/api/test_tag_merging.py8
-rw-r--r--server/szurubooru/tests/api/test_tag_updating.py5
13 files changed, 81 insertions, 67 deletions
diff --git a/server/szurubooru/tests/api/test_post_creating.py b/server/szurubooru/tests/api/test_post_creating.py
index 1a1f045..d88cb9a 100644
--- a/server/szurubooru/tests/api/test_post_creating.py
+++ b/server/szurubooru/tests/api/test_post_creating.py
@@ -31,7 +31,7 @@ def test_creating_minimal_posts(
patch('szurubooru.func.posts.update_post_thumbnail'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_creation'):
+ patch('szurubooru.func.snapshots.create'):
posts.create_post.return_value = (post, [])
posts.serialize_post.return_value = 'serialized post'
@@ -61,8 +61,8 @@ def test_creating_minimal_posts(
post, 'post-thumbnail')
posts.serialize_post.assert_called_once_with(
post, auth_user, options=None)
+ snapshots.create.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
- snapshots.save_entity_creation.assert_called_once_with(post, auth_user)
def test_creating_full_posts(context_factory, post_factory, user_factory):
@@ -79,7 +79,7 @@ def test_creating_full_posts(context_factory, post_factory, user_factory):
patch('szurubooru.func.posts.update_post_flags'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_creation'):
+ patch('szurubooru.func.snapshots.create'):
posts.create_post.return_value = (post, [])
posts.serialize_post.return_value = 'serialized post'
@@ -110,8 +110,8 @@ def test_creating_full_posts(context_factory, post_factory, user_factory):
post, ['flag1', 'flag2'])
posts.serialize_post.assert_called_once_with(
post, auth_user, options=None)
+ snapshots.create.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
- snapshots.save_entity_creation.assert_called_once_with(post, auth_user)
def test_anonymous_uploads(
@@ -122,7 +122,6 @@ def test_anonymous_uploads(
db.session.flush()
with patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_creation'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.create_post'), \
patch('szurubooru.func.posts.update_post_source'):
@@ -154,7 +153,6 @@ def test_creating_from_url_saves_source(
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_creation'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.create_post'), \
patch('szurubooru.func.posts.update_post_source'):
@@ -186,7 +184,6 @@ def test_creating_from_url_with_source_specified(
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_creation'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.create_post'), \
patch('szurubooru.func.posts.update_post_source'):
diff --git a/server/szurubooru/tests/api/test_post_deleting.py b/server/szurubooru/tests/api/test_post_deleting.py
index 2817580..19096e4 100644
--- a/server/szurubooru/tests/api/test_post_deleting.py
+++ b/server/szurubooru/tests/api/test_post_deleting.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import posts, tags
+from szurubooru.func import posts, tags, snapshots
@pytest.fixture(autouse=True)
@@ -10,16 +10,17 @@ def inject_config(config_injector):
def test_deleting(user_factory, post_factory, context_factory):
- db.session.add(post_factory(id=1))
- db.session.commit()
- with patch('szurubooru.func.tags.export_to_json'):
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
+ post = post_factory(id=1)
+ db.session.add(post)
+ with patch('szurubooru.func.tags.export_to_json'), \
+ patch('szurubooru.func.snapshots.delete'):
result = api.post_api.delete_post(
- context_factory(
- params={'version': 1},
- user=user_factory(rank=db.User.RANK_REGULAR)),
+ context_factory(params={'version': 1}, user=auth_user),
{'post_id': 1})
assert result == {}
assert db.session.query(db.Post).count() == 0
+ snapshots.delete.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
diff --git a/server/szurubooru/tests/api/test_post_featuring.py b/server/szurubooru/tests/api/test_post_featuring.py
index 9f3bd0d..c2822f8 100644
--- a/server/szurubooru/tests/api/test_post_featuring.py
+++ b/server/szurubooru/tests/api/test_post_featuring.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import posts
+from szurubooru.func import posts, snapshots
@pytest.fixture(autouse=True)
@@ -15,15 +15,15 @@ def inject_config(config_injector):
def test_featuring(user_factory, post_factory, context_factory):
- db.session.add(post_factory(id=1))
- db.session.commit()
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
+ post = post_factory(id=1)
+ db.session.add(post)
assert not posts.get_post_by_id(1).is_featured
- with patch('szurubooru.func.posts.serialize_post'):
+ with patch('szurubooru.func.posts.serialize_post'), \
+ patch('szurubooru.func.snapshots.modify'):
posts.serialize_post.return_value = 'serialized post'
result = api.post_api.set_featured_post(
- context_factory(
- params={'id': 1},
- user=user_factory(rank=db.User.RANK_REGULAR)))
+ context_factory(params={'id': 1}, user=auth_user))
assert result == 'serialized post'
assert posts.try_get_featured_post() is not None
assert posts.try_get_featured_post().post_id == 1
@@ -32,6 +32,7 @@ def test_featuring(user_factory, post_factory, context_factory):
context_factory(
user=user_factory(rank=db.User.RANK_REGULAR)))
assert result == 'serialized post'
+ snapshots.modify.assert_called_once_with(post, auth_user)
def test_trying_to_omit_required_parameter(user_factory, context_factory):
diff --git a/server/szurubooru/tests/api/test_post_updating.py b/server/szurubooru/tests/api/test_post_updating.py
index b577c7e..790e835 100644
--- a/server/szurubooru/tests/api/test_post_updating.py
+++ b/server/szurubooru/tests/api/test_post_updating.py
@@ -40,7 +40,7 @@ def test_post_updating(
patch('szurubooru.func.posts.update_post_flags'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_modification'), \
+ patch('szurubooru.func.snapshots.modify'), \
fake_datetime('1997-01-01'):
posts.serialize_post.return_value = 'serialized post'
@@ -77,9 +77,8 @@ def test_post_updating(
post, ['flag1', 'flag2'])
posts.serialize_post.assert_called_once_with(
post, auth_user, options=None)
+ snapshots.modify.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
- snapshots.save_entity_modification.assert_called_once_with(
- post, auth_user)
assert post.last_edit_time == datetime(1997, 1, 1)
@@ -90,10 +89,10 @@ def test_uploading_from_url_saves_source(
db.session.flush()
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_modification'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.update_post_content'), \
- patch('szurubooru.func.posts.update_post_source'):
+ patch('szurubooru.func.posts.update_post_source'), \
+ patch('szurubooru.func.snapshots.modify'):
net.download.return_value = b'content'
api.post_api.update_post(
context_factory(
@@ -112,10 +111,10 @@ def test_uploading_from_url_with_source_specified(
db.session.flush()
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
- patch('szurubooru.func.snapshots.save_entity_modification'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.update_post_content'), \
- patch('szurubooru.func.posts.update_post_source'):
+ patch('szurubooru.func.posts.update_post_source'), \
+ patch('szurubooru.func.snapshots.modify'):
net.download.return_value = b'content'
api.post_api.update_post(
context_factory(
diff --git a/server/szurubooru/tests/api/test_snapshot_retrieving.py b/server/szurubooru/tests/api/test_snapshot_retrieving.py
index a04326b..7e48d10 100644
--- a/server/szurubooru/tests/api/test_snapshot_retrieving.py
+++ b/server/szurubooru/tests/api/test_snapshot_retrieving.py
@@ -7,8 +7,8 @@ def snapshot_factory():
snapshot = db.Snapshot()
snapshot.creation_time = datetime(1999, 1, 1)
snapshot.resource_type = 'dummy'
- snapshot.resource_id = 1
- snapshot.resource_repr = 'dummy'
+ snapshot.resource_pkey = 1
+ snapshot.resource_name = 'dummy'
snapshot.operation = 'added'
snapshot.data = '{}'
return snapshot
diff --git a/server/szurubooru/tests/api/test_tag_category_creating.py b/server/szurubooru/tests/api/test_tag_category_creating.py
index 8bf0792..96afc39 100644
--- a/server/szurubooru/tests/api/test_tag_category_creating.py
+++ b/server/szurubooru/tests/api/test_tag_category_creating.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import tag_categories, tags
+from szurubooru.func import tag_categories, tags, snapshots
def _update_category_name(category, name):
@@ -15,21 +15,26 @@ def inject_config(config_injector):
})
-def test_creating_category(user_factory, context_factory):
- with patch('szurubooru.func.tag_categories.serialize_category'), \
+def test_creating_category(
+ tag_category_factory, user_factory, context_factory):
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
+ category = tag_category_factory(name='meta')
+ db.session.add(category)
+
+ with patch('szurubooru.func.tag_categories.create_category'), \
+ patch('szurubooru.func.tag_categories.serialize_category'), \
patch('szurubooru.func.tag_categories.update_category_name'), \
+ patch('szurubooru.func.snapshots.create'), \
patch('szurubooru.func.tags.export_to_json'):
+ tag_categories.create_category.return_value = category
tag_categories.update_category_name.side_effect = _update_category_name
tag_categories.serialize_category.return_value = 'serialized category'
result = api.tag_category_api.create_tag_category(
context_factory(
- params={'name': 'meta', 'color': 'black'},
- user=user_factory(rank=db.User.RANK_REGULAR)))
+ params={'name': 'meta', 'color': 'black'}, user=auth_user))
assert result == 'serialized category'
- category = db.session.query(db.TagCategory).one()
- assert category.name == 'meta'
- assert category.color == 'black'
- assert category.tag_count == 0
+ tag_categories.create_category.assert_called_once_with('meta', 'black')
+ snapshots.create.assert_called_once_with(category, auth_user)
tags.export_to_json.assert_called_once_with()
diff --git a/server/szurubooru/tests/api/test_tag_category_deleting.py b/server/szurubooru/tests/api/test_tag_category_deleting.py
index bb590ef..0a8d59b 100644
--- a/server/szurubooru/tests/api/test_tag_category_deleting.py
+++ b/server/szurubooru/tests/api/test_tag_category_deleting.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import tag_categories, tags
+from szurubooru.func import tag_categories, tags, snapshots
@pytest.fixture(autouse=True)
@@ -12,18 +12,19 @@ def inject_config(config_injector):
def test_deleting(user_factory, tag_category_factory, context_factory):
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
+ category = tag_category_factory(name='category')
db.session.add(tag_category_factory(name='root'))
- db.session.add(tag_category_factory(name='category'))
- db.session.commit()
- with patch('szurubooru.func.tags.export_to_json'):
+ db.session.add(category)
+ with patch('szurubooru.func.snapshots.delete'), \
+ patch('szurubooru.func.tags.export_to_json'):
result = api.tag_category_api.delete_tag_category(
- context_factory(
- params={'version': 1},
- user=user_factory(rank=db.User.RANK_REGULAR)),
+ context_factory(params={'version': 1}, user=auth_user),
{'category_name': 'category'})
assert result == {}
assert db.session.query(db.TagCategory).count() == 1
assert db.session.query(db.TagCategory).one().name == 'root'
+ snapshots.delete.assert_called_once_with(category, auth_user)
tags.export_to_json.assert_called_once_with()
diff --git a/server/szurubooru/tests/api/test_tag_category_retrieving.py b/server/szurubooru/tests/api/test_tag_category_retrieving.py
index e371530..7a834f0 100644
--- a/server/szurubooru/tests/api/test_tag_category_retrieving.py
+++ b/server/szurubooru/tests/api/test_tag_category_retrieving.py
@@ -35,7 +35,6 @@ def test_retrieving_single(
'color': 'dummy',
'usages': 0,
'default': False,
- 'snapshots': [],
'version': 1,
}
diff --git a/server/szurubooru/tests/api/test_tag_category_updating.py b/server/szurubooru/tests/api/test_tag_category_updating.py
index d5a863a..823d59a 100644
--- a/server/szurubooru/tests/api/test_tag_category_updating.py
+++ b/server/szurubooru/tests/api/test_tag_category_updating.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import tag_categories, tags
+from szurubooru.func import tag_categories, tags, snapshots
def _update_category_name(category, name):
@@ -20,29 +20,27 @@ def inject_config(config_injector):
def test_simple_updating(user_factory, tag_category_factory, context_factory):
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
category = tag_category_factory(name='name', color='black')
db.session.add(category)
- db.session.commit()
with patch('szurubooru.func.tag_categories.serialize_category'), \
patch('szurubooru.func.tag_categories.update_category_name'), \
patch('szurubooru.func.tag_categories.update_category_color'), \
+ patch('szurubooru.func.snapshots.modify'), \
patch('szurubooru.func.tags.export_to_json'):
tag_categories.update_category_name.side_effect = _update_category_name
tag_categories.serialize_category.return_value = 'serialized category'
result = api.tag_category_api.update_tag_category(
context_factory(
- params={
- 'name': 'changed',
- 'color': 'white',
- 'version': 1,
- },
- user=user_factory(rank=db.User.RANK_REGULAR)),
+ params={'name': 'changed', 'color': 'white', 'version': 1},
+ user=auth_user),
{'category_name': 'name'})
assert result == 'serialized category'
tag_categories.update_category_name.assert_called_once_with(
category, 'changed')
tag_categories.update_category_color.assert_called_once_with(
category, 'white')
+ snapshots.modify.assert_called_once_with(category, auth_user)
tags.export_to_json.assert_called_once_with()
diff --git a/server/szurubooru/tests/api/test_tag_creating.py b/server/szurubooru/tests/api/test_tag_creating.py
index 2c55177..dc05628 100644
--- a/server/szurubooru/tests/api/test_tag_creating.py
+++ b/server/szurubooru/tests/api/test_tag_creating.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import tags
+from szurubooru.func import tags, snapshots
@pytest.fixture(autouse=True)
@@ -10,12 +10,15 @@ def inject_config(config_injector):
def test_creating_simple_tags(tag_factory, user_factory, context_factory):
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
+ tag = tag_factory()
with patch('szurubooru.func.tags.create_tag'), \
patch('szurubooru.func.tags.get_or_create_tags_by_names'), \
patch('szurubooru.func.tags.serialize_tag'), \
+ patch('szurubooru.func.snapshots.create'), \
patch('szurubooru.func.tags.export_to_json'):
tags.get_or_create_tags_by_names.return_value = ([], [])
- tags.create_tag.return_value = tag_factory()
+ tags.create_tag.return_value = tag
tags.serialize_tag.return_value = 'serialized tag'
result = api.tag_api.create_tag(
context_factory(
@@ -26,10 +29,11 @@ def test_creating_simple_tags(tag_factory, user_factory, context_factory):
'suggestions': ['sug1', 'sug2'],
'implications': ['imp1', 'imp2'],
},
- user=user_factory(rank=db.User.RANK_REGULAR)))
+ user=auth_user))
assert result == 'serialized tag'
tags.create_tag.assert_called_once_with(
['tag1', 'tag2'], 'meta', ['sug1', 'sug2'], ['imp1', 'imp2'])
+ snapshots.create.assert_called_once_with(tag, auth_user)
tags.export_to_json.assert_called_once_with()
diff --git a/server/szurubooru/tests/api/test_tag_deleting.py b/server/szurubooru/tests/api/test_tag_deleting.py
index b5237d1..a657b02 100644
--- a/server/szurubooru/tests/api/test_tag_deleting.py
+++ b/server/szurubooru/tests/api/test_tag_deleting.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import tags
+from szurubooru.func import tags, snapshots
@pytest.fixture(autouse=True)
@@ -10,16 +10,18 @@ def inject_config(config_injector):
def test_deleting(user_factory, tag_factory, context_factory):
- db.session.add(tag_factory(names=['tag']))
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
+ tag = tag_factory(names=['tag'])
+ db.session.add(tag)
db.session.commit()
- with patch('szurubooru.func.tags.export_to_json'):
+ with patch('szurubooru.func.tags.export_to_json'), \
+ patch('szurubooru.func.snapshots.delete'):
result = api.tag_api.delete_tag(
- context_factory(
- params={'version': 1},
- user=user_factory(rank=db.User.RANK_REGULAR)),
+ context_factory(params={'version': 1}, user=auth_user),
{'tag_name': 'tag'})
assert result == {}
assert db.session.query(db.Tag).count() == 0
+ snapshots.delete.assert_called_once_with(tag, auth_user)
tags.export_to_json.assert_called_once_with()
diff --git a/server/szurubooru/tests/api/test_tag_merging.py b/server/szurubooru/tests/api/test_tag_merging.py
index 9786abc..a448c9c 100644
--- a/server/szurubooru/tests/api/test_tag_merging.py
+++ b/server/szurubooru/tests/api/test_tag_merging.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import tags
+from szurubooru.func import tags, snapshots
@pytest.fixture(autouse=True)
@@ -10,6 +10,7 @@ def inject_config(config_injector):
def test_merging(user_factory, tag_factory, context_factory, post_factory):
+ auth_user = user_factory(rank=db.User.RANK_REGULAR)
source_tag = tag_factory(names=['source'])
target_tag = tag_factory(names=['target'])
db.session.add_all([source_tag, target_tag])
@@ -24,6 +25,7 @@ def test_merging(user_factory, tag_factory, context_factory, post_factory):
assert target_tag.post_count == 0
with patch('szurubooru.func.tags.serialize_tag'), \
patch('szurubooru.func.tags.merge_tags'), \
+ patch('szurubooru.func.snapshots.merge'), \
patch('szurubooru.func.tags.export_to_json'):
api.tag_api.merge_tags(
context_factory(
@@ -33,8 +35,10 @@ def test_merging(user_factory, tag_factory, context_factory, post_factory):
'remove': 'source',
'mergeTo': 'target',
},
- user=user_factory(rank=db.User.RANK_REGULAR)))
+ user=auth_user))
tags.merge_tags.called_once_with(source_tag, target_tag)
+ snapshots.merge.assert_called_once_with(
+ source_tag, target_tag, auth_user)
tags.export_to_json.assert_called_once_with()
diff --git a/server/szurubooru/tests/api/test_tag_updating.py b/server/szurubooru/tests/api/test_tag_updating.py
index 81f195b..3fe69bd 100644
--- a/server/szurubooru/tests/api/test_tag_updating.py
+++ b/server/szurubooru/tests/api/test_tag_updating.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
import pytest
from szurubooru import api, db, errors
-from szurubooru.func import tags
+from szurubooru.func import tags, snapshots
@pytest.fixture(autouse=True)
@@ -31,6 +31,7 @@ def test_simple_updating(user_factory, tag_factory, context_factory):
patch('szurubooru.func.tags.update_tag_suggestions'), \
patch('szurubooru.func.tags.update_tag_implications'), \
patch('szurubooru.func.tags.serialize_tag'), \
+ patch('szurubooru.func.snapshots.modify'), \
patch('szurubooru.func.tags.export_to_json'):
tags.get_or_create_tags_by_names.return_value = ([], [])
tags.serialize_tag.return_value = 'serialized tag'
@@ -57,6 +58,8 @@ def test_simple_updating(user_factory, tag_factory, context_factory):
tag, ['imp1', 'imp2'])
tags.serialize_tag.assert_called_once_with(
tag, options=None)
+ snapshots.modify.assert_called_once_with(tag, auth_user)
+ tags.export_to_json.assert_called_once_with()
@pytest.mark.parametrize(

© 2015 - 2026 Jakob L. Kreuze