From 894cd295119b33fe786b51558b8b53033813ae27 Mon Sep 17 00:00:00 2001 From: rr- Date: Fri, 3 Feb 2017 19:53:10 +0100 Subject: [PATCH] server/tests: test image hash --- config.yaml.dist | 1 + server/szurubooru/func/image_hash.py | 10 +++++++- .../tests/api/test_post_creating.py | 3 ++- .../szurubooru/tests/assets/jpeg-similar.jpg | Bin 0 -> 10810 bytes server/szurubooru/tests/conftest.py | 4 +-- .../szurubooru/tests/func/test_image_hash.py | 24 ++++++++++++++++++ server/szurubooru/tests/func/test_posts.py | 11 ++------ 7 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 server/szurubooru/tests/assets/jpeg-similar.jpg create mode 100644 server/szurubooru/tests/func/test_image_hash.py diff --git a/config.yaml.dist b/config.yaml.dist index a38393a0..1f4a2307 100644 --- a/config.yaml.dist +++ b/config.yaml.dist @@ -36,6 +36,7 @@ smtp: elasticsearch: host: localhost port: 9200 + index: szurubooru limits: users_per_page: 20 diff --git a/server/szurubooru/func/image_hash.py b/server/szurubooru/func/image_hash.py index 8f8c4d72..ae368488 100644 --- a/server/szurubooru/func/image_hash.py +++ b/server/szurubooru/func/image_hash.py @@ -12,7 +12,10 @@ es = elasticsearch.Elasticsearch([{ 'host': config.config['elasticsearch']['host'], 'port': config.config['elasticsearch']['port'], }]) -session = SignatureES(es, index='szurubooru') + + +def _get_session(): + return SignatureES(es, index=config.config['elasticsearch']['index']) def _safe_blanket(default_param_factory): @@ -48,6 +51,7 @@ class Lookalike: def add_image(path, image_content): if not path or not image_content: return + session = _get_session() session.add_image(path=path, img=image_content, bytestream=True) @@ -55,6 +59,7 @@ def add_image(path, image_content): def delete_image(path): if not path: return + session = _get_session() es.delete_by_query( index=session.index, doc_type=session.doc_type, @@ -64,6 +69,7 @@ def delete_image(path): @_safe_blanket(lambda: []) def search_by_image(image_content): ret = [] + session = _get_session() for result in session.search_image( path=image_content, # sic bytestream=True): @@ -76,6 +82,7 @@ def search_by_image(image_content): @_safe_blanket(lambda: None) def purge(): + session = _get_session() es.delete_by_query( index=session.index, doc_type=session.doc_type, @@ -84,6 +91,7 @@ def purge(): @_safe_blanket(lambda: set()) def get_all_paths(): + session = _get_session() search = ( elasticsearch_dsl.Search( using=es, index=session.index, doc_type=session.doc_type) diff --git a/server/szurubooru/tests/api/test_post_creating.py b/server/szurubooru/tests/api/test_post_creating.py index 341990c8..9737a73b 100644 --- a/server/szurubooru/tests/api/test_post_creating.py +++ b/server/szurubooru/tests/api/test_post_creating.py @@ -258,7 +258,8 @@ def test_omitting_optional_field( def test_errors_not_spending_ids( - config_injector, tmpdir, context_factory, read_asset, user_factory): + config_injector, tmpdir, context_factory, read_asset, user_factory, + skip_post_hashing): config_injector({ 'data_dir': str(tmpdir.mkdir('data')), 'data_url': 'example.com', diff --git a/server/szurubooru/tests/assets/jpeg-similar.jpg b/server/szurubooru/tests/assets/jpeg-similar.jpg new file mode 100644 index 0000000000000000000000000000000000000000..af6120924c7c1d5a28cc9c2a59388d2b758fab4c GIT binary patch literal 10810 zcmbtZRag{Uv>m!T1ZfyTN*d|zl9+*^6oyXeP625cx{>Z0IusP7L%MV5lt%LUKiu!T z?{}Zaz1G_MoQL!6Z?Bhymkj`+s-lV_00{{Rp#1LuUY-HW@6BwT-0Ah4ogL`8bY)by z=vCh>xWwc!w`OHGdnP3GCKPLa2zoG#0Z~miFBLV&s{y);_7$~S{$e2ige_64A zO&}wo{1g5c=qUf{|IGDn_)1y6p+b=z;u3W{sHovLmMXLbX^Ny zmH@c_@W@0cL;xwkcZ*K}-E>>QdC10fl1Bf zM+j_^4^uWfmR#cgeyZ064BpL3=LA={CHmM+4*#(wiM0Qk~P^ltun#R zP(UTP>?5i3+Dxp9rq`z*OM8wxKONpyNF#4n2y-^3)`DMaVQNc*o@;1z&60GM4oZ~- z%#*uaFD+R{)Nh;L3h=3 zE0JS0?PUt&F&w!+$Ts{i&bzhK-!bfE!|5UzHDHk4`7{c`gqFIRwo+%Sr`ZeBr(Q#K z$C|cW*^>-)5BL_7QA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pB@21OY+WrYx7|jx2(cjb89J>Z58`h|bR_2QGHZZI6bPQ3qFBy`az)PN z)Y%^^JsZFi{P-u*^5eE88pW)c2Jx(~=2c4M)nU zub6G!ug|I+RiGa}kO9Hc{UjVE(c|oMb3g5}_{j+TC)@i~IHxpg{p&zK$jqWr%9&G& zICzJ^ve>X#fL=L0LWIUFpZo|+lW7%E0c^4RL2bdmvrzR876FMzKW6KB{}tEa1)x|s zuANLHNcK(++{>K!bKnEA^cNIVIJRDQt`HZMyePTDwz%z_8$iZW+eL zYCz6%T$v>q%CzrM9ij`Mk??Xfe01q?0;bZmud`iZ5;Tl)*v{Y&;Xa1L6F|5`j4f*Q zadKa*YVJtJW6i}TKr??P~Jg301t(1alHSpgl>|{Qdbe(#(-4a$~ literal 0 HcmV?d00001 diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index 5dd47576..db34ee02 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -155,7 +155,7 @@ def tag_factory(): return factory -@pytest.yield_fixture(autouse=True) +@pytest.yield_fixture def skip_post_hashing(): with patch('szurubooru.func.image_hash.add_image'), \ patch('szurubooru.func.image_hash.delete_image'): @@ -163,7 +163,7 @@ def skip_post_hashing(): @pytest.fixture -def post_factory(): +def post_factory(skip_post_hashing): # pylint: disable=invalid-name def factory( id=None, diff --git a/server/szurubooru/tests/func/test_image_hash.py b/server/szurubooru/tests/func/test_image_hash.py new file mode 100644 index 00000000..3bbdeba2 --- /dev/null +++ b/server/szurubooru/tests/func/test_image_hash.py @@ -0,0 +1,24 @@ +from time import sleep +from szurubooru.func import image_hash + + +def test_hashing(read_asset, config_injector): + config_injector({'elasticsearch': {'index': 'szurubooru_test'}}) + image_hash.purge() + image_hash.add_image('test', read_asset('jpeg.jpg')) + + sleep(0.1) + + paths = image_hash.get_all_paths() + results_exact = image_hash.search_by_image(read_asset('jpeg.jpg')) + results_similar = image_hash.search_by_image(read_asset('jpeg-similar.jpg')) + + assert len(paths) == 1 + assert len(results_exact) == 1 + assert len(results_similar) == 1 + assert results_exact[0].path == 'test' + assert results_exact[0].score == 63 + assert results_exact[0].distance == 0 + assert results_similar[0].path == 'test' + assert results_similar[0].score == 26 + assert abs(results_similar[0].distance - 0.189390583) < 1e-8 diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index f44fb03b..a10cc6d9 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -290,15 +290,8 @@ def test_update_post_source_with_too_long_string(): ), ]) def test_update_post_content_for_new_post( - tmpdir, - config_injector, - post_factory, - read_asset, - is_existing, - input_file, - expected_mime_type, - expected_type, - output_file_name): + tmpdir, config_injector, post_factory, read_asset, is_existing, + input_file, expected_mime_type, expected_type, output_file_name): with patch('szurubooru.func.util.get_sha1'): util.get_sha1.return_value = 'crc' config_injector({