mirror of
https://github.com/NewFuture/DDNS.git
synced 2026-10-20 08:17:43 +00:00
* Initial plan * feat(provider): add EdgeOne DNS provider for non-accelerated domains Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(provider): add EdgeOne DNS documentation for non-accelerated domains Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * fix(provider): update EdgeOne provider aliases per feedback - Acceleration domains: edgeone, edgeone_acc, teo_acc - DNS records: edgeone_dns, teo_dns, edgeone_noacc - Removed: teo, tencentedgeone, neo_acc, neo - Updated documentation to reflect new aliases Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * feat(provider): add extra parameter support and update documentation index - Add edgeone_dns to provider index documentation (README.md) - Add "teo" alias for backward compatibility (not documented) - Enable EdgeOneProvider to support both acceleration and DNS records via extra['dns_record'] parameter - Update provider aliases and documentation Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs: create comprehensive new-provider agent guide - Add detailed step-by-step guide for creating new DNS providers - Include API analysis, implementation, testing, and documentation steps - Provide code templates and examples for both BaseProvider and SimpleProvider - Add completion checklist and common pitfalls - Document all requirements including compatibility checks and index updates Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * refactor(provider): change extra parameter from dns_record to teoDomainType - Change EdgeOneProvider to use teoDomainType parameter instead of dns_record - Support values: "dns" or "acceleration" (default) - Parameter is case-insensitive - EdgeOneDnsProvider now uses extra parameter to control behavior - All 55 tests passing Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * refactor(provider): simplify EdgeOneDnsProvider with helper method - Extract common extra parameter preparation into _prepare_extra() method - Reduces code duplication across _query_record, _create_record, _update_record - All 55 tests passing Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * refactor(provider): make EdgeOneDnsProvider more elegant and concise - Use class attribute _default_domain_type = "dns" for clarity - Replace _prepare_extra() with inline setdefault() for more Pythonic code - setdefault() allows users to override teoDomainType if needed - All 55 tests passing Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * refactor(provider): use options instead of extra for teoDomainType - Move teoDomainType from per-call extra to instance-level options - More appropriate since provider type is fixed per instance - EdgeOneProvider reads teoDomainType from self.options at initialization - EdgeOneDnsProvider sets teoDomainType="dns" in __init__ - Simplified implementation: 28 lines vs 43 lines for EdgeOneDnsProvider - All 55 tests passing Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * refactor(provider): support both extra and options for teoDomainType with priority - Remove __init__ from EdgeOneProvider, read directly from self.options - Support teoDomainType in both extra (per-call) and options (initialization) - extra parameter has higher priority than options - Priority: extra > options > default ("acceleration") - All 55 tests passing Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(provider): add teoDomainType parameter documentation for EdgeOne - Document how to switch between acceleration domains and DNS records - Explain extra.teoDomainType parameter usage - Add configuration examples for both modes - Update parameter tables with teoDomainType and extra - Document priority: extra > initialization parameter - Add bilingual documentation (Chinese and English) Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(provider): remove initialization parameter config example from EdgeOne - Remove the example showing teoDomainType via initialization parameters - Only document usage via extra parameter - Remove priority note since only one method is documented - Keep recommendation to use EdgeOneDnsProvider for cleaner code - Update both Chinese and English documentation Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(agent): update new-provider guide with relative paths and schema notes - Update CLI compatibility note to mention checking --dns parameter choices - Change schema note to only require v4.0 (latest format) updates - Replace "multi-provider format" with "latest schema format" - Convert all absolute paths to relative paths from project root - Remove /home/runner/work/DDNS/DDNS/ prefix from all file paths Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(agent): correct latest schema version to v4.1 - Update schema compatibility section to reference v4.1 instead of v4.0 - v4.1 is the latest schema format that requires updates Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * feat(config): add edgeone_dns to CLI and schema v4.1 - Add edgeone_dns to CLI --dns parameter choices - Add edgeone_dns to schema v4.1 provider enum (both legacy and multi-provider sections) - Update provider descriptions to include EdgeOne DNS Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor labels_to_prompts_mapping format * fix(provider): filter teoDomainType from extra params before API call - Remove teoDomainType from extra dict before passing to Tencent Cloud API - Fixes "UnknownParameter - The parameter `extra_teoDomainType` is not recognized" error - teoDomainType is internal parameter for routing, not for API requests - All 55 tests passing Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(provider): update schema references to v4.1.json in EdgeOne docs - Update all $schema references from v4.0.json to v4.1.json - Applied to edgeone.md, edgeone.en.md, edgeone_dns.md, edgeone_dns.en.md - Ensures documentation references the latest schema format Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * Changes before error encountered Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * fix(config): preserve nested extra dict from JSON/ENV config - Process "extra" dict before extra_ prefixed keys to avoid flattening - Fixes issue where {"extra":{"teoDomainType":"dns"}} was incorrectly transformed to {"extra_teoDomainType":"dns"} - Maintains backward compatibility with extra_ prefixed keys - Priority: explicit extra dict > extra_ prefixed keys > unknown keys Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/test_provider_edgeone_dns.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/test_provider_edgeone_dns.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * style: apply ruff formatting fixes - Format 9 files with ruff - Fix 2 linting issues automatically - One complexity warning remains (C901) but doesn't affect functionality - All code now follows consistent formatting standards Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(agent): add ruff installation instructions to new-provider guide - Add pip3 install ruff command before formatting/linting steps - Ensures developers have required tools before running verification - Prevents common setup errors Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * docs(config): clarify extra dict and extra_ prefix priority within config sources - Add comments explaining that extra_ prefixed keys override nested extra dict values within the same source - Improves code documentation clarity for config flattening logic - Addresses feedback about intra-source priority ordering Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> * refactor(config): reduce complexity of _collect_extra method - Extract _process_extra_from_source helper method to reduce cyclomatic complexity - Fixes ruff C901 error (complexity was 14, now under threshold) - Maintains all existing functionality and test coverage - All 60 extra-related tests passing Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com> Co-authored-by: New Future <NewFuture@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
119 lines
4.8 KiB
Python
119 lines
4.8 KiB
Python
# coding=utf-8
|
|
"""
|
|
Unit tests for CLI extra field support in ddns.config.cli module
|
|
@author: GitHub Copilot
|
|
"""
|
|
|
|
import sys
|
|
from __init__ import unittest
|
|
from ddns.config.cli import load_config # noqa: E402
|
|
|
|
|
|
class TestCliExtraFields(unittest.TestCase):
|
|
"""Test CLI extra field parsing"""
|
|
|
|
def setUp(self):
|
|
"""Save original sys.argv"""
|
|
self.original_argv = sys.argv
|
|
|
|
def tearDown(self):
|
|
"""Restore original sys.argv"""
|
|
sys.argv = self.original_argv
|
|
|
|
def test_cli_extra_single_field(self):
|
|
"""Test single --extra.xxx argument"""
|
|
sys.argv = ["ddns", "--dns", "cloudflare", "--extra.proxied", "true"]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("dns"), "cloudflare")
|
|
self.assertEqual(config.get("extra_proxied"), "true")
|
|
|
|
def test_cli_extra_multiple_fields(self):
|
|
"""Test multiple --extra.xxx arguments"""
|
|
sys.argv = [
|
|
"ddns",
|
|
"--dns",
|
|
"cloudflare",
|
|
"--extra.proxied",
|
|
"true",
|
|
"--extra.comment",
|
|
"Test comment",
|
|
"--extra.priority",
|
|
"10",
|
|
]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("dns"), "cloudflare")
|
|
self.assertEqual(config.get("extra_proxied"), "true")
|
|
self.assertEqual(config.get("extra_comment"), "Test comment")
|
|
self.assertEqual(config.get("extra_priority"), "10")
|
|
|
|
def test_cli_extra_with_standard_args(self):
|
|
"""Test --extra.xxx mixed with standard arguments"""
|
|
sys.argv = [
|
|
"ddns",
|
|
"--dns",
|
|
"alidns",
|
|
"--id",
|
|
"test@example.com",
|
|
"--token",
|
|
"secret123",
|
|
"--extra.custom_field",
|
|
"custom_value",
|
|
"--ttl",
|
|
"300",
|
|
]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("dns"), "alidns")
|
|
self.assertEqual(config.get("id"), "test@example.com")
|
|
self.assertEqual(config.get("token"), "secret123")
|
|
self.assertEqual(config.get("ttl"), 300)
|
|
self.assertEqual(config.get("extra_custom_field"), "custom_value")
|
|
|
|
def test_cli_extra_flag_without_value(self):
|
|
"""Test --extra.xxx without a value (should be treated as True)"""
|
|
sys.argv = ["ddns", "--dns", "cloudflare", "--extra.enabled"]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("dns"), "cloudflare")
|
|
self.assertTrue(config.get("extra_enabled"))
|
|
|
|
def test_cli_extra_with_dots_in_name(self):
|
|
"""Test --extra.xxx.yyy format (nested key)"""
|
|
sys.argv = ["ddns", "--dns", "cloudflare", "--extra.settings.key1", "value1"]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("dns"), "cloudflare")
|
|
# The key should be settings.key1 (not nested object)
|
|
self.assertEqual(config.get("extra_settings.key1"), "value1")
|
|
|
|
def test_cli_extra_empty_value(self):
|
|
"""Test --extra.xxx with empty string value"""
|
|
sys.argv = ["ddns", "--dns", "cloudflare", "--extra.comment", ""]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("dns"), "cloudflare")
|
|
self.assertEqual(config.get("extra_comment"), "")
|
|
|
|
def test_cli_extra_numeric_values(self):
|
|
"""Test --extra.xxx with numeric string values"""
|
|
sys.argv = ["ddns", "--dns", "cloudflare", "--extra.priority", "100", "--extra.weight", "0.5"]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("extra_priority"), "100")
|
|
self.assertEqual(config.get("extra_weight"), "0.5")
|
|
|
|
def test_cli_extra_special_characters(self):
|
|
"""Test --extra.xxx with special characters in value"""
|
|
sys.argv = ["ddns", "--dns", "cloudflare", "--extra.url", "https://example.com/path?key=value"]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("extra_url"), "https://example.com/path?key=value")
|
|
|
|
def test_cli_no_extra_args(self):
|
|
"""Test that config works without any extra arguments"""
|
|
sys.argv = ["ddns", "--dns", "cloudflare", "--id", "test@example.com"]
|
|
config = load_config("Test DDNS", "Test doc", "1.0.0", "2025-07-04")
|
|
self.assertEqual(config.get("dns"), "cloudflare")
|
|
self.assertEqual(config.get("id"), "test@example.com")
|
|
# No extra_* keys should exist
|
|
extra_keys = [k for k in config.keys() if k.startswith("extra_")]
|
|
self.assertEqual(len(extra_keys), 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|