Browse Source

Test OptinalManager plugin

shortcutme 7 years ago
parent
commit
0a2617cd21

+ 42 - 0
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

+ 1 - 0
plugins/OptionalManager/Test/conftest.py

@@ -0,0 +1 @@
+from src.Test.conftest import *

+ 5 - 0
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.