From 82bb9c63c8876464f48cce21a1cea5655c94a06c Mon Sep 17 00:00:00 2001 From: Luxray5474 Date: Sun, 23 Aug 2020 23:25:09 -0400 Subject: [PATCH] pre-commit stuff and and pytest updates --- client/js/models/post.js | 2 +- client/js/views/post_upload_view.js | 1 - server/szurubooru/api/post_api.py | 6 ++++-- server/szurubooru/func/posts.py | 7 +++++-- server/szurubooru/tests/conftest.py | 1 + server/szurubooru/tests/func/test_posts.py | 2 ++ server/szurubooru/tests/model/test_post.py | 2 ++ 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/client/js/models/post.js b/client/js/models/post.js index cd13d522..59b34189 100644 --- a/client/js/models/post.js +++ b/client/js/models/post.js @@ -147,7 +147,7 @@ class Post extends events.EventTarget { } set fileLastModifiedTime(value) { - this._fileLastModifiedTime = value; + this._fileLastModifiedTime = value; } set flags(value) { diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js index 5e396f11..0610e57b 100644 --- a/client/js/views/post_upload_view.js +++ b/client/js/views/post_upload_view.js @@ -220,7 +220,6 @@ class PostUploadView extends events.EventTarget { duplicatesFound++; continue; } - console.log(uploadable) this._uploadables.push(uploadable); this._emit("change"); this._renderRowNode(uploadable); diff --git a/server/szurubooru/api/post_api.py b/server/szurubooru/api/post_api.py index fa3643a0..9262af56 100644 --- a/server/szurubooru/api/post_api.py +++ b/server/szurubooru/api/post_api.py @@ -76,7 +76,6 @@ def create_post( flags = ctx.get_param_as_string_list( "flags", default=posts.get_default_flags(content) ) - file_last_modified_time = ctx.get_param_as_int("fileLastModifiedTime") post, new_tags = posts.create_post( content, tag_names, None if anonymous else ctx.user @@ -88,7 +87,10 @@ def create_post( posts.update_post_relations(post, relations) posts.update_post_notes(post, notes) posts.update_post_flags(post, flags) - posts.update_post_file_last_modified_time(post, file_last_modified_time) + if ctx.has_param("fileLastModifiedTime"): + posts.update_post_file_last_modified_time( + post, ctx.get_as_param("file_last_modified_time") + ) if ctx.has_file("thumbnail"): posts.update_post_thumbnail(post, ctx.get_file("thumbnail")) ctx.session.add(post) diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index ec58116c..2816bb52 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -426,12 +426,15 @@ def create_post( return post, new_tags -def update_post_file_last_modified_time(post: model.Post, timestamp: int) -> None: +def update_post_file_last_modified_time( + post: model.Post, timestamp: int +) -> None: assert post - + # Timestamp is in ms, so it must be divided by 1000 otherwise out of range post.file_last_modified_time = datetime.fromtimestamp(timestamp / 1000) + def update_post_safety(post: model.Post, safety: str) -> None: assert post safety = util.flip(SAFETY_MAP).get(safety, None) diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index 6e127bcd..213f1134 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -168,6 +168,7 @@ def post_factory(): post.flags = [] post.mime_type = "application/octet-stream" post.creation_time = datetime(1996, 1, 1) + post.file_last_modified_time = datetime(1997, 1, 1) return post return factory diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index acedf6f3..3f3116d1 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -122,6 +122,7 @@ def test_serialize_post( post.post_id = 1 post.creation_time = datetime(1997, 1, 1) post.last_edit_time = datetime(1998, 1, 1) + post.file_last_modified_time = datetime(1999, 1, 1) post.tags = [ tag_factory( names=["tag1", "tag2"], @@ -215,6 +216,7 @@ def test_serialize_post( "version": 1, "creationTime": datetime(1997, 1, 1), "lastEditTime": datetime(1998, 1, 1), + "fileLastModifiedTime": datetime(1999, 1, 1), "safety": "safe", "source": "4gag", "type": "image", diff --git a/server/szurubooru/tests/model/test_post.py b/server/szurubooru/tests/model/test_post.py index f01455d3..6c6c2f9f 100644 --- a/server/szurubooru/tests/model/test_post.py +++ b/server/szurubooru/tests/model/test_post.py @@ -24,6 +24,7 @@ def test_saving_post(post_factory, user_factory, tag_factory): post.checksum = "deadbeef" post.creation_time = datetime(1997, 1, 1) post.last_edit_time = datetime(1998, 1, 1) + post.file_last_modified_time = datetime(1999, 1, 1) post.mime_type = "application/whatever" db.session.add_all([user, tag1, tag2, related_post1, related_post2, post]) @@ -44,6 +45,7 @@ def test_saving_post(post_factory, user_factory, tag_factory): assert post.checksum == "deadbeef" assert post.creation_time == datetime(1997, 1, 1) assert post.last_edit_time == datetime(1998, 1, 1) + assert post.file_last_modified_time == datetime(1999, 1, 1) assert len(post.relations) == 2 # relation bidirectionality is realized on business level in func.posts assert len(related_post1.relations) == 0