mirror of
https://github.com/Ekultek/Zeus-Scanner.git
synced 2026-03-11 08:55:51 +00:00
- Migrated from requirements.txt to Poetry package management - Added pytest, pytest-cov, and pytest-mock as dev dependencies - Configured pytest with coverage reporting (80% threshold) - Created test directory structure with unit/integration subdirectories - Added comprehensive test fixtures in conftest.py - Updated .gitignore with testing and build artifacts - Added Poetry script commands for running tests - Updated dependencies to modern compatible versions
142 lines
No EOL
4.8 KiB
Python
142 lines
No EOL
4.8 KiB
Python
"""Validation tests to verify the testing infrastructure is properly set up."""
|
|
|
|
import pytest
|
|
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import Mock
|
|
|
|
|
|
class TestInfrastructureValidation:
|
|
"""Test class to validate the testing infrastructure."""
|
|
|
|
def test_pytest_is_available(self):
|
|
"""Verify pytest is installed and working."""
|
|
assert pytest.__version__
|
|
assert int(pytest.__version__.split('.')[0]) >= 7
|
|
|
|
def test_fixtures_are_available(self, temp_dir, mock_config):
|
|
"""Verify custom fixtures are accessible."""
|
|
assert isinstance(temp_dir, Path)
|
|
assert temp_dir.exists()
|
|
assert temp_dir.is_dir()
|
|
|
|
assert isinstance(mock_config, Mock)
|
|
assert hasattr(mock_config, 'debug')
|
|
assert mock_config.debug is False
|
|
|
|
def test_markers_are_defined(self):
|
|
"""Verify pytest markers are configured."""
|
|
markers = pytest.mark._markers
|
|
assert 'unit' in markers
|
|
assert 'integration' in markers
|
|
assert 'slow' in markers
|
|
|
|
@pytest.mark.unit
|
|
def test_unit_marker_works(self):
|
|
"""Test that unit marker can be used."""
|
|
assert True
|
|
|
|
@pytest.mark.integration
|
|
def test_integration_marker_works(self):
|
|
"""Test that integration marker can be used."""
|
|
assert True
|
|
|
|
@pytest.mark.slow
|
|
def test_slow_marker_works(self):
|
|
"""Test that slow marker can be used."""
|
|
assert True
|
|
|
|
def test_coverage_is_configured(self):
|
|
"""Verify coverage is properly configured."""
|
|
import sys
|
|
# Coverage should be running if pytest-cov is installed
|
|
assert any('coverage' in str(mod) for mod in sys.modules)
|
|
|
|
def test_mock_fixtures_work(self, mock_response, mock_requests):
|
|
"""Verify mock fixtures are functioning."""
|
|
assert mock_response.status_code == 200
|
|
assert mock_response.text
|
|
assert 'Server' in mock_response.headers
|
|
|
|
assert hasattr(mock_requests, 'get')
|
|
assert hasattr(mock_requests, 'post')
|
|
|
|
def test_sample_data_fixtures(self, sample_html, sample_headers, sample_urls):
|
|
"""Verify sample data fixtures provide expected data."""
|
|
assert '<html>' in sample_html
|
|
assert '<form' in sample_html
|
|
|
|
assert 'Server' in sample_headers
|
|
assert 'Content-Type' in sample_headers
|
|
|
|
assert len(sample_urls) > 0
|
|
assert all(url.startswith('http') for url in sample_urls)
|
|
|
|
def test_file_operations(self, temp_dir, test_file):
|
|
"""Verify file operation fixtures work correctly."""
|
|
assert test_file.exists()
|
|
assert test_file.is_file()
|
|
assert test_file.parent == temp_dir
|
|
|
|
content = test_file.read_text()
|
|
assert 'Test content' in content
|
|
assert len(content.splitlines()) == 3
|
|
|
|
def test_environment_fixture(self, env_vars):
|
|
"""Verify environment variable fixture works."""
|
|
import os
|
|
|
|
env_vars(TEST_VAR='test_value', TEST_NUM='42')
|
|
assert os.environ.get('TEST_VAR') == 'test_value'
|
|
assert os.environ.get('TEST_NUM') == '42'
|
|
|
|
env_vars(TEST_VAR=None)
|
|
assert os.environ.get('TEST_VAR') is None
|
|
|
|
def test_output_capture(self, captured_output):
|
|
"""Verify output capture fixture works."""
|
|
stdout, stderr = captured_output
|
|
|
|
print("Test stdout")
|
|
import sys
|
|
print("Test stderr", file=sys.stderr)
|
|
|
|
stdout.seek(0)
|
|
stderr.seek(0)
|
|
|
|
assert stdout.read().strip() == "Test stdout"
|
|
assert stderr.read().strip() == "Test stderr"
|
|
|
|
|
|
class TestProjectStructure:
|
|
"""Validate the project structure is correct."""
|
|
|
|
def test_test_directories_exist(self):
|
|
"""Verify test directories are created."""
|
|
base_path = Path(__file__).parent
|
|
assert base_path.exists()
|
|
assert (base_path / '__init__.py').exists()
|
|
assert (base_path / 'unit').exists()
|
|
assert (base_path / 'unit' / '__init__.py').exists()
|
|
assert (base_path / 'integration').exists()
|
|
assert (base_path / 'integration' / '__init__.py').exists()
|
|
|
|
def test_conftest_exists(self):
|
|
"""Verify conftest.py is in place."""
|
|
conftest_path = Path(__file__).parent / 'conftest.py'
|
|
assert conftest_path.exists()
|
|
assert conftest_path.stat().st_size > 0
|
|
|
|
def test_project_packages_importable(self):
|
|
"""Verify project packages can be imported."""
|
|
try:
|
|
import lib
|
|
import var
|
|
assert lib.__file__
|
|
assert var.__file__
|
|
except ImportError as e:
|
|
pytest.fail(f"Failed to import project packages: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__, "-v"]) |