def test_valid(self): z = DNSZone() # Add SOA from pypdnsrest.dnsrecords import DNSSoaRecordData from pypdnsrest.dnsrecords import DNSSoaRecord soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) rec = DNSSoaRecord(self.zone) rec.set_data(soadata) z.add_record(rec) # Add NS from pypdnsrest.dnsrecords import DNSNsRecord rec = DNSNsRecord(self.zone) rec.set_data(u"ns1.{0}".format(self.zone)) z.add_record(rec) rec = DNSNsRecord(self.zone) rec.set_data(u"ns2.{0}".format(self.zone)) z.add_record(rec) # Add A from pypdnsrest.dnsrecords import DNSARecord from ipaddress import IPv4Address rec = DNSARecord(self.zone) rec.set_data(IPv4Address(u"192.168.0.1")) z.add_record(rec) self.assertTrue(z.validate())
def test_record_wrong_serial2(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), "invalid") rec = DNSSoaRecord(self.zone) with self.assertRaises(InvalidDNSRecordException) as context: rec.set_data(soadata)
def test_record_str(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) rec = DNSSoaRecord(self.zone) rec.set_data(soadata) self.assertIsInstance(str(rec), str)
def test_record2(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1, timedelta(hours=1), timedelta(hours=1), timedelta(hours=1), timedelta(hours=1)) rec = DNSSoaRecord(self.zone) self.assertTrue(rec.set_data(soadata))
def test_invalid_ttl(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1, timedelta(hours=1), timedelta(hours=1), timedelta(hours=1), timedelta(seconds=1)) rec = DNSSoaRecord(self.zone) with self.assertRaises(InvalidDNSRecordException) as context: rec.set_data(soadata)
def test_add_record_soa(self): from pypdnsrest.dnsrecords import DNSSoaRecord from pypdnsrest.dnsrecords import DNSSoaRecordData soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) rec = DNSSoaRecord(self.zone) rec.set_data(soadata) self.assertTrue(self.api.add_record(self.zone, rec))
def test_invalid_zone(self): from pypdnsrest.dnsrecords import DNSSoaRecord from pypdnsrest.dnsrecords import DNSSoaRecordData soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) rec = DNSSoaRecord(self.zone) rec.set_data(soadata) z = DNSZone() z.add_record(rec) self.assertFalse(z.validate())
def test_to_string(self): from pypdnsrest.dnsrecords import DNSSoaRecord from pypdnsrest.dnsrecords import DNSSoaRecordData soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) rec = DNSSoaRecord(self.zone) rec.set_data(soadata) z = DNSZone() z.add_record(rec) self.assertIsInstance(str(z), str)
def parse(self, name: str, data: str, ttl: int) -> DNSRecordBase: from pypdnsrest.dnsrecords import DNSSoaRecord from pypdnsrest.dnsrecords import DNSSoaRecordData if data.count(u" ") != 6: raise ValueError("Invalid value: '{0}'".format(data)) tmp = data.split(" ") d = DNSSoaRecordData(nameserver=tmp[0], email=tmp[1], serial=int(tmp[2]), refresh=timedelta(seconds=int(tmp[3])), retry=timedelta(seconds=int(tmp[4])), expire=timedelta(seconds=int(tmp[5])), ttl=timedelta(seconds=int(tmp[6]))) rec = DNSSoaRecord(name, timedelta(seconds=ttl)) rec.set_data(d) return rec
def test_record(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) rec = DNSSoaRecord(self.zone) self.assertTrue(rec.set_data(soadata))
def test_record_invalid_admin(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"test", 1) rec = DNSSoaRecord(self.zone) with self.assertRaises(InvalidDNSRecordException) as context: rec.set_data(soadata)
def test_record_empty_nameserver2(self): soadata = DNSSoaRecordData(None, u"admin.{0}".format(self.zone), 1) rec = DNSSoaRecord(self.zone) with self.assertRaises(InvalidDNSRecordException) as context: rec.set_data(soadata)
def test_get_data(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) self.assertIsInstance(soadata.get_data(), dict)
def test_data_to_str(self): soadata = DNSSoaRecordData(u"ns1.{0}".format(self.zone), u"admin.{0}".format(self.zone), 1) self.assertIsInstance(str(soadata), str)
"ns1.{0}".format(zone), "ns2.{0}".format(zone), ]) # Add SOA record from pypdnsrest.dnsrecords import DNSSoaRecord from pypdnsrest.dnsrecords import DNSSoaRecordData serial = -1 for i in api.get_zone(zone).get_records(): if isinstance(i, DNSSoaRecord): recdata = i.get_data() if isinstance(recdata, DNSSoaRecordData): serial = recdata.get_data()['serial'] soadata = DNSSoaRecordData("ns1.{0}".format(zone), "admin.{0}".format(zone), serial + 1) rec = DNSSoaRecord(zone) rec.set_data(soadata) api.add_record(zone, rec) # Add NS records from pypdnsrest.dnsrecords import DNSNsRecord rec = DNSNsRecord(zone) rec.set_data("ns1.{0}".format(zone)) api.add_record(zone, rec) rec = DNSNsRecord(zone) rec.set_data("ns2.{0}".format(zone)) api.add_record(zone, rec)