From 7c302631014f85efa05cf809679f55260a0d9593 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 7 Jul 2021 18:50:53 +0200 Subject: [PATCH] #1784 - location of existing unittests refactored for futuru use --- .../igniter/test_bootstrap_repos.py | 0 tests/{ => unit}/igniter/test_tools.py | 0 .../openpype/lib/test_user_settings.py | 0 .../sync_server/fixture/openpype/logs.bson | Bin 0 -> 2824 bytes .../fixture/openpype/logs.metadata.json | 1 + .../fixture/openpype/settings.bson | Bin 0 -> 623 bytes .../fixture/openpype/settings.metadata.json | 1 + .../fixture/test_db/test_project.bson | Bin 0 -> 13295 bytes .../test_db/test_project.metadata.json | 1 + .../sync_server/test_site_operations.py | 164 ++++++++++++++++++ 10 files changed, 167 insertions(+) rename tests/{ => unit}/igniter/test_bootstrap_repos.py (100%) rename tests/{ => unit}/igniter/test_tools.py (100%) rename tests/{ => unit}/openpype/lib/test_user_settings.py (100%) create mode 100644 tests/unit/openpype/modules/sync_server/fixture/openpype/logs.bson create mode 100644 tests/unit/openpype/modules/sync_server/fixture/openpype/logs.metadata.json create mode 100644 tests/unit/openpype/modules/sync_server/fixture/openpype/settings.bson create mode 100644 tests/unit/openpype/modules/sync_server/fixture/openpype/settings.metadata.json create mode 100644 tests/unit/openpype/modules/sync_server/fixture/test_db/test_project.bson create mode 100644 tests/unit/openpype/modules/sync_server/fixture/test_db/test_project.metadata.json create mode 100644 tests/unit/openpype/modules/sync_server/test_site_operations.py diff --git a/tests/igniter/test_bootstrap_repos.py b/tests/unit/igniter/test_bootstrap_repos.py similarity index 100% rename from tests/igniter/test_bootstrap_repos.py rename to tests/unit/igniter/test_bootstrap_repos.py diff --git a/tests/igniter/test_tools.py b/tests/unit/igniter/test_tools.py similarity index 100% rename from tests/igniter/test_tools.py rename to tests/unit/igniter/test_tools.py diff --git a/tests/openpype/lib/test_user_settings.py b/tests/unit/openpype/lib/test_user_settings.py similarity index 100% rename from tests/openpype/lib/test_user_settings.py rename to tests/unit/openpype/lib/test_user_settings.py diff --git a/tests/unit/openpype/modules/sync_server/fixture/openpype/logs.bson b/tests/unit/openpype/modules/sync_server/fixture/openpype/logs.bson new file mode 100644 index 0000000000000000000000000000000000000000..37efb8a4a8dd94738bd7800df8e7a6d0f4c010c6 GIT binary patch literal 2824 zcmdUw&ui2`6vxM)*7^gAJtf+z9Nn@3+}vNbEQ71~3DWoPofFEjJz^WMwHLxha@EF|~7 zz5P7?bL&O>*~`kPW-%yDGe0;#+Nv}}9ze$b*au1j$r0Q&2}FC_p`a5 z&MQfuIM#=p#67H=kzS=XU4nieav4{FdqDRC+0v>Up#-gb^%J zj*z8wa9dQlm_1TMIE40ek#~;oUDWr*m*G+T*q+5R4>mJZo^YCAd2I*rVH9MC57E7f zwi42PS3tL#qkCZwx=-|9>0(L~o;g zUqpM*u-kcd$b%fg#Rq4}s4(jpl`TGBo|ombo3b%gOE+UxR=` literal 0 HcmV?d00001 diff --git a/tests/unit/openpype/modules/sync_server/fixture/openpype/logs.metadata.json b/tests/unit/openpype/modules/sync_server/fixture/openpype/logs.metadata.json new file mode 100644 index 0000000000..8c7a16261d --- /dev/null +++ b/tests/unit/openpype/modules/sync_server/fixture/openpype/logs.metadata.json @@ -0,0 +1 @@ +{"options":{"capped":true,"size":{"$numberDouble":"1.073741824E+09"},"max":{"$numberInt":"5000"}},"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"f982c4d7baf54d03b88aaa540c9ced8e","collectionName":"logs"} \ No newline at end of file diff --git a/tests/unit/openpype/modules/sync_server/fixture/openpype/settings.bson b/tests/unit/openpype/modules/sync_server/fixture/openpype/settings.bson new file mode 100644 index 0000000000000000000000000000000000000000..dbfe2e88c6e63f08fccd8a06a280b29dd9bf5bbc GIT binary patch literal 623 zcmbV~Jx&8L5QS&6AXcIY5+#SAqo4%|3JN6p!MmPKO#HL*%p&bg=(!1J0nWidfUr@D zkir^Sp7;6LZ=MT)19TSd-(GHRpW6A!-NoxfhK^tg06efzKqe6vXAGq^Vj!rf49WJM z81Qq`N;b^`&QwxSG_@xSu!oo)DQ9OX;(`W7gk$ZPoI<7Lw+~8jfihz-(ab3CjNu_R z>NV@7V@9#P6-&l?7ikRm$6HuTw8p1MU0-|0bCi_)t~mXtb6x8Zy{{sg`BWRf9?`yv z0IvT?<1*dL!=>~{kGh;5sF97@$}w7MP45K?xY_`kt~~sJG(SmU_#Trl4`a>;Ny@BQ literal 0 HcmV?d00001 diff --git a/tests/unit/openpype/modules/sync_server/fixture/openpype/settings.metadata.json b/tests/unit/openpype/modules/sync_server/fixture/openpype/settings.metadata.json new file mode 100644 index 0000000000..dafcd98d52 --- /dev/null +++ b/tests/unit/openpype/modules/sync_server/fixture/openpype/settings.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"8329d557adfe48018cd533dc648e3b7f","collectionName":"settings"} \ No newline at end of file diff --git a/tests/unit/openpype/modules/sync_server/fixture/test_db/test_project.bson b/tests/unit/openpype/modules/sync_server/fixture/test_db/test_project.bson new file mode 100644 index 0000000000000000000000000000000000000000..c81a0bd315f5c02f4ef86523e34f8b4098ae31cf GIT binary patch literal 13295 zcmeHOO^h5z6)yJ-pyYzYfdg;=E{Fp^;s^*3NPqwdMT&?J7nCChBJsVduAb^i?`9`) z#Ij_iFx^$Js@|*j-uHgmyz)`TZfiPi_N7;?AOH06g`d>E_OnYyydH3NJ7X*e{p-9H zGsCm{oP8K0F^}S=8ZNZ$*k-R`*l79f9D>_jXF0UP^>hWBXt_>s#$)@iNIah(#NuUN zCx|dce{&}$Iw1~x%4@TK6hJ55F2;5k%lDq`wOuhy;q!C5w&`}Z?pUG<_Fvh za6dR7FOEZ|RjZ9;a*XCilQkt_cT^~K$4*R~h4w*1HJ92i=^J72i`GFF7jvY+Tz6Vcs zC*~pVbfBh)Xy^pXWS>llK7^-%7joMzS4))|-U?3N?sCUxFGEiSAv*gW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jV|c`fP7JUh%bg?Iu!ASyL$DAXnINw0#k%(Pb_revo= zv}_D)UkngZJp^l!eB8O}L<8Gh6k{s7K8igM_@a0T;Kc67+psmHf-c%Ena)jKLq+Sd zXuX&GHjTKLxAc03&7G0f5Vez33rX)SjrMSoCK0ui#NTaF`b^)89ZGNg_0=~%|4OH~ zf5}*pB4-jIZShb!1mH67AlmfSgae3l8EMo}8LI7hLCmE_pUhIfiNmC6zP|R` zUwozDUf+lxP~1|&mRg)+JFpuUR%!V>ehgP*IxqrGOb}W}KL$3}>QoL*E?at08ku4FQYQU&|tdME%&s}O-8#+L`5-630H?Pfb>Kl+rv0WWi=Svdq*gm1^~-Wg&&CjSDOP)M4d2;Aj-1A6Bq3X8I~K7wVQ$^bny$<|QT$ z8Rmos@s@N}Lr&BTomGOsP8=fVC5DF8NLo;^mveM}NOAh^lGukwli0^_)))-$<(yXk z*9N$iq(4Z7BfT+pC?_sGs?>5TGu}hPjF((XTGo?bLi+s;@G?%uD^0H@k@MGPTLNHD{W0wRae0p8J)Syq0r7;>ddl z5_gj1>K}!?4;9+y66rjf&0AOt-}iq96~CZ*rf;o^}TxR`to;R468zQ4L#fPz@ri>2)z$|lpD3Frsp> z-zDE&$_gXKEL`bpg!-PON`V9n9>LVG5~MN{rRyCUJsxw*)xM@r#h<14duQdU+NL~O zu2L!XHcam25|y#K7BJK;Rn%qQiXv2PY7L7}`YI`l(0N?H^i=$NlCg?VWpoYopsa8E zLUfc``%JnAOVN9Ay}PIs%{agM+>(nR`Q@nin!UsCEcD@fo6vEbZpLI(m5xGTRT|`% zVUYS4x3?`vm1&8O*O5samF}hZZRV$nnZuNsf6I9L3uIYesK@=I%0y3mb+I cYjUn))vGhJH|x{W^_jVGW61H}Xl3bt05iqOQ~&?~ literal 0 HcmV?d00001 diff --git a/tests/unit/openpype/modules/sync_server/fixture/test_db/test_project.metadata.json b/tests/unit/openpype/modules/sync_server/fixture/test_db/test_project.metadata.json new file mode 100644 index 0000000000..b43f27f459 --- /dev/null +++ b/tests/unit/openpype/modules/sync_server/fixture/test_db/test_project.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"bfe11cd230d041438b288f7d6ad8e70f","collectionName":"test_project"} \ No newline at end of file diff --git a/tests/unit/openpype/modules/sync_server/test_site_operations.py b/tests/unit/openpype/modules/sync_server/test_site_operations.py new file mode 100644 index 0000000000..7e1c994456 --- /dev/null +++ b/tests/unit/openpype/modules/sync_server/test_site_operations.py @@ -0,0 +1,164 @@ +"""Test file for Sync Server, tests site operations add_site, remove_site""" +import os +import pytest +from bson.objectid import ObjectId + +from tests.lib.DBHandler import DBHandler + +TEST_DB_NAME = "test_db" +TEST_PROJECT_NAME = "test_project" +TEST_OPENPYPE_NAME = "test_openpype" +REPRESENTATION_ID = "60e578d0c987036c6a7b741d" + + +@pytest.fixture(scope='session') +def monkeypatch_session(): + """Monkeypatch couldn't be used with module or session fixtures.""" + from _pytest.monkeypatch import MonkeyPatch + m = MonkeyPatch() + yield m + m.undo() + + +@pytest.fixture(scope="module") +def db_init(monkeypatch_session): + backup_dir = os.path.abspath( + os.path.join( + os.path.dirname(__file__), + 'fixture' + ) + ) + + uri = os.environ.get("OPENPYPE_MONGO") or "mongodb://localhost:27017" + db = DBHandler(uri) + db.setup_from_dump(TEST_DB_NAME, backup_dir, True, + db_name_out=TEST_DB_NAME) + + db.setup_from_dump("openpype", backup_dir, True, + db_name_out=TEST_OPENPYPE_NAME) + + # set needed env vars temporarily for tests + monkeypatch_session.setenv("OPENPYPE_MONGO", uri) + monkeypatch_session.setenv("AVALON_MONGO", uri) + monkeypatch_session.setenv("OPENPYPE_DATABASE_NAME", TEST_OPENPYPE_NAME) + monkeypatch_session.setenv("AVALON_TIMEOUT", '3000') + monkeypatch_session.setenv("AVALON_DB", TEST_DB_NAME) + monkeypatch_session.setenv("AVALON_PROJECT", TEST_PROJECT_NAME) + monkeypatch_session.setenv("PYPE_DEBUG", "3") + + +@pytest.fixture(scope="module") +def setup_avalon_db(db_init): + """Connect to Avalon, only after 'db_init' sets env vars.""" + from avalon.api import AvalonMongoDB + db = AvalonMongoDB() + yield db + + +@pytest.fixture(scope="module") +def setup_sync_server_module(db_init): + """Get sync_server_module from ModulesManager""" + from openpype.modules import ModulesManager + + manager = ModulesManager() + sync_server = manager.modules_by_name["sync_server"] + yield sync_server + + +@pytest.mark.usefixtures("setup_avalon_db") +def test_project_created(setup_avalon_db): + assert ['test_project'] == setup_avalon_db.database.collection_names(False) + + +@pytest.mark.usefixtures("setup_avalon_db") +def test_objects_imported(setup_avalon_db): + count_obj = len(list(setup_avalon_db.database[TEST_PROJECT_NAME].find({}))) + assert 15 == count_obj + + +@pytest.mark.usefixtures("setup_sync_server_module") +def test_add_site(setup_avalon_db, setup_sync_server_module): + """Adds 'test_site', checks that added, checks that doesn't duplicate.""" + query = { + "_id": ObjectId(REPRESENTATION_ID) + } + + ret = setup_avalon_db.database[TEST_PROJECT_NAME].find(query) + + assert 1 == len(list(ret)), \ + "Single {} must be in DB".format(REPRESENTATION_ID) + + setup_sync_server_module.add_site(TEST_PROJECT_NAME, REPRESENTATION_ID, + site_name='test_site') + + ret = list(setup_avalon_db.database[TEST_PROJECT_NAME].find(query)) + + assert 1 == len(ret), \ + "Single {} must be in DB".format(REPRESENTATION_ID) + + ret = ret.pop() + site_names = [site["name"] for site in ret["files"][0]["sites"]] + assert 'test_site' in site_names, "Site name wasn't added" + + +@pytest.mark.usefixtures("setup_sync_server_module") +def test_add_site_again(setup_avalon_db, setup_sync_server_module): + """Depends on test_add_site, must throw exception.""" + with pytest.raises(ValueError): + setup_sync_server_module.add_site(TEST_PROJECT_NAME, REPRESENTATION_ID, + site_name='test_site') + + +@pytest.mark.usefixtures("setup_sync_server_module") +def test_add_site_again_force(setup_avalon_db, setup_sync_server_module): + """Depends on test_add_site, must not throw exception.""" + setup_sync_server_module.add_site(TEST_PROJECT_NAME, REPRESENTATION_ID, + site_name='test_site', force=True) + + query = { + "_id": ObjectId(REPRESENTATION_ID) + } + + ret = list(setup_avalon_db.database[TEST_PROJECT_NAME].find(query)) + + assert 1 == len(ret), \ + "Single {} must be in DB".format(REPRESENTATION_ID) + + +@pytest.mark.usefixtures("setup_sync_server_module") +def test_remove_site(setup_avalon_db, setup_sync_server_module): + """Depends on test_add_site, must remove 'test_site'.""" + setup_sync_server_module.remove_site(TEST_PROJECT_NAME, REPRESENTATION_ID, + site_name='test_site') + + query = { + "_id": ObjectId(REPRESENTATION_ID) + } + + ret = list(setup_avalon_db.database[TEST_PROJECT_NAME].find(query)) + + assert 1 == len(ret), \ + "Single {} must be in DB".format(REPRESENTATION_ID) + + ret = ret.pop() + site_names = [site["name"] for site in ret["files"][0]["sites"]] + + assert 'test_site' not in site_names, "Site name wasn't removed" + + +@pytest.mark.usefixtures("setup_sync_server_module") +def test_remove_site_again(setup_avalon_db, setup_sync_server_module): + """Depends on test_add_site, must trow exception""" + with pytest.raises(ValueError): + setup_sync_server_module.remove_site(TEST_PROJECT_NAME, + REPRESENTATION_ID, + site_name='test_site') + + query = { + "_id": ObjectId(REPRESENTATION_ID) + } + + ret = list(setup_avalon_db.database[TEST_PROJECT_NAME].find(query)) + + assert 1 == len(ret), \ + "Single {} must be in DB".format(REPRESENTATION_ID)