|
|
|
@ -10,12 +10,12 @@ from six import text_type |
|
|
|
|
|
|
|
from suds import WebFault |
|
|
|
|
|
|
|
from mock import patch |
|
|
|
from unittest import TestCase |
|
|
|
|
|
|
|
from octodns.provider.transip import TransipProvider |
|
|
|
from octodns.provider.yaml import YamlProvider |
|
|
|
from octodns.zone import Zone |
|
|
|
from transip.service.domain import DomainService |
|
|
|
from transip.service.objects import DnsEntry |
|
|
|
|
|
|
|
|
|
|
|
@ -32,12 +32,11 @@ class MockResponse(object): |
|
|
|
dnsEntries = [] |
|
|
|
|
|
|
|
|
|
|
|
class MockDomainService(DomainService): |
|
|
|
class MockDomainService(object): |
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
super(MockDomainService, self).__init__('MockDomainService', *args, |
|
|
|
**kwargs) |
|
|
|
self.mockupEntries = [] |
|
|
|
self.throw_auth_fault = False |
|
|
|
|
|
|
|
def mockup(self, records): |
|
|
|
|
|
|
|
@ -67,6 +66,9 @@ class MockDomainService(DomainService): |
|
|
|
# Skips authentication layer and returns the entries loaded by "Mockup" |
|
|
|
def get_info(self, domain_name): |
|
|
|
|
|
|
|
if self.throw_auth_fault: |
|
|
|
self.raiseInvalidAuth() |
|
|
|
|
|
|
|
# Special 'domain' to trigger error |
|
|
|
if str(domain_name) == str('notfound.unit.tests'): |
|
|
|
self.raiseZoneNotFound() |
|
|
|
@ -135,26 +137,39 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd |
|
|
|
source.populate(expected) |
|
|
|
return expected |
|
|
|
|
|
|
|
def test_init(self): |
|
|
|
@patch('octodns.provider.transip.TransipProvider._domain_service', |
|
|
|
return_value=MockDomainService()) |
|
|
|
def test_init(self, _): |
|
|
|
|
|
|
|
# No key nor key_file |
|
|
|
with self.assertRaises(Exception) as ctx: |
|
|
|
TransipProvider('test', 'unittest') |
|
|
|
|
|
|
|
self.assertEquals( |
|
|
|
str('Missing `key` of `key_file` parameter in config'), |
|
|
|
str('Missing `key` or `key_file` parameter in config'), |
|
|
|
str(ctx.exception)) |
|
|
|
|
|
|
|
# With key |
|
|
|
TransipProvider('test', 'unittest', key=self.bogus_key) |
|
|
|
|
|
|
|
# Existence and content of the key is tested in the SDK on client call |
|
|
|
# With key_file |
|
|
|
TransipProvider('test', 'unittest', key_file='/fake/path') |
|
|
|
|
|
|
|
def test_populate(self): |
|
|
|
@patch('suds.client.Client.__init__', new=lambda *args, **kwargs: None) |
|
|
|
def test_domain_service(self): |
|
|
|
# Special case smoke test for DomainService to get coverage |
|
|
|
TransipProvider('test', 'unittest', key=self.bogus_key) |
|
|
|
|
|
|
|
@patch('octodns.provider.transip.TransipProvider._domain_service', |
|
|
|
return_value=MockDomainService()) |
|
|
|
def test_populate(self, _): |
|
|
|
_expected = self.make_expected() |
|
|
|
|
|
|
|
# Unhappy Plan - Not authenticated |
|
|
|
# Live test against API, will fail in an unauthorized error |
|
|
|
with self.assertRaises(WebFault) as ctx: |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client.throw_auth_fault = True |
|
|
|
zone = Zone('unit.tests.', []) |
|
|
|
provider.populate(zone, True) |
|
|
|
|
|
|
|
@ -163,12 +178,14 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd |
|
|
|
|
|
|
|
self.assertEquals(str('200'), ctx.exception.fault.faultcode) |
|
|
|
|
|
|
|
# No more auth problems |
|
|
|
provider._client.throw_auth_fault = False |
|
|
|
|
|
|
|
# Unhappy Plan - Zone does not exists |
|
|
|
# Will trigger an exception if provider is used as a target for a |
|
|
|
# non-existing zone |
|
|
|
with self.assertRaises(Exception) as ctx: |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
zone = Zone('notfound.unit.tests.', []) |
|
|
|
provider.populate(zone, True) |
|
|
|
|
|
|
|
@ -184,13 +201,11 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd |
|
|
|
# Won't trigger an exception if provider is NOT used as a target for a |
|
|
|
# non-existing zone. |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
zone = Zone('notfound.unit.tests.', []) |
|
|
|
provider.populate(zone, False) |
|
|
|
|
|
|
|
# Happy Plan - Populate with mockup records |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
provider._client.mockup(_expected.records) |
|
|
|
zone = Zone('unit.tests.', []) |
|
|
|
provider.populate(zone, False) |
|
|
|
@ -208,19 +223,19 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd |
|
|
|
|
|
|
|
# Happy Plan - Even if the zone has no records the zone should exist |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
zone = Zone('unit.tests.', []) |
|
|
|
exists = provider.populate(zone, True) |
|
|
|
self.assertTrue(exists, 'populate should return true') |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
def test_plan(self): |
|
|
|
@patch('octodns.provider.transip.TransipProvider._domain_service', |
|
|
|
return_value=MockDomainService()) |
|
|
|
def test_plan(self, _): |
|
|
|
_expected = self.make_expected() |
|
|
|
|
|
|
|
# Test Happy plan, only create |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
plan = provider.plan(_expected) |
|
|
|
|
|
|
|
self.assertEqual(15, plan.change_counts['Create']) |
|
|
|
@ -229,12 +244,13 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
def test_apply(self): |
|
|
|
@patch('octodns.provider.transip.TransipProvider._domain_service', |
|
|
|
return_value=MockDomainService()) |
|
|
|
def test_apply(self, _): |
|
|
|
_expected = self.make_expected() |
|
|
|
|
|
|
|
# Test happy flow. Create all supoorted records |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
plan = provider.plan(_expected) |
|
|
|
self.assertEqual(15, len(plan.changes)) |
|
|
|
changes = provider.apply(plan) |
|
|
|
@ -246,7 +262,6 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd |
|
|
|
changes = [] # reset changes |
|
|
|
with self.assertRaises(Exception) as ctx: |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
plan = provider.plan(_expected) |
|
|
|
plan.desired.name = 'notfound.unit.tests.' |
|
|
|
changes = provider.apply(plan) |
|
|
|
@ -265,7 +280,6 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd |
|
|
|
|
|
|
|
with self.assertRaises(Exception) as ctx: |
|
|
|
provider = TransipProvider('test', 'unittest', self.bogus_key) |
|
|
|
provider._client = MockDomainService('unittest', self.bogus_key) |
|
|
|
plan = provider.plan(_expected) |
|
|
|
plan.desired.name = 'failsetdns.unit.tests.' |
|
|
|
changes = provider.apply(plan) |
|
|
|
|