|
@@ -0,0 +1,69 @@
|
|
|
|
+# Copyright (C) 2011 Internet Systems Consortium.
|
|
|
|
+#
|
|
|
|
+# Permission to use, copy, modify, and distribute this software for any
|
|
|
|
+# purpose with or without fee is hereby granted, provided that the above
|
|
|
|
+# copyright notice and this permission notice appear in all copies.
|
|
|
|
+#
|
|
|
|
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
|
|
|
|
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
+
|
|
|
|
+import isc.log
|
|
|
|
+import unittest
|
|
|
|
+from isc.dns import Name
|
|
|
|
+from isc.xfrin.diff import Diff, NoSuchZone
|
|
|
|
+
|
|
|
|
+class DiffTest(unittest.TestCase):
|
|
|
|
+ """
|
|
|
|
+ Tests for the isc.xfrin.diff.Diff class.
|
|
|
|
+
|
|
|
|
+ It also plays role of a data source and an updater, so it can manipulate
|
|
|
|
+ some test variables while being called.
|
|
|
|
+ """
|
|
|
|
+ def setUp(self):
|
|
|
|
+ """
|
|
|
|
+ This sets internal variables so we can see nothing was called yet.
|
|
|
|
+ """
|
|
|
|
+ self.__updater_requested = False
|
|
|
|
+
|
|
|
|
+ def get_updater(self, zone_name, replace):
|
|
|
|
+ """
|
|
|
|
+ This one pretends this is the data source client and serves
|
|
|
|
+ getting an updater.
|
|
|
|
+
|
|
|
|
+ If zone_name is 'none.example.org.', it returns None, otherwise
|
|
|
|
+ it returns self.
|
|
|
|
+ """
|
|
|
|
+ # The diff should not delete the old data.
|
|
|
|
+ self.assertFalse(replace)
|
|
|
|
+ self.__updater_requested = True
|
|
|
|
+ # Pretend this zone doesn't exist
|
|
|
|
+ if zone_name == Name('none.example.org.'):
|
|
|
|
+ return None
|
|
|
|
+ else:
|
|
|
|
+ return self
|
|
|
|
+
|
|
|
|
+ def test_create(self):
|
|
|
|
+ """
|
|
|
|
+ This test the case when the diff is successfuly created. It just
|
|
|
|
+ tries it does not throw and gets the updater.
|
|
|
|
+ """
|
|
|
|
+ diff = Diff(self, Name('example.org.'))
|
|
|
|
+ self.assertTrue(self.__updater_requested)
|
|
|
|
+
|
|
|
|
+ def test_create_nonexist(self):
|
|
|
|
+ """
|
|
|
|
+ Try to create a diff on a zone that doesn't exist. This should
|
|
|
|
+ raise a correct exception.
|
|
|
|
+ """
|
|
|
|
+ self.assertRaises(NoSuchZone, Diff, self, Name('none.example.org.'))
|
|
|
|
+ self.assertTrue(self.__updater_requested)
|
|
|
|
+
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+ isc.log.init("bind10")
|
|
|
|
+ unittest.main()
|