Beispiel #1
0
class ZoneModifySaveTest(unittest.TestCase):
    def setUp(self):
        self.zone = Zone('example.com.')
        zone_file = os.path.join(os.path.dirname(__file__), 'files',
                                 'example.com')
        self.zone.load_from_file(zone_file)

        self.zone.root.soa.mname = 'mname.example.com.'
        self.zone.root.soa.rname = 'rname.example.com.'
        self.zone.root.soa.serial += 1
        self.zone.root.soa.refresh = 1
        self.zone.root.soa.retry = 2
        self.zone.root.soa.expire = 3
        self.zone.root.soa.minttl = 4

        self.zone.add_name('zip.example.com.')
        self.zone.names['zip.example.com.'].records('A', create=True).add(
            '10.9.8.7')  # noqa: E501

        mx = self.zone.names['foo.example.com.'].records('MX')
        mx.delete((10, 'mail.example.com.'))
        mx.add((30, 'anothermail.example.com.'))

        self.zone.names['bar.example.com.'].records('A').add('10.20.30.40')

        self.zone.delete_name('foofoo.example.com.')

        self.zone.delete_name('barbar.example.com')

        self.saved_filename = tempfile.mkstemp()[1]
        # self.saved_filename = '/var/tmp/foo.tmp'
        self.zone.save(self.saved_filename)

    def test_file_exists(self):
        self.assertTrue(os.path.exists(self.saved_filename))

    def test_file_size(self):
        size = os.stat(self.saved_filename)[6]
        self.assertEqual(size, 682)

    def test_save_autoserial_greater(self):
        saved_filename = tempfile.mkstemp()[1]
        self.zone.save(saved_filename, autoserial=True)

        z = Zone('example.com.')
        z.load_from_file(saved_filename)
        self.assertTrue(z.root.soa.serial >= self.zone.root.soa.serial)
Beispiel #2
0
class ZoneModifySaveTest(unittest.TestCase):
    def setUp(self):
        self.zone = Zone("example.com.")
        zone_file = os.path.join(os.path.dirname(__file__), "files", "example.com")
        self.zone.load_from_file(zone_file)

        self.zone.root.soa.mname = "mname.example.com."
        self.zone.root.soa.rname = "rname.example.com."
        self.zone.root.soa.serial += 1
        self.zone.root.soa.refresh = 1
        self.zone.root.soa.retry = 2
        self.zone.root.soa.expire = 3
        self.zone.root.soa.minttl = 4

        self.zone.add_name("zip.example.com.")
        self.zone.names["zip.example.com."].records("A", create=True).add(
            "10.9.8.7"
        )  # noqa: E501

        mx = self.zone.names["foo.example.com."].records("MX")
        mx.delete((10, "mail.example.com."))
        mx.add((30, "anothermail.example.com."))

        self.zone.names["bar.example.com."].records("A").add("10.20.30.40")

        self.zone.delete_name("foofoo.example.com.")

        self.zone.delete_name("barbar.example.com")

        self.saved_filename = tempfile.mkstemp()[1]
        # self.saved_filename = '/var/tmp/foo.tmp'
        self.zone.save(self.saved_filename)

    def test_file_exists(self):
        self.assertTrue(os.path.exists(self.saved_filename))

    def test_file_size(self):
        size = os.stat(self.saved_filename)[6]
        self.assertEqual(size, 682)

    def test_save_autoserial_greater(self):
        saved_filename = tempfile.mkstemp()[1]
        self.zone.save(saved_filename, autoserial=True)

        z = Zone("example.com.")
        z.load_from_file(saved_filename)
        self.assertTrue(z.root.soa.serial >= self.zone.root.soa.serial)