You've already forked directdnsonly
- Migrated from setuptools to Poetry; added pyproject.toml, poetry.lock, poetry.toml and .python-version (Python 3.11.12) - Built out full directdnsonly Python package with BIND and CoreDNS MySQL backends, CherryPy REST API, persist-queue worker, and vyper-based config - Auth credentials now read from config/env (app.auth_username/password) rather than hardcoded; override via DADNS_APP_AUTH_PASSWORD env var - Added Dockerfile.deepseek: Python 3.11 slim + BIND9 + Poetry install - Rewrote docker-compose.yml for local dev stack (MySQL + dadns services) - Added SQL schema, docker/ BIND configs, justfile, tests, and README - Expanded .gitignore for Poetry/Python project artifacts
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import pytest
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import scoped_session, sessionmaker
|
|
|
|
from directdnsonly.app.backends.coredns_mysql import CoreDNSMySQLBackend, CoreDNSRecord
|
|
from loguru import logger
|
|
|
|
|
|
@pytest.fixture
|
|
def mysql_backend(tmp_path):
|
|
# Setup in-memory SQLite for testing (replace with test MySQL in CI)
|
|
engine = create_engine("sqlite:///:memory:")
|
|
CoreDNSRecord.metadata.create_all(engine)
|
|
|
|
class TestBackend(CoreDNSMySQLBackend):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.engine = engine
|
|
self.Session = scoped_session(sessionmaker(bind=engine))
|
|
|
|
yield TestBackend()
|
|
engine.dispose()
|
|
|
|
|
|
def test_zone_operations(mysql_backend):
|
|
zone_data = """
|
|
example.com. 300 IN SOA ns.example.com. admin.example.com. (2023 3600 1800 604800 86400)
|
|
example.com. 300 IN A 192.0.2.1
|
|
"""
|
|
# Test zone creation
|
|
assert mysql_backend.write_zone("example.com", zone_data)
|
|
assert mysql_backend.zone_exists("example.com")
|
|
|
|
# Test record update
|
|
updated_zone = """
|
|
example.com. 3600 IN A 192.0.2.1
|
|
example.com. 300 IN AAAA 2001:db8::1
|
|
"""
|
|
assert mysql_backend.write_zone("example.com", updated_zone)
|
|
|
|
# Test record removal
|
|
reduced_zone = "example.com. 300 IN A 192.0.2.1"
|
|
assert mysql_backend.write_zone("example.com", reduced_zone)
|
|
|
|
# Test zone deletion
|
|
assert mysql_backend.delete_zone("example.com")
|
|
assert not mysql_backend.zone_exists("example.com") |