Exemplo n.º 1
0
    def test_init(self):
        with self.assertRaises(Exception) as ctx:
            TransipProvider('test', 'unittest')

        self.assertEquals(
            str('Missing `key` of `key_file` parameter in config'),
            str(ctx.exception))

        TransipProvider('test', 'unittest', key=self.bogus_key)

        # Existence and content of the key is tested in the SDK on client call
        TransipProvider('test', 'unittest', key_file='/fake/path')
Exemplo n.º 2
0
    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(12, plan.change_counts['Create'])
        self.assertEqual(0, plan.change_counts['Update'])
        self.assertEqual(0, plan.change_counts['Delete'])

        return
Exemplo n.º 3
0
    def mockup(self, records):

        provider = TransipProvider('', '', '')

        _dns_entries = []
        for record in records:
            if record._type in provider.SUPPORTS:
                entries_for = getattr(provider,
                                      '_entries_for_{}'.format(record._type))

                # Root records have '@' as name
                name = record.name
                if name == '':
                    name = provider.ROOT_RECORD

                _dns_entries.extend(entries_for(name, record))

                # NS is not supported as a DNS Entry,
                # so it should cover the if statement
                _dns_entries.append(
                    DnsEntry('@', '3600', 'NS', 'ns01.transip.nl.'))

        self.mockupEntries = _dns_entries
Exemplo n.º 4
0
    def mockup(self, records):

        provider = TransipProvider('', '', '')

        _dns_entries = []
        for record in records:
            if record._type in provider.SUPPORTS:
                entries_for = getattr(provider,
                                      '_entries_for_{}'.format(record._type))

                # Root records have '@' as name
                name = record.name
                if name == '':
                    name = provider.ROOT_RECORD

                _dns_entries.extend(entries_for(name, record))

                # Add a non-supported type
                # so it triggers the "is supported" (transip.py:115) check and
                # give 100% code coverage
                _dns_entries.append(
                    DnsEntry('@', '3600', 'BOGUS', 'ns01.transip.nl.'))

        self.mockupEntries = _dns_entries
Exemplo n.º 5
0
    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(12, len(plan.changes))
        changes = provider.apply(plan)
        self.assertEqual(changes, len(plan.changes))

        # Test unhappy flow. Trigger 'not found error' in apply stage
        # This should normally not happen as populate will capture it first
        # but just in case.
        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)

        # Changes should not be set due to an Exception
        self.assertEqual([], changes)

        self.assertEquals(str('WebFault'),
                          str(ctx.exception.__class__.__name__))

        self.assertEquals(str('102'), ctx.exception.fault.faultcode)

        # Test unhappy flow. Trigger a unrecoverable error while saving
        _expected = self.make_expected()  # reset expected
        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 = 'failsetdns.unit.tests.'
            changes = provider.apply(plan)

        # Changes should not be set due to an Exception
        self.assertEqual([], changes)

        self.assertEquals(str('TransipException'),
                          str(ctx.exception.__class__.__name__))
Exemplo n.º 6
0
    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)
            zone = Zone('unit.tests.', [])
            provider.populate(zone, True)

        self.assertEquals(str('WebFault'),
                          str(ctx.exception.__class__.__name__))

        self.assertEquals(str('200'), ctx.exception.fault.faultcode)

        # 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)

        self.assertEquals(str('TransipNewZoneException'),
                          str(ctx.exception.__class__.__name__))

        self.assertEquals(
            'populate: (102) Transip used as target' +
            ' for non-existing zone: notfound.unit.tests.',
            ctx.exception.message)

        # Happy Plan - Zone does not exists
        # 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)

        # Transip allows relative values for types like cname, mx.
        # Test is these are correctly appended with the domain
        provider._currentZone = zone
        self.assertEquals("www.unit.tests.", provider._parse_to_fqdn("www"))
        self.assertEquals("www.unit.tests.",
                          provider._parse_to_fqdn("www.unit.tests."))
        self.assertEquals("www.sub.sub.sub.unit.tests.",
                          provider._parse_to_fqdn("www.sub.sub.sub"))
        self.assertEquals("unit.tests.", provider._parse_to_fqdn("@"))

        # 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