mirror of
				https://github.com/github/octodns.git
				synced 2024-05-11 05:55:00 +00:00 
			
		
		
		
	fastdns provider:
- added unit tests for apply functions - added another json config file for this - 100% code coverage reached
This commit is contained in:
		
							
								
								
									
										166
									
								
								tests/fixtures/fastdns-records-prev-other.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										166
									
								
								tests/fixtures/fastdns-records-prev-other.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,166 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "recordsets": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "10 20 30 foo-1.other.tests.",
 | 
				
			||||||
 | 
					                "12 20 30 foo-2.other.tests."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "SRV",
 | 
				
			||||||
 | 
					            "name": "_srv._tcp.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "10 20 30 foo-1.other.tests.",
 | 
				
			||||||
 | 
					                "12 20 30 foo-2.other.tests."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "SRV",
 | 
				
			||||||
 | 
					            "name": "_srv._tcp.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "2601:644:500:e210:62f8:1dff:feb8:9471"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "AAAA",
 | 
				
			||||||
 | 
					            "name": "aaaa.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "ns1.akam.net.",
 | 
				
			||||||
 | 
					                "ns2.akam.net.",
 | 
				
			||||||
 | 
					                "ns3.akam.net.",
 | 
				
			||||||
 | 
					                "ns4.akam.net."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "NS",
 | 
				
			||||||
 | 
					            "name": "old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 3600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "1.2.3.4",
 | 
				
			||||||
 | 
					                "1.2.3.5"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "A",
 | 
				
			||||||
 | 
					            "name": "old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 300
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "ns1.akam.net hostmaster.akamai.com 1489074932 86400 7200 604800 300"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "SOA",
 | 
				
			||||||
 | 
					            "name": "other.tests",
 | 
				
			||||||
 | 
					            "ttl": 3600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "1 1 7491973e5f8b39d5327cd4e08bc81b05f7710b49",
 | 
				
			||||||
 | 
					                "1 1 bf6b6825d2977c511a475bbefb88aad54a92ac73"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "SSHFP",
 | 
				
			||||||
 | 
					            "name": "old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 3600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "other.tests."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "CNAME",
 | 
				
			||||||
 | 
					            "name": "old.cname.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 300
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "other.tests."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "CNAME",
 | 
				
			||||||
 | 
					            "name": "excluded.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 3600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "other.tests."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "CNAME",
 | 
				
			||||||
 | 
					            "name": "included.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 3600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "10 smtp-4.other.tests.",
 | 
				
			||||||
 | 
					                "20 smtp-2.other.tests.",
 | 
				
			||||||
 | 
					                "30 smtp-3.other.tests.",
 | 
				
			||||||
 | 
					                "40 smtp-1.other.tests."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "MX",
 | 
				
			||||||
 | 
					            "name": "mx.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 300
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "10 100 \"S\" \"SIP+D2U\" \"!^.*$!sip:info@bar.example.com!\" .",
 | 
				
			||||||
 | 
					                "100 100 \"U\" \"SIP+D2U\" \"!^.*$!sip:info@bar.example.com!\" ."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "NAPTR",
 | 
				
			||||||
 | 
					            "name": "naptr.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "foo.bar.com."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "PTR",
 | 
				
			||||||
 | 
					            "name": "ptr.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 300
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "\"v=spf1 ip4:192.168.0.1/16-all\""
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "SPF",
 | 
				
			||||||
 | 
					            "name": "spf.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "ns1.other.tests.",
 | 
				
			||||||
 | 
					                "ns2.other.tests."
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "NS",
 | 
				
			||||||
 | 
					            "name": "under.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 3600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "\"Bah bah black sheep\"",
 | 
				
			||||||
 | 
					                "\"have you any wool.\"",
 | 
				
			||||||
 | 
					                "\"v=DKIM1;k=rsa;s=email;h=sha256;p=A/kinda+of/long/string+with+numb3rs\""
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "TXT",
 | 
				
			||||||
 | 
					            "name": "txt.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 600
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "2.2.3.7"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "A",
 | 
				
			||||||
 | 
					            "name": "www.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 300
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "rdata": [
 | 
				
			||||||
 | 
					                "2.2.3.6"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "type": "A",
 | 
				
			||||||
 | 
					            "name": "www.sub.old.other.tests",
 | 
				
			||||||
 | 
					            "ttl": 300
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "metadata": {
 | 
				
			||||||
 | 
					        "totalElements": 16,
 | 
				
			||||||
 | 
					        "showAll": true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -88,8 +88,10 @@ class TestFastdnsProvider(TestCase):
 | 
				
			|||||||
        del provider._zone_records[zone.name]
 | 
					        del provider._zone_records[zone.name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_apply(self):
 | 
					    def test_apply(self):
 | 
				
			||||||
        provider = AkamaiProvider("test", "secret", "akam.com", "atok", "ctok")
 | 
					        provider = AkamaiProvider("test", "s", "akam.com", "atok", "ctok",
 | 
				
			||||||
 | 
					                                  "cid", "gid")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # tests create update delete through previous state config json
 | 
				
			||||||
        with requests_mock() as mock:
 | 
					        with requests_mock() as mock:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            with open('tests/fixtures/fastdns-records-prev.json') as fh:
 | 
					            with open('tests/fixtures/fastdns-records-prev.json') as fh:
 | 
				
			||||||
@@ -102,3 +104,47 @@ class TestFastdnsProvider(TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            changes = provider.apply(plan)
 | 
					            changes = provider.apply(plan)
 | 
				
			||||||
            self.assertEquals(29, changes)
 | 
					            self.assertEquals(29, changes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Test against a zone that doesn't exist yet
 | 
				
			||||||
 | 
					        with requests_mock() as mock:
 | 
				
			||||||
 | 
					            with open('tests/fixtures/fastdns-records-prev-other.json') as fh:
 | 
				
			||||||
 | 
					                mock.get(ANY, status_code=404)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            plan = provider.plan(self.expected)
 | 
				
			||||||
 | 
					            mock.post(ANY, status_code=201)
 | 
				
			||||||
 | 
					            mock.put(ANY, status_code=200)
 | 
				
			||||||
 | 
					            mock.delete(ANY, status_code=204)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            changes = provider.apply(plan)
 | 
				
			||||||
 | 
					            self.assertEquals(14, changes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Test against a zone that doesn't exist yet, but gid not provided
 | 
				
			||||||
 | 
					        with requests_mock() as mock:
 | 
				
			||||||
 | 
					            with open('tests/fixtures/fastdns-records-prev-other.json') as fh:
 | 
				
			||||||
 | 
					                mock.get(ANY, status_code=404)
 | 
				
			||||||
 | 
					            provider = AkamaiProvider("test", "s", "akam.com", "atok", "ctok",
 | 
				
			||||||
 | 
					                                      "cid")
 | 
				
			||||||
 | 
					            plan = provider.plan(self.expected)
 | 
				
			||||||
 | 
					            mock.post(ANY, status_code=201)
 | 
				
			||||||
 | 
					            mock.put(ANY, status_code=200)
 | 
				
			||||||
 | 
					            mock.delete(ANY, status_code=204)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            changes = provider.apply(plan)
 | 
				
			||||||
 | 
					            self.assertEquals(14, changes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Test against a zone that doesn't exist, but cid not provided
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with requests_mock() as mock:
 | 
				
			||||||
 | 
					            mock.get(ANY, status_code=404)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            provider = AkamaiProvider("test", "s", "akam.com", "atok", "ctok")
 | 
				
			||||||
 | 
					            plan = provider.plan(self.expected)
 | 
				
			||||||
 | 
					            mock.post(ANY, status_code=201)
 | 
				
			||||||
 | 
					            mock.put(ANY, status_code=200)
 | 
				
			||||||
 | 
					            mock.delete(ANY, status_code=204)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
 | 
					                changes = provider.apply(plan)
 | 
				
			||||||
 | 
					            except NameError as e:
 | 
				
			||||||
 | 
					                expected = "contractId not specified to create zone"
 | 
				
			||||||
 | 
					                self.assertEquals(e.message, expected)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user