1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Fixes and unit tests for new plan output functionality

This commit is contained in:
Ross McFarland
2018-01-06 16:26:48 -08:00
parent ddf53b7a47
commit ad1d0f0fe8
2 changed files with 75 additions and 2 deletions

View File

@@ -143,7 +143,7 @@ def _value_stringifier(record, sep):
values = [str(v) for v in record.values]
except AttributeError:
values = [record.value]
for code, gv in getattr(record, 'geo', {}).items():
for code, gv in sorted(getattr(record, 'geo', {}).items()):
vs = ', '.join([str(v) for v in gv.values])
values.append('{}: {}'.format(code, vs))
return sep.join(values)

View File

@@ -5,9 +5,15 @@
from __future__ import absolute_import, division, print_function, \
unicode_literals
from StringIO import StringIO
from logging import getLogger
from unittest import TestCase
from octodns.provider.plan import PlanLogger
from octodns.provider.plan import Plan, PlanHtml, PlanLogger, PlanMarkdown
from octodns.record import Create, Delete, Record, Update
from octodns.zone import Zone
from helpers import SimpleProvider
class TestPlanLogger(TestCase):
@@ -17,3 +23,70 @@ class TestPlanLogger(TestCase):
PlanLogger('invalid', 'not-a-level')
self.assertEquals('Unsupported level: not-a-level',
ctx.exception.message)
simple = SimpleProvider()
zone = Zone('unit.tests.', [])
existing = Record.new(zone, 'a', {
'ttl': 300,
'type': 'A',
# This matches the zone data above, one to swap, one to leave
'values': ['1.1.1.1', '2.2.2.2'],
})
new = Record.new(zone, 'a', {
'geo': {
'AF': ['5.5.5.5'],
'NA-US': ['6.6.6.6']
},
'ttl': 300,
'type': 'A',
# This leaves one, swaps ones, and adds one
'values': ['2.2.2.2', '3.3.3.3', '4.4.4.4'],
}, simple)
create = Create(Record.new(zone, 'b', {
'ttl': 60,
'type': 'CNAME',
'value': 'foo.unit.tests.'
}, simple))
update = Update(existing, new)
delete = Delete(new)
changes = [create, delete, update]
plans = [
(simple, Plan(zone, zone, changes)),
(simple, Plan(zone, zone, changes)),
]
class TestPlanHtml(TestCase):
log = getLogger('TestPlanHtml')
def test_empty(self):
out = StringIO()
PlanHtml('html').run([], fh=out)
self.assertEquals('<b>No changes were planned</b>', out.getvalue())
def test_simple(self):
out = StringIO()
PlanHtml('html').run(plans, fh=out)
out = out.getvalue()
self.assertTrue(' <td colspan=6>Summary: Creates=1, Updates=1, '
'Deletes=1, Existing Records=0</td>' in out)
class TestPlanMarkdown(TestCase):
log = getLogger('TestPlanMarkdown')
def test_empty(self):
out = StringIO()
PlanMarkdown('markdown').run([], fh=out)
self.assertEquals('## No changes were planned\n', out.getvalue())
def test_simple(self):
out = StringIO()
PlanMarkdown('markdown').run(plans, fh=out)
out = out.getvalue()
self.assertTrue('## unit.tests.' in out)
self.assertTrue('Create | b | CNAME | 60 | foo.unit.tests.' in out)
self.assertTrue('Update | a | A | 300 | 1.1.1.1;' in out)
self.assertTrue('NA-US: 6.6.6.6 | test' in out)
self.assertTrue('Delete | a | A | 300 | 2.2.2.2;' in out)