[svn] commit: r3320 - in /branches/trac375/src/lib/datasrc/python: pydatasrc.cc tests/pydatasrc_test.py

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Oct 22 13:26:43 UTC 2010


Author: jelte
Date: Fri Oct 22 13:26:43 2010
New Revision: 3320

Log:
more tests

Modified:
    branches/trac375/src/lib/datasrc/python/pydatasrc.cc
    branches/trac375/src/lib/datasrc/python/tests/pydatasrc_test.py

Modified: branches/trac375/src/lib/datasrc/python/pydatasrc.cc
==============================================================================
--- branches/trac375/src/lib/datasrc/python/pydatasrc.cc (original)
+++ branches/trac375/src/lib/datasrc/python/pydatasrc.cc Fri Oct 22 13:26:43 2010
@@ -97,6 +97,10 @@
       "Returns the RRClass of the DataSrc object." },
     { "init", reinterpret_cast<PyCFunction>(DataSrc_init), METH_VARARGS,
       "Initializes the data source with the given configuration.\n"
+      ""
+      "This method takes the following arguments:\n"
+      "str config: JSON representation of the datasource configuration\n"
+      "\n"
       "At this moment, the only configuration is a dict containing\n"
       "the key 'database_file', of which the value is a string\n"
       "specifying the SQlite3 database file.\n"

Modified: branches/trac375/src/lib/datasrc/python/tests/pydatasrc_test.py
==============================================================================
--- branches/trac375/src/lib/datasrc/python/tests/pydatasrc_test.py (original)
+++ branches/trac375/src/lib/datasrc/python/tests/pydatasrc_test.py Fri Oct 22 13:26:43 2010
@@ -28,10 +28,29 @@
     for l in list:
         yield l
 
+def get_new_rrs_no_iter(list):
+    if len(list) > 0:
+        return list[0]
+    else:
+        return None
+
+def get_new_rrs_no_args():
+    for l in []:
+        yield l
+
+def get_new_rrs_bad(list):
+    for l in list:
+        # just some exception
+        raise TypeError("a")
+        yield l
+
 
 class DataSourceTest(unittest.TestCase):
     def setUp(self):
         self.ds = DataSrc()
+
+    def test_bad_construct(self):
+        self.assertRaises(TypeError, DataSrc, 1)
         
     def test_init_close(self):
         self.assertRaises(DataSrcError, self.ds.close)
@@ -40,6 +59,7 @@
         self.assertRaises(DataSrcError, self.ds.init, "{")
         self.assertRaises(DataSrcError, self.ds.init, "{ \"database_file\": \"/ badfilename /\" }")
         self.assertRaises(DataSrcError, self.ds.init, "{ \"database_file\": \"/brokendb.sqlite3\" }")
+        self.assertRaises(DataSrcError, self.ds.init, "{ \'")
         self.ds.init("{ \"database_file\": \""+ testdata_path + "/example.org.sqlite3\" }")
         self.assertEqual(0, self.ds.close())
 
@@ -151,6 +171,8 @@
         result, result_name = self.ds.find_previous_name(Name("www.nosuch.zone"), Name("nosuch.zone"))
         self.assertEqual(DataSrc.ERROR, result);
         self.assertEqual(None, result_name);
+
+        self.assertRaises(TypeError, self.ds.find_previous_name)
         
     def test_find_covering_nsec3(self):
         self.ds.init("{ \"database_file\": \""+ testdata_path + "/test.sqlite3\" }")
@@ -185,6 +207,8 @@
         self.assertRaises(TypeError, self.ds.start_transaction, 1, RRClass.IN())
         self.assertRaises(TypeError, self.ds.start_transaction, Name("example.com"), 1)
 
+        self.assertRaises(TypeError, DataSrcTransaction)
+
         transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
         self.assertEqual(DataSrcTransaction.INIT, transaction.get_state())
 
@@ -255,6 +279,9 @@
         self.assertEqual(1, len(result))
         self.assertEqual("added.example.com. 3600 IN A 192.0.2.1\n", str(result[0]))
 
+        self.assertRaises(TypeError, self.ds.commit_transaction)
+        self.assertRaises(TypeError, self.ds.add_rrset)
+
     def test_del_rrset_rollback(self):
         rrset = RRset(Name("www.example.com"), RRClass.IN(), RRType.A(), RRTTL(3600))
         rrset.add_rdata(Rdata(rrset.get_type(), rrset.get_class(), "192.0.2.1"))
@@ -280,6 +307,8 @@
         self.assertEqual(DataSrc.SUCCESS, n);
         self.assertEqual(1, len(result))
 
+        self.assertRaises(TypeError, self.ds.rollback_transaction)
+
     def test_del_rrset_commit(self):
         rrset = RRset(Name("www.example.com"), RRClass.IN(), RRType.A(), RRTTL(3600))
         rrset.add_rdata(Rdata(rrset.get_type(), rrset.get_class(), "192.0.2.1"))
@@ -305,6 +334,8 @@
         self.assertEqual(1, len(result))
         self.assertEqual(0, result[0].get_rdata_count())
 
+        self.assertRaises(TypeError, self.ds.del_rrset)
+
     def test_del_rrset_name(self):
         rrset = RRset(Name("www.example.com"), RRClass.IN(), RRType.ANY(), RRTTL(3600))
         
@@ -345,34 +376,10 @@
         transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
         result = self.ds.start_transaction(transaction)
         self.assertEqual(DataSrc.W_NO_SUCH_ZONE, result)
+
+        self.assertRaises(TypeError, self.ds.del_zone)
         
     def test_replace_zone_list(self):
-        transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
-        result = self.ds.start_transaction(transaction)
-        self.assertEqual(DataSrc.W_SUCCESS, result)
-
-        result = []
-        n = self.ds.find_rrset(Name("www.example.com"), RRClass.IN(), RRType.A(), result, 0, Name("example.com"))
-        self.assertEqual(DataSrc.SUCCESS, n);
-        self.assertEqual(1, len(result))
-
-        new_rrs = []
-        result = self.ds.replace_zone(transaction, new_rrs)
-        self.assertEqual(DataSrc.W_SUCCESS, result)
-
-        self.assertRaises(TypeError, self.ds.replace_zone, transaction)
-        self.assertRaises(TypeError, self.ds.replace_zone, transaction, 1)
-        self.assertRaises(TypeError, self.ds.replace_zone, transaction, [1])
-
-        result = self.ds.commit_transaction(transaction)
-        self.assertEqual(DataSrc.W_SUCCESS, result)
-
-        result = []
-        n = self.ds.find_rrset(Name("www.example.com"), RRClass.IN(), RRType.A(), result, 0, Name("example.com"))
-        self.assertEqual(DataSrc.SUCCESS, n);
-        self.assertEqual(0, len(result))
-
-    def test_replace_zone_function(self):
         transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
         result = self.ds.start_transaction(transaction)
         self.assertEqual(DataSrc.W_SUCCESS, result)
@@ -395,6 +402,60 @@
 
         new_rrs = [ rrset1, rrset2, rrset3 ]
 
+        result = self.ds.replace_zone(transaction, new_rrs)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        self.assertRaises(TypeError, self.ds.replace_zone, transaction)
+        self.assertRaises(TypeError, self.ds.replace_zone, transaction, 1)
+        self.assertRaises(TypeError, self.ds.replace_zone, transaction, [1])
+
+        result = self.ds.commit_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        result = []
+        n = self.ds.find_rrset(Name("www.example.com"), RRClass.IN(), RRType.A(), result, 0, Name("example.com"))
+        self.assertEqual(DataSrc.SUCCESS, n);
+        self.assertEqual(0, len(result))
+
+    def test_replace_zone_list_new_zone(self):
+        transaction = DataSrcTransaction(self.ds, Name("new.example.com"), RRClass.IN())
+        result = self.ds.start_transaction(transaction)
+        self.assertEqual(DataSrc.W_NO_SUCH_ZONE, result)
+
+        result = self.ds.start_transaction(transaction, True)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        result = self.ds.replace_zone(transaction, [])
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        result = self.ds.commit_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        result = []
+
+    def test_replace_zone_function(self):
+        transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
+        result = self.ds.start_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        result = []
+        n = self.ds.find_rrset(Name("www.example.com"), RRClass.IN(), RRType.A(), result, 0, Name("example.com"))
+        self.assertEqual(DataSrc.SUCCESS, n);
+        self.assertEqual(1, len(result))
+
+        result = []
+        n = self.ds.find_rrset(Name("example.com"), RRClass.IN(), RRType.SOA(), result, 0, Name("example.com"))
+        self.assertEqual(DataSrc.SUCCESS, n);
+        self.assertEqual(1, len(result))
+
+        rrset1 = result[0]
+        rrset2 = RRset(Name("added.example.com"), RRClass.IN(), RRType.A(), RRTTL(3600))
+        rrset2.add_rdata(Rdata(rrset2.get_type(), rrset2.get_class(), "192.0.2.1"))
+        rrset3 = RRset(Name("added2.example.com"), RRClass.IN(), RRType.A(), RRTTL(3600))
+        rrset3.add_rdata(Rdata(rrset3.get_type(), rrset3.get_class(), "192.0.2.2"))
+
+        new_rrs = [ rrset1, rrset2, rrset3 ]
+
         result = self.ds.replace_zone(transaction, get_new_rrs, new_rrs)
         self.assertEqual(DataSrc.W_SUCCESS, result)
 
@@ -409,6 +470,50 @@
         n = self.ds.find_rrset(Name("added.example.com"), RRClass.IN(), RRType.A(), result, 0, Name("example.com"))
         self.assertEqual(DataSrc.SUCCESS, n);
         self.assertEqual(1, len(result))
+
+    def test_replace_zone_function_not_rrset(self):
+        transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
+        result = self.ds.start_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        new_rrs = [ "Something that is not an RRset" ]
+
+        self.assertRaises(TypeError, self.ds.replace_zone, transaction, get_new_rrs, new_rrs)
+        result = self.ds.rollback_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+    def test_replace_zone_function_not_iterator(self):
+        transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
+        result = self.ds.start_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        new_rrs = [ "Something that is not an RRset" ]
+
+        self.assertRaises(TypeError, self.ds.replace_zone, transaction, get_new_rrs_no_iter, new_rrs)
+        result = self.ds.rollback_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+    def test_replace_zone_function_bad_call(self):
+        transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
+        result = self.ds.start_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        new_rrs = [ "Something that is not an RRset" ]
+
+        self.assertRaises(TypeError, self.ds.replace_zone, transaction, get_new_rrs_no_args, new_rrs)
+        result = self.ds.rollback_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+    def test_replace_zone_function_that_raises(self):
+        transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
+        result = self.ds.start_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        new_rrs = [ "Something that is not an RRset" ]
+
+        self.assertRaises(TypeError, self.ds.replace_zone, transaction, get_new_rrs_bad, new_rrs)
+        result = self.ds.rollback_transaction(transaction)
+        self.assertEqual(DataSrc.W_SUCCESS, result)
 
     def test_have_rrset(self):
         transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
@@ -488,6 +593,9 @@
         transaction = DataSrcTransaction(self.ds, Name("example.com"), RRClass.IN())
         result = self.ds.start_transaction(transaction)
         self.assertEqual(DataSrc.W_SUCCESS, result)
+
+        self.assertRaises(TypeError, self.ds.do_ixfr, transaction, 1)
+        self.assertRaises(TypeError, self.ds.do_ixfr)
 
         result = self.ds.do_ixfr(transaction, rrsets)
         self.assertEqual(DataSrc.W_ERROR, result)




More information about the bind10-changes mailing list