Browse Source

Clean up context cases, full test coverage

pull/1029/head
Ross McFarland 2 years ago
parent
commit
ebe9374405
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
3 changed files with 72 additions and 19 deletions
  1. +13
    -18
      octodns/manager.py
  2. +3
    -1
      tests/test_octodns_manager.py
  3. +56
    -0
      tests/test_octodns_record.py

+ 13
- 18
octodns/manager.py View File

@ -254,15 +254,14 @@ class Manager(object):
def _config_plan_outputs(self, plan_outputs_config):
plan_outputs = {}
for plan_output_name, plan_output_config in plan_outputs_config.items():
context = getattr(plan_output_config, 'context', None)
context = getattr(plan_output_config, 'context', '')
try:
_class = plan_output_config.pop('class')
except KeyError:
self.log.exception('Invalid plan_output class')
msg = f'plan_output {plan_output_name} is missing class'
if context:
msg += f', {context}'
raise ManagerException(msg)
raise ManagerException(
f'plan_output {plan_output_name} is missing class, {context}'
)
_class, module, version = self._get_named_class(
'plan_output', _class, context
)
@ -281,10 +280,9 @@ class Manager(object):
)
except TypeError:
self.log.exception('Invalid plan_output config')
msg = f'Incorrect plan_output config for {plan_output_name}'
if context:
msg += f', {plan_output_config.context}'
raise ManagerException(msg)
raise ManagerException(
f'Incorrect plan_output config for {plan_output_name}, {context}'
)
return plan_outputs
@ -324,10 +322,9 @@ class Manager(object):
self.log.exception(
'_get_{}_class: Unable to import module %s', _class
)
msg = f'Unknown {_type} class: {_class}'
if context:
msg += f', {context}'
raise ManagerException(msg)
raise ManagerException(
f'Unknown {_type} class: {_class}, {context}'
)
try:
return getattr(module, class_name), module_name, version
@ -344,7 +341,6 @@ class Manager(object):
def _build_kwargs(self, source):
# Build up the arguments we need to pass to the provider
kwargs = {}
context = getattr(source, 'context', None)
for k, v in source.items():
try:
if v.startswith('env/'):
@ -353,10 +349,9 @@ class Manager(object):
v = environ[env_var]
except KeyError:
self.log.exception('Invalid provider config')
msg = f'Incorrect provider config, missing env var {env_var}'
if context:
msg += f', {context}'
raise ManagerException(msg)
raise ManagerException(
f'Incorrect provider config, missing env var {env_var}, {source.context}'
)
except AttributeError:
pass
kwargs[k] = v


+ 3
- 1
tests/test_octodns_manager.py View File

@ -104,7 +104,9 @@ class TestManager(TestCase):
with self.assertRaises(ManagerException) as ctx:
name = 'bad-plan-output-missing-class.yaml'
Manager(get_config_filename(name)).sync()
self.assertTrue('plan_output bad is missing class' in str(ctx.exception))
self.assertTrue(
'plan_output bad is missing class' in str(ctx.exception)
)
def test_bad_plan_output_config(self):
with self.assertRaises(ManagerException) as ctx:


+ 56
- 0
tests/test_octodns_record.py View File

@ -22,6 +22,7 @@ from octodns.record import (
ValidationError,
ValuesMixin,
)
from octodns.yaml import ContextDict
from octodns.zone import Zone
@ -572,3 +573,58 @@ class TestRecordValidation(TestCase):
},
lenient=True,
)
def test_validation_context(self):
# fails validation, no context
with self.assertRaises(ValidationError) as ctx:
Record.new(
self.zone, 'www', {'type': 'A', 'ttl': -1, 'value': '1.2.3.4'}
)
self.assertFalse(', line' in str(ctx.exception))
# fails validation, with context
with self.assertRaises(ValidationError) as ctx:
Record.new(
self.zone,
'www',
ContextDict(
{'type': 'A', 'ttl': -1, 'value': '1.2.3.4'},
context='needle',
),
)
self.assertTrue('needle' in str(ctx.exception))
def test_invalid_type_context(self):
# fails validation, no context
with self.assertRaises(Exception) as ctx:
Record.new(
self.zone, 'www', {'type': 'X', 'ttl': 42, 'value': '1.2.3.4'}
)
self.assertFalse(', line' in str(ctx.exception))
# fails validation, with context
with self.assertRaises(Exception) as ctx:
Record.new(
self.zone,
'www',
ContextDict(
{'type': 'X', 'ttl': 42, 'value': '1.2.3.4'},
context='needle',
),
)
self.assertTrue('needle' in str(ctx.exception))
def test_missing_type_context(self):
# fails validation, no context
with self.assertRaises(Exception) as ctx:
Record.new(self.zone, 'www', {'ttl': 42, 'value': '1.2.3.4'})
self.assertFalse(', line' in str(ctx.exception))
# fails validation, with context
with self.assertRaises(Exception) as ctx:
Record.new(
self.zone,
'www',
ContextDict({'ttl': 42, 'value': '1.2.3.4'}, context='needle'),
)
self.assertTrue('needle' in str(ctx.exception))

Loading…
Cancel
Save