diff --git a/tests/__init__.py b/tests/__init__.py index e69de29bb..b3955bbcc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,6 @@ +import sys +import os + +sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) # Ensure tests/ is in sys.path +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) # Ensure project root is in sys.path + diff --git a/tests/common.py b/tests/common.py deleted file mode 100644 index abfb89874..000000000 --- a/tests/common.py +++ /dev/null @@ -1,9 +0,0 @@ -import unittest -from pathlib import Path - -from conftest import nettacker_dir, tests_dir - - -class TestCase(unittest.TestCase): - nettacker_path = Path(nettacker_dir) - tests_path = Path(tests_dir) diff --git a/tests/conftest.py b/tests/conftest.py index c30b36bf5..ae66928e0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,9 @@ import sys -from os.path import abspath, dirname, join +from pathlib import Path -project_root = dirname(dirname(__file__)) -nettacker_dir = abspath(join(project_root, "src/nettacker")) -tests_dir = abspath(join(project_root, "tests")) +project_root = Path(__file__).resolve().parent.parent +nettacker_dir = project_root / "src" / "nettacker" +tests_dir = project_root / "tests" -sys.path.insert(0, nettacker_dir) -sys.path.insert(1, tests_dir) +sys.path.insert(0, str(nettacker_dir)) +sys.path.insert(1, str(tests_dir)) diff --git a/tests/lib/payloads/test_passwords.py b/tests/lib/payloads/test_passwords.py index c819478ab..d21434d73 100644 --- a/tests/lib/payloads/test_passwords.py +++ b/tests/lib/payloads/test_passwords.py @@ -1,16 +1,16 @@ from collections import Counter - import pytest - -from tests.common import TestCase - +from tests.test_common import TestCase class TestPasswords(TestCase): - top_1000_common_passwords_path = "lib/payloads/passwords/top_1000_common_passwords.txt" + + def setUp(self): + super().setUp() # Call parent setup to ensure nettacker_path is set + self.top_1000_common_passwords_path = self.nettacker_path / "lib" / "payloads" / "passwords" / "top_1000_common_passwords.txt" @pytest.mark.xfail(reason="It currently contains 1001 passwords.") def test_top_1000_common_passwords(self): - with open(self.nettacker_path / self.top_1000_common_passwords_path) as top_1000_file: + with open(self.top_1000_common_passwords_path) as top_1000_file: top_1000_passwords = [line.strip() for line in top_1000_file.readlines()] self.assertEqual(len(top_1000_passwords), 1000, "There should be exactly 1000 passwords") diff --git a/tests/test_common.py b/tests/test_common.py new file mode 100644 index 000000000..f06c77824 --- /dev/null +++ b/tests/test_common.py @@ -0,0 +1,21 @@ +import unittest +from pathlib import Path + +class TestCase(unittest.TestCase): + def setUp(self): + # Fix the paths + self.project_root = Path(__file__).resolve().parent.parent # Go up from 'tests' + self.nettacker_path = self.project_root / "nettacker" # Correct location + self.tests_path = self.project_root / "tests" + + # Debugging information + print(f"DEBUG: Expected nettacker_path: {self.nettacker_path}") + print(f"DEBUG: Expected tests_path: {self.tests_path}") + + def test_paths_exist(self): + # Check if paths exist + self.assertTrue(self.nettacker_path.exists(), f"Nettacker directory does not exist: {self.nettacker_path}") + self.assertTrue(self.tests_path.exists(), f"Tests directory does not exist: {self.tests_path}") + +if __name__ == "__main__": + unittest.main()