mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
YamlProvider idna/utf-8 support, prefers utf8
This commit is contained in:
@@ -15,7 +15,9 @@ from unittest import TestCase
|
||||
from yaml import safe_load
|
||||
from yaml.constructor import ConstructorError
|
||||
|
||||
from octodns.idna import idna_encode
|
||||
from octodns.record import Create
|
||||
from octodns.provider import ProviderException
|
||||
from octodns.provider.base import Plan
|
||||
from octodns.provider.yaml import (
|
||||
_list_all_yaml_files,
|
||||
@@ -172,6 +174,40 @@ class TestYamlProvider(TestCase):
|
||||
# make sure nothing is left
|
||||
self.assertEqual([], list(data.keys()))
|
||||
|
||||
def test_idna_filenames(self):
|
||||
with TemporaryDirectory() as td:
|
||||
name = 'déjà.vu.'
|
||||
filename = f'{name}yaml'
|
||||
|
||||
provider = YamlProvider('test', td.dirname)
|
||||
zone = Zone(idna_encode(name), [])
|
||||
|
||||
# create a idna named file
|
||||
with open(join(td.dirname, idna_encode(filename)), 'w') as fh:
|
||||
pass
|
||||
|
||||
fh.write(
|
||||
'''---
|
||||
'':
|
||||
type: A
|
||||
value: 1.2.3.4
|
||||
'''
|
||||
)
|
||||
|
||||
# populates fine when there's just the idna version (as a fallback)
|
||||
provider.populate(zone)
|
||||
self.assertEqual(1, len(zone.records))
|
||||
|
||||
# create a utf8 named file
|
||||
with open(join(td.dirname, filename), 'w') as fh:
|
||||
pass
|
||||
|
||||
# does not allow both idna and utf8 named files
|
||||
with self.assertRaises(ProviderException) as ctx:
|
||||
provider.populate(zone)
|
||||
msg = str(ctx.exception)
|
||||
self.assertTrue('Both UTF-8' in msg)
|
||||
|
||||
def test_empty(self):
|
||||
source = YamlProvider(
|
||||
'test', join(dirname(__file__), 'config'), supports_root_ns=False
|
||||
|
||||
Reference in New Issue
Block a user