Working tests.
This commit is contained in:
parent
ce8012779b
commit
d4aee28247
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.coverage
|
||||||
|
.env
|
||||||
|
__pycache__/
|
||||||
|
logs/
|
||||||
@ -52,7 +52,7 @@ COPY --from=builder /install /usr/local
|
|||||||
|
|
||||||
# Copy application files
|
# Copy application files
|
||||||
COPY main.py .
|
COPY main.py .
|
||||||
COPY config.py .
|
COPY gunicorn_config.py .
|
||||||
COPY .env.example .env
|
COPY .env.example .env
|
||||||
|
|
||||||
# Create necessary directories
|
# Create necessary directories
|
||||||
|
|||||||
26
conftest.py
Normal file
26
conftest.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"""
|
||||||
|
Pytest configuration for WebDAV server tests
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
# Configure pytest-asyncio
|
||||||
|
def pytest_configure(config):
|
||||||
|
"""Configure pytest with custom settings"""
|
||||||
|
config.addinivalue_line(
|
||||||
|
"markers", "asyncio: mark test as an asyncio test"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def event_loop():
|
||||||
|
"""Create an instance of the default event loop for the test session."""
|
||||||
|
loop = asyncio.get_event_loop_policy().new_event_loop()
|
||||||
|
yield loop
|
||||||
|
loop.close()
|
||||||
|
|
||||||
|
|
||||||
|
# Set asyncio mode
|
||||||
|
pytest_plugins = ('pytest_asyncio',)
|
||||||
14
main.py
14
main.py
@ -679,7 +679,8 @@ class WebDAVHandler:
|
|||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=207,
|
status=207,
|
||||||
content_type='application/xml; charset=utf-8',
|
content_type='application/xml',
|
||||||
|
charset='utf-8',
|
||||||
text='<?xml version="1.0" encoding="utf-8"?>\n' + xml_response,
|
text='<?xml version="1.0" encoding="utf-8"?>\n' + xml_response,
|
||||||
headers={
|
headers={
|
||||||
'DAV': '1, 2, 3',
|
'DAV': '1, 2, 3',
|
||||||
@ -786,7 +787,8 @@ class WebDAVHandler:
|
|||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=207,
|
status=207,
|
||||||
content_type='application/xml; charset=utf-8',
|
content_type='application/xml',
|
||||||
|
charset='utf-8',
|
||||||
text='<?xml version="1.0" encoding="utf-8"?>\n' + xml_response
|
text='<?xml version="1.0" encoding="utf-8"?>\n' + xml_response
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -923,7 +925,8 @@ class WebDAVHandler:
|
|||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=200,
|
status=200,
|
||||||
content_type='application/xml; charset=utf-8',
|
content_type='application/xml',
|
||||||
|
charset='utf-8',
|
||||||
text=response_xml,
|
text=response_xml,
|
||||||
headers={
|
headers={
|
||||||
'Lock-Token': f'<{lock_token}>',
|
'Lock-Token': f'<{lock_token}>',
|
||||||
@ -1007,9 +1010,10 @@ async def webdav_middleware(app, handler):
|
|||||||
"""Middleware to handle authentication and routing"""
|
"""Middleware to handle authentication and routing"""
|
||||||
|
|
||||||
async def middleware_handler(request: web.Request):
|
async def middleware_handler(request: web.Request):
|
||||||
# Skip authentication for OPTIONS preflight
|
# Handle OPTIONS without authentication
|
||||||
if request.method == 'OPTIONS':
|
if request.method == 'OPTIONS':
|
||||||
return await handler(request)
|
webdav = app['webdav']
|
||||||
|
return await webdav.handle_options(request, {})
|
||||||
|
|
||||||
# Authenticate user
|
# Authenticate user
|
||||||
user = await app['auth'].authenticate(request)
|
user = await app['auth'].authenticate(request)
|
||||||
|
|||||||
@ -4,10 +4,7 @@
|
|||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
# Upstream backend
|
# Upstream backend
|
||||||
upstream webdav_backend {
|
|
||||||
server webdav:8080 max_fails=3 fail_timeout=30s;
|
|
||||||
keepalive 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
# HTTP Server - Redirect to HTTPS
|
# HTTP Server - Redirect to HTTPS
|
||||||
server {
|
server {
|
||||||
@ -19,7 +16,10 @@ server {
|
|||||||
location /.well-known/acme-challenge/ {
|
location /.well-known/acme-challenge/ {
|
||||||
root /var/www/certbot;
|
root /var/www/certbot;
|
||||||
}
|
}
|
||||||
|
upstream webdav_backend {
|
||||||
|
server webdav:8080 max_fails=3 fail_timeout=30s;
|
||||||
|
keepalive 32;
|
||||||
|
}
|
||||||
# Redirect all other traffic to HTTPS
|
# Redirect all other traffic to HTTPS
|
||||||
location / {
|
location / {
|
||||||
return 301 https://$server_name$request_uri;
|
return 301 https://$server_name$request_uri;
|
||||||
52
pytest.ini
Normal file
52
pytest.ini
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
[pytest]
|
||||||
|
# Pytest configuration for WebDAV server tests
|
||||||
|
|
||||||
|
# Asyncio configuration
|
||||||
|
asyncio_mode = auto
|
||||||
|
asyncio_default_fixture_loop_scope = function
|
||||||
|
|
||||||
|
# Test discovery patterns
|
||||||
|
python_files = test_*.py *_test.py
|
||||||
|
python_classes = Test*
|
||||||
|
python_functions = test_*
|
||||||
|
|
||||||
|
# Minimum version
|
||||||
|
minversion = 7.0
|
||||||
|
|
||||||
|
# Add current directory to Python path
|
||||||
|
pythonpath = .
|
||||||
|
|
||||||
|
# Test output options
|
||||||
|
addopts =
|
||||||
|
-v
|
||||||
|
--strict-markers
|
||||||
|
--tb=short
|
||||||
|
--disable-warnings
|
||||||
|
-p no:warnings
|
||||||
|
|
||||||
|
# Markers
|
||||||
|
markers =
|
||||||
|
asyncio: mark test as an asyncio test
|
||||||
|
slow: mark test as slow running
|
||||||
|
integration: mark test as integration test
|
||||||
|
unit: mark test as unit test
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
log_cli = false
|
||||||
|
log_cli_level = INFO
|
||||||
|
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s
|
||||||
|
log_cli_date_format = %Y-%m-%d %H:%M:%S
|
||||||
|
|
||||||
|
# Coverage options (if using pytest-cov)
|
||||||
|
[coverage:run]
|
||||||
|
source = .
|
||||||
|
omit =
|
||||||
|
*/tests/*
|
||||||
|
*/test_*.py
|
||||||
|
*/.venv/*
|
||||||
|
*/venv/*
|
||||||
|
|
||||||
|
[coverage:report]
|
||||||
|
precision = 2
|
||||||
|
show_missing = True
|
||||||
|
skip_covered = False
|
||||||
@ -4,6 +4,7 @@ Tests all WebDAV methods, authentication, and edge cases
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
import asyncio
|
import asyncio
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
@ -22,7 +23,7 @@ from main import Database, AuthHandler, WebDAVHandler, init_app, Config
|
|||||||
# Fixtures
|
# Fixtures
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
async def temp_dir():
|
async def temp_dir():
|
||||||
"""Create temporary directory for tests"""
|
"""Create temporary directory for tests"""
|
||||||
temp_path = Path(tempfile.mkdtemp())
|
temp_path = Path(tempfile.mkdtemp())
|
||||||
@ -30,7 +31,7 @@ async def temp_dir():
|
|||||||
shutil.rmtree(temp_path, ignore_errors=True)
|
shutil.rmtree(temp_path, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
async def test_db(temp_dir):
|
async def test_db(temp_dir):
|
||||||
"""Create test database"""
|
"""Create test database"""
|
||||||
db_path = temp_dir / 'test.db'
|
db_path = temp_dir / 'test.db'
|
||||||
@ -43,7 +44,7 @@ async def test_db(temp_dir):
|
|||||||
yield db
|
yield db
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
async def test_app(test_db, temp_dir, monkeypatch):
|
async def test_app(test_db, temp_dir, monkeypatch):
|
||||||
"""Create test application"""
|
"""Create test application"""
|
||||||
# Override config for testing
|
# Override config for testing
|
||||||
@ -60,7 +61,7 @@ async def test_app(test_db, temp_dir, monkeypatch):
|
|||||||
yield app
|
yield app
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
async def client(test_app):
|
async def client(test_app):
|
||||||
"""Create test client"""
|
"""Create test client"""
|
||||||
server = TestServer(test_app)
|
server = TestServer(test_app)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user