From 22a05639160bf7c0417d82af78e0ac4df3d43f15 Mon Sep 17 00:00:00 2001 From: Joe Williams Date: Mon, 10 Jul 2017 16:00:50 -0700 Subject: [PATCH 1/4] fix unsafe plan text interpolation --- octodns/provider/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octodns/provider/base.py b/octodns/provider/base.py index 2fd4349..bcf566a 100644 --- a/octodns/provider/base.py +++ b/octodns/provider/base.py @@ -56,8 +56,8 @@ class Plan(object): delete_pcent = self.change_counts['Delete'] / existing_record_count if update_pcent > self.MAX_SAFE_UPDATE_PCENT: - raise UnsafePlan('Too many updates, %s is over %s percent' - '(%s/%s)', + raise UnsafePlan('Too many updates, {} is over {} percent' + '({}/{})'.format, update_pcent, self.MAX_SAFE_UPDATE_PCENT * 100, self.change_counts['Update'], From 2b58e065e8569e336aaec2cd3f759f03ed69867a Mon Sep 17 00:00:00 2001 From: Joe Williams Date: Tue, 11 Jul 2017 07:09:20 -0700 Subject: [PATCH 2/4] fix format --- octodns/provider/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/octodns/provider/base.py b/octodns/provider/base.py index bcf566a..8c97edb 100644 --- a/octodns/provider/base.py +++ b/octodns/provider/base.py @@ -57,18 +57,18 @@ class Plan(object): if update_pcent > self.MAX_SAFE_UPDATE_PCENT: raise UnsafePlan('Too many updates, {} is over {} percent' - '({}/{})'.format, + '({}/{})'.format( update_pcent, self.MAX_SAFE_UPDATE_PCENT * 100, self.change_counts['Update'], - existing_record_count) + existing_record_count)) if delete_pcent > self.MAX_SAFE_DELETE_PCENT: - raise UnsafePlan('Too many deletes, %s is over %s percent' - '(%s/%s)', + raise UnsafePlan('Too many deletes, {} is over {} percent' + '({}/{})'.format( delete_pcent, self.MAX_SAFE_DELETE_PCENT * 100, self.change_counts['Delete'], - existing_record_count) + existing_record_count)) def __repr__(self): return 'Creates={}, Updates={}, Deletes={}, Existing Records={}' \ From 11a246da81928640387a8af36f0b3da8a93cfbe2 Mon Sep 17 00:00:00 2001 From: Joe Williams Date: Tue, 11 Jul 2017 07:20:18 -0700 Subject: [PATCH 3/4] whitespace --- octodns/provider/base.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/octodns/provider/base.py b/octodns/provider/base.py index 8c97edb..d2561ba 100644 --- a/octodns/provider/base.py +++ b/octodns/provider/base.py @@ -58,17 +58,17 @@ class Plan(object): if update_pcent > self.MAX_SAFE_UPDATE_PCENT: raise UnsafePlan('Too many updates, {} is over {} percent' '({}/{})'.format( - update_pcent, - self.MAX_SAFE_UPDATE_PCENT * 100, - self.change_counts['Update'], - existing_record_count)) + update_pcent, + self.MAX_SAFE_UPDATE_PCENT * 100, + self.change_counts['Update'], + existing_record_count)) if delete_pcent > self.MAX_SAFE_DELETE_PCENT: raise UnsafePlan('Too many deletes, {} is over {} percent' '({}/{})'.format( - delete_pcent, - self.MAX_SAFE_DELETE_PCENT * 100, - self.change_counts['Delete'], - existing_record_count)) + delete_pcent, + self.MAX_SAFE_DELETE_PCENT * 100, + self.change_counts['Delete'], + existing_record_count)) def __repr__(self): return 'Creates={}, Updates={}, Deletes={}, Existing Records={}' \ From 5b746845ed567169edb523a2149d385743c84c0c Mon Sep 17 00:00:00 2001 From: Joe Williams Date: Tue, 11 Jul 2017 07:36:24 -0700 Subject: [PATCH 4/4] add tests --- tests/test_octodns_provider_base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_octodns_provider_base.py b/tests/test_octodns_provider_base.py index bd134bc..e44adc0 100644 --- a/tests/test_octodns_provider_base.py +++ b/tests/test_octodns_provider_base.py @@ -214,9 +214,11 @@ class TestBaseProvider(TestCase): for i in range(int(Plan.MIN_EXISTING_RECORDS * Plan.MAX_SAFE_UPDATE_PCENT) + 1)] - with self.assertRaises(UnsafePlan): + with self.assertRaises(UnsafePlan) as ctx: Plan(zone, zone, changes).raise_if_unsafe() + self.assertTrue('Too many updates' in ctx.exception.message) + def test_safe_updates_min_existing_pcent(self): # MAX_SAFE_UPDATE_PCENT is safe when more # than MIN_EXISTING_RECORDS exist @@ -260,9 +262,11 @@ class TestBaseProvider(TestCase): for i in range(int(Plan.MIN_EXISTING_RECORDS * Plan.MAX_SAFE_DELETE_PCENT) + 1)] - with self.assertRaises(UnsafePlan): + with self.assertRaises(UnsafePlan) as ctx: Plan(zone, zone, changes).raise_if_unsafe() + self.assertTrue('Too many deletes' in ctx.exception.message) + def test_safe_deletes_min_existing_pcent(self): # MAX_SAFE_DELETE_PCENT is safe when more # than MIN_EXISTING_RECORDS exist