diff --git a/plugins/OptionalManager/Test/TestOptionalManager.py b/plugins/OptionalManager/Test/TestOptionalManager.py new file mode 100644 index 00000000..a61aa078 --- /dev/null +++ b/plugins/OptionalManager/Test/TestOptionalManager.py @@ -0,0 +1,42 @@ +import hashlib +import os +import copy + +import pytest + +from OptionalManager import OptionalManagerPlugin +from util import helper + + +@pytest.mark.usefixtures("resetSettings") +class TestOptionalManager: + def testDbFill(self, site): + contents = site.content_manager.contents + assert len(site.content_manager.hashfield) > 0 + assert contents.db.execute("SELECT COUNT(*) FROM file_optional WHERE is_downloaded = 1").fetchone()[0] == len(site.content_manager.hashfield) + + def testSetContent(self, site): + contents = site.content_manager.contents + + # Add new file + new_content = copy.deepcopy(contents["content.json"]) + new_content["files_optional"]["testfile"] = { + "size": 1234, + "sha512": "aaaabbbbcccc" + } + num_optional_files_before = contents.db.execute("SELECT COUNT(*) FROM file_optional").fetchone()[0] + contents["content.json"] = new_content + assert contents.db.execute("SELECT COUNT(*) FROM file_optional").fetchone()[0] > num_optional_files_before + + # Remove file + new_content = copy.deepcopy(contents["content.json"]) + del new_content["files_optional"]["testfile"] + num_optional_files_before = contents.db.execute("SELECT COUNT(*) FROM file_optional").fetchone()[0] + contents["content.json"] = new_content + assert contents.db.execute("SELECT COUNT(*) FROM file_optional").fetchone()[0] < num_optional_files_before + + def testDeleteContent(self, site): + contents = site.content_manager.contents + num_optional_files_before = contents.db.execute("SELECT COUNT(*) FROM file_optional").fetchone()[0] + del contents["content.json"] + assert contents.db.execute("SELECT COUNT(*) FROM file_optional").fetchone()[0] < num_optional_files_before diff --git a/plugins/OptionalManager/Test/conftest.py b/plugins/OptionalManager/Test/conftest.py new file mode 100644 index 00000000..8c1df5b2 --- /dev/null +++ b/plugins/OptionalManager/Test/conftest.py @@ -0,0 +1 @@ +from src.Test.conftest import * \ No newline at end of file diff --git a/plugins/OptionalManager/Test/pytest.ini b/plugins/OptionalManager/Test/pytest.ini new file mode 100644 index 00000000..d09210d1 --- /dev/null +++ b/plugins/OptionalManager/Test/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +python_files = Test*.py +addopts = -rsxX -v --durations=6 +markers = + webtest: mark a test as a webtest. \ No newline at end of file