Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Claude Code
.claude/*
616 changes: 616 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[tool.poetry]
name = "fancode-project"
version = "0.1.0"
description = "Fancode streaming project"
authors = ["Developer <dev@example.com>"]
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.8"
pycryptodome = "3.19.0"
pytz = "2023.3.post1"
requests = "2.31.0"
urllib3 = "2.0.6"
pyzipper = "0.3.6"
diskcache = "5.6.3"
beautifulsoup4 = "4.12.3"
cachetools = "5.3.3"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"--strict-markers",
"--strict-config",
"--verbose",
"--tb=short",
"--cov=./",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=80"
]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Slow running tests"
]

[tool.coverage.run]
source = ["."]
omit = [
"*/tests/*",
"*/test_*",
"*/__init__.py",
"*/conftest.py",
"*/venv/*",
"*/.venv/*",
"decrypt.py"
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:"
]
Empty file added tests/__init__.py
Empty file.
130 changes: 130 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import pytest
import tempfile
import shutil
from pathlib import Path
from unittest.mock import Mock, patch


@pytest.fixture
def temp_dir():
"""Provides a temporary directory for test files."""
temp_path = Path(tempfile.mkdtemp())
yield temp_path
shutil.rmtree(temp_path)


@pytest.fixture
def temp_file(temp_dir):
"""Provides a temporary file path."""
file_path = temp_dir / "test_file.txt"
yield file_path
if file_path.exists():
file_path.unlink()


@pytest.fixture
def mock_requests():
"""Provides a mock requests module."""
with patch("requests.get") as mock_get, \
patch("requests.post") as mock_post, \
patch("requests.put") as mock_put, \
patch("requests.delete") as mock_delete:

mock_response = Mock()
mock_response.status_code = 200
mock_response.json.return_value = {"status": "success"}
mock_response.text = "mock response"

mock_get.return_value = mock_response
mock_post.return_value = mock_response
mock_put.return_value = mock_response
mock_delete.return_value = mock_response

yield {
"get": mock_get,
"post": mock_post,
"put": mock_put,
"delete": mock_delete,
"response": mock_response
}


@pytest.fixture
def mock_os_environ():
"""Provides a mock os.environ for testing environment variables."""
with patch.dict("os.environ", {"password": "test_password", "TEST_VAR": "test_value"}):
yield


@pytest.fixture
def sample_zip_file(temp_dir):
"""Creates a sample zip file for testing."""
import zipfile

zip_path = temp_dir / "test.zip"
test_content = "This is test content"

with zipfile.ZipFile(zip_path, 'w') as zf:
zf.writestr("test.txt", test_content)

return zip_path


@pytest.fixture
def mock_cache():
"""Provides a mock cache object."""
cache_mock = Mock()
cache_mock.get.return_value = None
cache_mock.set.return_value = True
cache_mock.delete.return_value = True
cache_mock.clear.return_value = True
return cache_mock


@pytest.fixture
def sample_html():
"""Provides sample HTML content for BeautifulSoup testing."""
return """
<html>
<head><title>Test Page</title></head>
<body>
<div class="content">
<h1>Test Header</h1>
<p>Test paragraph</p>
<a href="https://example.com">Test Link</a>
</div>
</body>
</html>
"""


@pytest.fixture
def mock_file_operations():
"""Provides mocks for file operations."""
with patch("builtins.open", create=True) as mock_open, \
patch("os.path.exists") as mock_exists, \
patch("os.remove") as mock_remove, \
patch("os.system") as mock_system:

mock_exists.return_value = True
mock_remove.return_value = None
mock_system.return_value = 0

yield {
"open": mock_open,
"exists": mock_exists,
"remove": mock_remove,
"system": mock_system
}


@pytest.fixture(autouse=True)
def cleanup_test_files():
"""Automatically cleanup any test files created during tests."""
yield

# Clean up any test files that might have been created
test_files = ["test_output.txt", "temp_test_file.txt"]
for file_path in test_files:
if Path(file_path).exists():
Path(file_path).unlink()
Empty file added tests/integration/__init__.py
Empty file.
140 changes: 140 additions & 0 deletions tests/test_setup_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
Validation tests to ensure the testing infrastructure is properly set up.
These tests verify that all testing components are working correctly.
"""

import pytest
import sys
from pathlib import Path


class TestSetupValidation:
"""Test class to validate the testing infrastructure setup."""

def test_pytest_is_working(self):
"""Validate that pytest is properly installed and working."""
assert True, "pytest is working correctly"

def test_pytest_markers(self):
"""Validate that custom pytest markers are configured."""
# This test itself uses a marker to verify marker functionality
pass

@pytest.mark.unit
def test_unit_marker(self):
"""Validate unit test marker is working."""
assert True, "Unit marker is working"

@pytest.mark.integration
def test_integration_marker(self):
"""Validate integration test marker is working."""
assert True, "Integration marker is working"

@pytest.mark.slow
def test_slow_marker(self):
"""Validate slow test marker is working."""
assert True, "Slow marker is working"

def test_fixtures_are_available(self, temp_dir, temp_file):
"""Validate that conftest.py fixtures are working."""
# Test temp_dir fixture
assert temp_dir.exists(), "temp_dir fixture is not working"
assert temp_dir.is_dir(), "temp_dir should be a directory"

# Test temp_file fixture
assert temp_file.parent == temp_dir, "temp_file should be in temp_dir"

# Create and test file
temp_file.write_text("test content")
assert temp_file.exists(), "temp_file creation failed"
assert temp_file.read_text() == "test content", "temp_file content mismatch"

def test_mock_requests_fixture(self, mock_requests):
"""Validate that mock_requests fixture is working."""
# Test that all request methods are mocked
assert "get" in mock_requests, "GET method not mocked"
assert "post" in mock_requests, "POST method not mocked"
assert "put" in mock_requests, "PUT method not mocked"
assert "delete" in mock_requests, "DELETE method not mocked"
assert "response" in mock_requests, "Mock response not available"

# Test mock response properties
response = mock_requests["response"]
assert response.status_code == 200, "Mock response status code incorrect"
assert response.json()["status"] == "success", "Mock response JSON incorrect"

def test_mock_os_environ_fixture(self, mock_os_environ):
"""Validate that mock_os_environ fixture is working."""
import os
assert os.environ.get("password") == "test_password", "Mock environment variable not set"
assert os.environ.get("TEST_VAR") == "test_value", "Mock test variable not set"

def test_mock_cache_fixture(self, mock_cache):
"""Validate that mock_cache fixture is working."""
# Test cache methods
assert mock_cache.get("test_key") is None, "Mock cache get not working"
assert mock_cache.set("test_key", "test_value") is True, "Mock cache set not working"
assert mock_cache.delete("test_key") is True, "Mock cache delete not working"
assert mock_cache.clear() is True, "Mock cache clear not working"

def test_sample_html_fixture(self, sample_html):
"""Validate that sample_html fixture is working."""
from bs4 import BeautifulSoup

soup = BeautifulSoup(sample_html, 'html.parser')
assert soup.find('title').text == "Test Page", "Sample HTML title incorrect"
assert soup.find('h1').text == "Test Header", "Sample HTML header incorrect"
assert soup.find('a')['href'] == "https://example.com", "Sample HTML link incorrect"

def test_mock_file_operations_fixture(self, mock_file_operations):
"""Validate that mock_file_operations fixture is working."""
mocks = mock_file_operations

# Test that all file operations are mocked
assert "open" in mocks, "open not mocked"
assert "exists" in mocks, "exists not mocked"
assert "remove" in mocks, "remove not mocked"
assert "system" in mocks, "system not mocked"

def test_project_structure(self):
"""Validate that the project structure is correct."""
project_root = Path(__file__).parent.parent

# Check required files exist
assert (project_root / "pyproject.toml").exists(), "pyproject.toml not found"
assert (project_root / "tests").exists(), "tests directory not found"
assert (project_root / "tests" / "conftest.py").exists(), "conftest.py not found"
assert (project_root / "tests" / "unit").exists(), "unit tests directory not found"
assert (project_root / "tests" / "integration").exists(), "integration tests directory not found"

# Check __init__.py files
assert (project_root / "tests" / "__init__.py").exists(), "tests/__init__.py not found"
assert (project_root / "tests" / "unit" / "__init__.py").exists(), "tests/unit/__init__.py not found"
assert (project_root / "tests" / "integration" / "__init__.py").exists(), "tests/integration/__init__.py not found"

def test_python_version(self):
"""Validate that Python version meets requirements."""
# Assuming Python 3.8+ is required based on pyproject.toml
assert sys.version_info >= (3, 8), f"Python 3.8+ required, but running {sys.version}"

def test_dependencies_available(self):
"""Validate that all required dependencies are importable."""
# Test core dependencies
try:
import requests
import pytz
import pyzipper
import diskcache
import cachetools
from bs4 import BeautifulSoup
from Crypto.Cipher import AES # pycryptodome
except ImportError as e:
pytest.fail(f"Required dependency not available: {e}")

# Test testing dependencies
try:
import pytest
import pytest_cov
import pytest_mock
except ImportError as e:
pytest.fail(f"Required testing dependency not available: {e}")
Empty file added tests/unit/__init__.py
Empty file.