74 lines
1.9 KiB
Python
74 lines
1.9 KiB
Python
import os
|
|
import shutil
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
from dns_sync.registry import (
|
|
configured_adapter_endpoints,
|
|
load_adapter,
|
|
)
|
|
|
|
|
|
class PluginTemplateTests(unittest.TestCase):
|
|
def test_template_loads_as_external_plugin(self):
|
|
source = Path("examples/plugin_template")
|
|
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
plugin = root / "example"
|
|
|
|
shutil.copytree(
|
|
source,
|
|
plugin,
|
|
)
|
|
|
|
with patch.dict(
|
|
os.environ,
|
|
{
|
|
"ENABLED_PLUGINS": "example",
|
|
"DNS_SYNC_PLUGIN_PATH": directory,
|
|
"EXAMPLE_ENDPOINTS": "example.test",
|
|
},
|
|
clear=True,
|
|
):
|
|
config = SimpleNamespace()
|
|
|
|
endpoints = configured_adapter_endpoints(
|
|
"example",
|
|
config,
|
|
)
|
|
|
|
self.assertEqual(
|
|
tuple(
|
|
endpoint.identity
|
|
for endpoint in endpoints
|
|
),
|
|
("example://example.test:443",),
|
|
)
|
|
|
|
adapter = load_adapter(
|
|
"example",
|
|
config,
|
|
endpoints[0],
|
|
)
|
|
|
|
self.assertEqual(
|
|
adapter.name,
|
|
"example",
|
|
)
|
|
self.assertEqual(
|
|
adapter.endpoint,
|
|
endpoints[0],
|
|
)
|
|
self.assertEqual(
|
|
adapter.client.endpoint,
|
|
endpoints[0],
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|