BIND 10 trac2018, updated. f9ec0f7c7b3d60c19b258f2c0d95edb7d4a3e8a1 [2018] move module-level tests to own test class
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Jun 5 10:03:19 UTC 2012
The branch, trac2018 has been updated
via f9ec0f7c7b3d60c19b258f2c0d95edb7d4a3e8a1 (commit)
via e33d599164b3d1de0617da52ae2b1153238e11d1 (commit)
via 47965690b14b7567183ee041e5ba302b287141e3 (commit)
via 38292a61825ac30e3a589d8b0922c42ad3437055 (commit)
from 6f8dbd0f299c6c0f97cf24e87116fa32f43c8a0f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f9ec0f7c7b3d60c19b258f2c0d95edb7d4a3e8a1
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Jun 5 12:02:10 2012 +0200
[2018] move module-level tests to own test class
commit e33d599164b3d1de0617da52ae2b1153238e11d1
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Jun 5 11:58:34 2012 +0200
[2018] update docstrings
commit 47965690b14b7567183ee041e5ba302b287141e3
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Jun 5 11:56:04 2012 +0200
[2018] separate diff creation from get_update_zone
and made get_update_zone protected instead of private
commit 38292a61825ac30e3a589d8b0922c42ad3437055
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Jun 5 11:27:00 2012 +0200
[2018] replace diff.get_updater by find() and find_all()
-----------------------------------------------------------------------
Summary of changes:
src/lib/python/isc/ddns/libddns_messages.mes | 2 +-
src/lib/python/isc/ddns/session.py | 103 +++++++------
src/lib/python/isc/ddns/tests/session_tests.py | 190 ++++++++++++------------
src/lib/python/isc/xfrin/diff.py | 26 +++-
src/lib/python/isc/xfrin/tests/diff_tests.py | 86 +++++++++++
5 files changed, 262 insertions(+), 145 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/ddns/libddns_messages.mes b/src/lib/python/isc/ddns/libddns_messages.mes
index dad516f..d6bea7d 100644
--- a/src/lib/python/isc/ddns/libddns_messages.mes
+++ b/src/lib/python/isc/ddns/libddns_messages.mes
@@ -194,7 +194,7 @@ should give more information on what prerequisite type failed.
If the result code is FORMERR, the prerequisite section was not well-formed.
An error response with the given result code is sent back to the client.
-% LIBDDNS_UPDATE_UNCAUGHT_EXCEPTION update client %1 for zone %2: uncaught exception while processing update section: %1
+% LIBDDNS_UPDATE_UNCAUGHT_EXCEPTION update client %1 for zone %2: uncaught exception while processing update section: %3
An uncaught exception was encountered while processing the Update
section of a DDNS message. The specific exception is shown in the log message.
To make sure DDNS service is not interrupted, this problem is caught instead
diff --git a/src/lib/python/isc/ddns/session.py b/src/lib/python/isc/ddns/session.py
index fa51d0e..31c724a 100644
--- a/src/lib/python/isc/ddns/session.py
+++ b/src/lib/python/isc/ddns/session.py
@@ -189,13 +189,13 @@ class UpdateSession:
'''
try:
- self.__get_update_zone()
- # conceptual code that would follow
+ self._get_update_zone()
+ self.__check_update_acl(self.__zname, self.__zclass)
+ self._create_diff()
prereq_result = self.__check_prerequisites()
if prereq_result != Rcode.NOERROR():
self.__make_response(prereq_result)
return UPDATE_ERROR, self.__zname, self.__zclass
- self.__check_update_acl(self.__zname, self.__zclass)
update_result = self.__do_update()
if update_result != Rcode.NOERROR():
self.__make_response(update_result)
@@ -215,7 +215,7 @@ class UpdateSession:
self.__message = None
return UPDATE_DROP, None, None
- def __get_update_zone(self):
+ def _get_update_zone(self):
'''Parse the zone section and find the zone to be updated.
If the zone section is valid and the specified zone is found in
@@ -224,8 +224,11 @@ class UpdateSession:
zone
__zname: The zone name as a Name object
__zclass: The zone class as an RRClass object
- __finder: A ZoneFinder for this zone
- If this method raises an exception, these members are not set
+ If this method raises an exception, these members are not set.
+
+ Note: This method is protected for ease of use in tests, where
+ methods are tested that need the setup done here without calling
+ the full handle() method.
'''
# Validation: the zone section must contain exactly one question,
# and it must be of type SOA.
@@ -243,19 +246,9 @@ class UpdateSession:
zclass = zrecord.get_class()
zone_type, datasrc_client = self.__zone_config.find_zone(zname, zclass)
if zone_type == isc.ddns.zone_config.ZONE_PRIMARY:
- # create an ixfr-out-friendly diff structure to work on
- self.__diff = isc.xfrin.diff.Diff(datasrc_client, zname,
- journaling=True,
- single_update_mode=True)
- # Note that while it is really the ZoneUpdater that is set
- # here, it is still called finder, as the only methods that
- # are and should be used on this object are find() and find_all()
- # (ZoneUpdater provides the ZoneFinder interface itself, no
- # separate get_zone_finder())
- self.__finder = self.__diff.get_updater()
+ self.__datasrc_client = datasrc_client
self.__zname = zname
self.__zclass = zclass
- self.__datasrc_client = datasrc_client
return
elif zone_type == isc.ddns.zone_config.ZONE_SECONDARY:
# We are a secondary server; since we don't yet support update
@@ -270,6 +263,26 @@ class UpdateSession:
ZoneFormatter(zname, zclass))
raise UpdateError('notauth', zname, zclass, Rcode.NOTAUTH(), True)
+ def _create_diff(self):
+ '''
+ Initializes the internal data structure used for searching current
+ data and for adding and deleting data. This is supposed to be called
+ after ACL checks but before prerequisite checks (since the latter
+ needs the find calls provided by the Diff class).
+ Adds the private member:
+ __diff: A buffer of changes made against the zone by this update
+ This object also contains find() calls, see documentation
+ of the Diff class.
+
+ Note: This method is protected for ease of use in tests, where
+ methods are tested that need the setup done here without calling
+ the full handle() method.
+ '''
+ self.__diff = isc.xfrin.diff.Diff(self.__datasrc_client,
+ self.__zname,
+ journaling=True,
+ single_update_mode=True)
+
def __check_update_acl(self, zname, zclass):
'''Apply update ACL for the zone to be updated.'''
acl = self.__zone_config.get_update_acl(zname, zclass)
@@ -313,9 +326,9 @@ class UpdateSession:
only return what the result code would be (and not read/copy
any actual data).
'''
- result, _, _ = self.__finder.find(rrset.get_name(), rrset.get_type(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, _, _ = self.__diff.find(rrset.get_name(), rrset.get_type(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
return result == ZoneFinder.SUCCESS
def __prereq_rrset_exists_value(self, rrset):
@@ -324,10 +337,10 @@ class UpdateSession:
RFC2136 Section 2.4.2
Returns True if the prerequisite is satisfied, False otherwise.
'''
- result, found_rrset, _ = self.__finder.find(rrset.get_name(),
- rrset.get_type(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, found_rrset, _ = self.__diff.find(rrset.get_name(),
+ rrset.get_type(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
if result == ZoneFinder.SUCCESS and\
rrset.get_name() == found_rrset.get_name() and\
rrset.get_type() == found_rrset.get_type():
@@ -366,9 +379,9 @@ class UpdateSession:
to only return what the result code would be (and not read/copy
any actual data).
'''
- result, rrsets, flags = self.__finder.find_all(rrset.get_name(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, rrsets, flags = self.__diff.find_all(rrset.get_name(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
if result == ZoneFinder.SUCCESS and\
(flags & ZoneFinder.RESULT_WILDCARD == 0):
return True
@@ -592,10 +605,10 @@ class UpdateSession:
# is explicitely ignored here)
if rrset.get_type() == RRType.SOA():
return
- result, orig_rrset, _ = self.__finder.find(rrset.get_name(),
- rrset.get_type(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, orig_rrset, _ = self.__diff.find(rrset.get_name(),
+ rrset.get_type(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
if result == ZoneFinder.CNAME:
# Ignore non-cname rrs that try to update CNAME records
# (if rrset itself is a CNAME, the finder result would be
@@ -626,10 +639,10 @@ class UpdateSession:
Special cases: if the delete statement is for the
zone's apex, and the type is either SOA or NS, it
is ignored.'''
- result, to_delete, _ = self.__finder.find(rrset.get_name(),
- rrset.get_type(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, to_delete, _ = self.__diff.find(rrset.get_name(),
+ rrset.get_type(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
if result == ZoneFinder.SUCCESS:
if to_delete.get_name() == self.__zname and\
(to_delete.get_type() == RRType.SOA() or\
@@ -651,10 +664,10 @@ class UpdateSession:
# (see ticket #2016)
# The related test is currently disabled. When this is fixed,
# enable that test again.
- result, orig_rrset, _ = self.__finder.find(rrset.get_name(),
- rrset.get_type(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, orig_rrset, _ = self.__diff.find(rrset.get_name(),
+ rrset.get_type(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
# Even a real rrset comparison wouldn't help here...
# The goal is to make sure that after deletion of the
# given rrset, at least 1 NS record is left (at the apex).
@@ -684,9 +697,9 @@ class UpdateSession:
Special case: if the name is the zone's apex, SOA and
NS records are kept.
'''
- result, rrsets, flags = self.__finder.find_all(rrset.get_name(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, rrsets, flags = self.__diff.find_all(rrset.get_name(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
if result == ZoneFinder.SUCCESS and\
(flags & ZoneFinder.RESULT_WILDCARD == 0):
for to_delete in rrsets:
@@ -736,9 +749,9 @@ class UpdateSession:
# serial magic and add the newly created one
# get it from DS and to increment and stuff
- result, old_soa, _ = self.__finder.find(self.__zname, RRType.SOA(),
- ZoneFinder.NO_WILDCARD |
- ZoneFinder.FIND_GLUE_OK)
+ result, old_soa, _ = self.__diff.find(self.__zname, RRType.SOA(),
+ ZoneFinder.NO_WILDCARD |
+ ZoneFinder.FIND_GLUE_OK)
if self.__added_soa is not None:
new_soa = self.__added_soa
diff --git a/src/lib/python/isc/ddns/tests/session_tests.py b/src/lib/python/isc/ddns/tests/session_tests.py
index cbcac12..3e7ace5 100644
--- a/src/lib/python/isc/ddns/tests/session_tests.py
+++ b/src/lib/python/isc/ddns/tests/session_tests.py
@@ -94,6 +94,97 @@ def create_rrset(name, rrclass, rrtype, ttl, rdatas = []):
add_rdata(rrset, rdata)
return rrset
+class SessionModuleTests(unittest.TestCase):
+ '''Tests for module-level functions in the session.py module'''
+
+ def test_foreach_rr_in_rrset(self):
+ rrset = create_rrset("www.example.org", TEST_RRCLASS,
+ RRType.A(), 3600, [ "192.0.2.1" ])
+
+ l = []
+ for rr in foreach_rr(rrset):
+ l.append(str(rr))
+ self.assertEqual(["www.example.org. 3600 IN A 192.0.2.1\n"], l)
+
+ add_rdata(rrset, "192.0.2.2")
+ add_rdata(rrset, "192.0.2.3")
+
+ # but through the generator, there should be several 1-line entries
+ l = []
+ for rr in foreach_rr(rrset):
+ l.append(str(rr))
+ self.assertEqual(["www.example.org. 3600 IN A 192.0.2.1\n",
+ "www.example.org. 3600 IN A 192.0.2.2\n",
+ "www.example.org. 3600 IN A 192.0.2.3\n",
+ ], l)
+
+ def test_convert_rrset_class(self):
+ # Converting an RRSET to a different class should work
+ # if the rdata types can be converted
+ rrset = create_rrset("www.example.org", RRClass.NONE(), RRType.A(),
+ 3600, [ b'\xc0\x00\x02\x01', b'\xc0\x00\x02\x02'])
+
+ rrset2 = convert_rrset_class(rrset, RRClass.IN())
+ self.assertEqual("www.example.org. 3600 IN A 192.0.2.1\n" +
+ "www.example.org. 3600 IN A 192.0.2.2\n",
+ str(rrset2))
+
+ rrset3 = convert_rrset_class(rrset2, RRClass.NONE())
+ self.assertEqual("www.example.org. 3600 CLASS254 A \\# 4 " +
+ "c0000201\nwww.example.org. 3600 CLASS254 " +
+ "A \\# 4 c0000202\n",
+ str(rrset3))
+
+ # depending on what type of bad data is given, a number
+ # of different exceptions could be raised (TODO: i recall
+ # there was a ticket about making a better hierarchy for
+ # dns/parsing related exceptions)
+ self.assertRaises(InvalidRdataLength, convert_rrset_class,
+ rrset, RRClass.CH())
+ add_rdata(rrset, b'\xc0\x00')
+ self.assertRaises(DNSMessageFORMERR, convert_rrset_class,
+ rrset, RRClass.IN())
+
+ def test_collect_rrsets(self):
+ '''
+ Tests the 'rrset collector' method, which collects rrsets
+ with the same name and type
+ '''
+ collected = []
+
+ collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
+ RRType.A(), 0, [ "192.0.2.1" ]))
+ # Same name and class, different type
+ collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
+ RRType.TXT(), 0, [ "one" ]))
+ collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
+ RRType.A(), 0, [ "192.0.2.2" ]))
+ collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
+ RRType.TXT(), 0, [ "two" ]))
+ # Same class and type as an existing one, different name
+ collect_rrsets(collected, create_rrset("b.example.org", RRClass.IN(),
+ RRType.A(), 0, [ "192.0.2.3" ]))
+ # Same name and type as an existing one, different class
+ collect_rrsets(collected, create_rrset("a.example.org", RRClass.CH(),
+ RRType.TXT(), 0, [ "one" ]))
+ collect_rrsets(collected, create_rrset("b.example.org", RRClass.IN(),
+ RRType.A(), 0, [ "192.0.2.4" ]))
+ collect_rrsets(collected, create_rrset("a.example.org", RRClass.CH(),
+ RRType.TXT(), 0, [ "two" ]))
+
+ strings = [ rrset.to_text() for rrset in collected ]
+ # note + vs , in this list
+ expected = ['a.example.org. 0 IN A 192.0.2.1\n' +
+ 'a.example.org. 0 IN A 192.0.2.2\n',
+ 'a.example.org. 0 IN TXT "one"\n' +
+ 'a.example.org. 0 IN TXT "two"\n',
+ 'b.example.org. 0 IN A 192.0.2.3\n' +
+ 'b.example.org. 0 IN A 192.0.2.4\n',
+ 'a.example.org. 0 CH TXT "one"\n' +
+ 'a.example.org. 0 CH TXT "two"\n']
+
+ self.assertEqual(expected, strings)
+
class SessionTestBase(unittest.TestCase):
'''Base class for all sesion related tests.
@@ -112,10 +203,11 @@ class SessionTestBase(unittest.TestCase):
ZoneConfig([], TEST_RRCLASS,
self._datasrc_client,
self._acl_map))
- self._session._UpdateSession__get_update_zone()
+ self._session._get_update_zone()
+ self._session._create_diff()
def tearDown(self):
- # With the Updater created in __get_update_zone, and tests
+ # With the Updater created in _get_update_zone, and tests
# doing all kinds of crazy stuff, one might get database locked
# errors if it doesn't clean up explicitely after each test
self._session = None
@@ -200,94 +292,6 @@ class SessionTest(SessionTestBase):
# zone class doesn't match
self.check_notauth(Name('example.org'), RRClass.CH())
- def test_foreach_rr_in_rrset(self):
- rrset = create_rrset("www.example.org", TEST_RRCLASS,
- RRType.A(), 3600, [ "192.0.2.1" ])
-
- l = []
- for rr in foreach_rr(rrset):
- l.append(str(rr))
- self.assertEqual(["www.example.org. 3600 IN A 192.0.2.1\n"], l)
-
- add_rdata(rrset, "192.0.2.2")
- add_rdata(rrset, "192.0.2.3")
-
- # but through the generator, there should be several 1-line entries
- l = []
- for rr in foreach_rr(rrset):
- l.append(str(rr))
- self.assertEqual(["www.example.org. 3600 IN A 192.0.2.1\n",
- "www.example.org. 3600 IN A 192.0.2.2\n",
- "www.example.org. 3600 IN A 192.0.2.3\n",
- ], l)
-
- def test_convert_rrset_class(self):
- # Converting an RRSET to a different class should work
- # if the rdata types can be converted
- rrset = create_rrset("www.example.org", RRClass.NONE(), RRType.A(),
- 3600, [ b'\xc0\x00\x02\x01', b'\xc0\x00\x02\x02'])
-
- rrset2 = convert_rrset_class(rrset, RRClass.IN())
- self.assertEqual("www.example.org. 3600 IN A 192.0.2.1\n" +
- "www.example.org. 3600 IN A 192.0.2.2\n",
- str(rrset2))
-
- rrset3 = convert_rrset_class(rrset2, RRClass.NONE())
- self.assertEqual("www.example.org. 3600 CLASS254 A \\# 4 " +
- "c0000201\nwww.example.org. 3600 CLASS254 " +
- "A \\# 4 c0000202\n",
- str(rrset3))
-
- # depending on what type of bad data is given, a number
- # of different exceptions could be raised (TODO: i recall
- # there was a ticket about making a better hierarchy for
- # dns/parsing related exceptions)
- self.assertRaises(InvalidRdataLength, convert_rrset_class,
- rrset, RRClass.CH())
- add_rdata(rrset, b'\xc0\x00')
- self.assertRaises(DNSMessageFORMERR, convert_rrset_class,
- rrset, RRClass.IN())
-
- def test_collect_rrsets(self):
- '''
- Tests the 'rrset collector' method, which collects rrsets
- with the same name and type
- '''
- collected = []
-
- collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
- RRType.A(), 0, [ "192.0.2.1" ]))
- # Same name and class, different type
- collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
- RRType.TXT(), 0, [ "one" ]))
- collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
- RRType.A(), 0, [ "192.0.2.2" ]))
- collect_rrsets(collected, create_rrset("a.example.org", RRClass.IN(),
- RRType.TXT(), 0, [ "two" ]))
- # Same class and type as an existing one, different name
- collect_rrsets(collected, create_rrset("b.example.org", RRClass.IN(),
- RRType.A(), 0, [ "192.0.2.3" ]))
- # Same name and type as an existing one, different class
- collect_rrsets(collected, create_rrset("a.example.org", RRClass.CH(),
- RRType.TXT(), 0, [ "one" ]))
- collect_rrsets(collected, create_rrset("b.example.org", RRClass.IN(),
- RRType.A(), 0, [ "192.0.2.4" ]))
- collect_rrsets(collected, create_rrset("a.example.org", RRClass.CH(),
- RRType.TXT(), 0, [ "two" ]))
-
- strings = [ rrset.to_text() for rrset in collected ]
- # note + vs , in this list
- expected = ['a.example.org. 0 IN A 192.0.2.1\n' +
- 'a.example.org. 0 IN A 192.0.2.2\n',
- 'a.example.org. 0 IN TXT "one"\n' +
- 'a.example.org. 0 IN TXT "two"\n',
- 'b.example.org. 0 IN A 192.0.2.3\n' +
- 'b.example.org. 0 IN A 192.0.2.4\n',
- 'a.example.org. 0 CH TXT "one"\n' +
- 'a.example.org. 0 CH TXT "two"\n']
-
- self.assertEqual(expected, strings)
-
def __check_prerequisite_exists_combined(self, method, rrclass, expected):
'''shared code for the checks for the very similar (but reversed
in behaviour) methods __prereq_rrset_exists and
@@ -448,7 +452,8 @@ class SessionTest(SessionTestBase):
zconfig = ZoneConfig([], TEST_RRCLASS, self._datasrc_client,
self._acl_map)
session = UpdateSession(msg, TEST_CLIENT4, zconfig)
- session._UpdateSession__get_update_zone()
+ session._get_update_zone()
+ session._create_diff()
# compare the to_text output of the rcodes (nicer error messages)
# This call itself should also be done by handle(),
# but just for better failures, it is first called on its own
@@ -473,7 +478,8 @@ class SessionTest(SessionTestBase):
zconfig = ZoneConfig([], TEST_RRCLASS, self._datasrc_client,
self._acl_map)
session = UpdateSession(msg, TEST_CLIENT4, zconfig)
- session._UpdateSession__get_update_zone()
+ session._get_update_zone()
+ session._create_diff()
# compare the to_text output of the rcodes (nicer error messages)
# This call itself should also be done by handle(),
# but just for better failures, it is first called on its own
diff --git a/src/lib/python/isc/xfrin/diff.py b/src/lib/python/isc/xfrin/diff.py
index a3a9d7d..b03669d 100644
--- a/src/lib/python/isc/xfrin/diff.py
+++ b/src/lib/python/isc/xfrin/diff.py
@@ -377,12 +377,24 @@ class Diff:
else:
return (self.__deletions, self.__additions)
- def get_updater(self):
+ def find(self, name, rrtype, options=isc.datasrc.ZoneFinder.FIND_DEFAULT):
"""
- Returns the ZoneUpdater associated with this Diff instance.
- While update statements can be used on this updater, its main
- goal is to provide the ZoneFinder interface for searching through
- the zone as it was on the moment the updater was created.
- If the Diff has been committed, this will return None.
+ Calls the find() method in the ZoneFinder associated with this
+ Diff's ZoneUpdater, i.e. the find() on the zone as it was on the
+ moment this Diff object got created.
+ See the ZoneFinder documentation for a full description.
+ Note that the result does not include changes made in this Diff
+ instance so far.
"""
- return self.__updater
+ return self.__updater.find(name, rrtype, options)
+
+ def find_all(self, name, options=isc.datasrc.ZoneFinder.FIND_DEFAULT):
+ """
+ Calls the find() method in the ZoneFinder associated with this
+ Diff's ZoneUpdater, i.e. the find_all() on the zone as it was on the
+ moment this Diff object got created.
+ See the ZoneFinder documentation for a full description.
+ Note that the result does not include changes made in this Diff
+ instance so far.
+ """
+ return self.__updater.find_all(name, options)
diff --git a/src/lib/python/isc/xfrin/tests/diff_tests.py b/src/lib/python/isc/xfrin/tests/diff_tests.py
index 6c545d2..bbfcc9e 100644
--- a/src/lib/python/isc/xfrin/tests/diff_tests.py
+++ b/src/lib/python/isc/xfrin/tests/diff_tests.py
@@ -48,6 +48,13 @@ class DiffTest(unittest.TestCase):
self.__broken_called = False
self.__warn_called = False
self.__should_replace = False
+ self.__find_called = False
+ self.__find_name = None
+ self.__find_type = None
+ self.__find_options = None
+ self.__find_all_called = False
+ self.__find_all_name = None
+ self.__find_all_options = None
# Some common values
self.__rrclass = RRClass.IN()
self.__type = RRType.A()
@@ -156,6 +163,23 @@ class DiffTest(unittest.TestCase):
return self
+ def find(self, name, rrtype, options=None):
+ self.__find_called = True
+ self.__find_name = name
+ self.__find_type = rrtype
+ self.__find_options = options
+ # Doesn't really matter what is returned, as long
+ # as the test can check that it's passed along
+ return "find_return"
+
+ def find_all(self, name, options=None):
+ self.__find_all_called = True
+ self.__find_all_name = name
+ self.__find_all_options = options
+ # Doesn't really matter what is returned, as long
+ # as the test can check that it's passed along
+ return "find_all_return"
+
def test_create(self):
"""
This test the case when the diff is successfuly created. It just
@@ -587,6 +611,68 @@ class DiffTest(unittest.TestCase):
self.assertRaises(ValueError, diff.add_data, a)
self.assertRaises(ValueError, diff.delete_data, a)
+ def test_find(self):
+ diff = Diff(self, Name('example.org.'))
+ name = Name('www.example.org.')
+ rrtype = RRType.A()
+
+ self.assertFalse(self.__find_called)
+ self.assertEqual(None, self.__find_name)
+ self.assertEqual(None, self.__find_type)
+ self.assertEqual(None, self.__find_options)
+
+ self.assertEqual("find_return", diff.find(name, rrtype))
+
+ self.assertTrue(self.__find_called)
+ self.assertEqual(name, self.__find_name)
+ self.assertEqual(rrtype, self.__find_type)
+ self.assertEqual(isc.datasrc.ZoneFinder.FIND_DEFAULT,
+ self.__find_options)
+
+ def test_find_options(self):
+ diff = Diff(self, Name('example.org.'))
+ name = Name('foo.example.org.')
+ rrtype = RRType.TXT()
+ options = isc.datasrc.ZoneFinder.NO_WILDCARD |\
+ isc.datasrc.ZoneFinder.FIND_GLUE_OK
+
+ self.assertEqual("find_return", diff.find(name, rrtype, options))
+
+ self.assertTrue(self.__find_called)
+ self.assertEqual(name, self.__find_name)
+ self.assertEqual(rrtype, self.__find_type)
+ self.assertEqual(options, self.__find_options)
+
+ def test_find_all(self):
+ diff = Diff(self, Name('example.org.'))
+ name = Name('www.example.org.')
+
+ self.assertFalse(self.__find_all_called)
+ self.assertEqual(None, self.__find_all_name)
+ self.assertEqual(None, self.__find_all_options)
+
+ self.assertEqual("find_all_return", diff.find_all(name))
+
+ self.assertTrue(self.__find_all_called)
+ self.assertEqual(name, self.__find_all_name)
+ self.assertEqual(isc.datasrc.ZoneFinder.FIND_DEFAULT,
+ self.__find_all_options)
+
+ def test_find_all_options(self):
+ diff = Diff(self, Name('example.org.'))
+ name = Name('www.example.org.')
+ options = isc.datasrc.ZoneFinder.NO_WILDCARD |\
+ isc.datasrc.ZoneFinder.FIND_GLUE_OK
+
+ self.assertFalse(self.__find_all_called)
+ self.assertEqual(None, self.__find_all_name)
+ self.assertEqual(None, self.__find_all_options)
+
+ self.assertEqual("find_all_return", diff.find_all(name, options))
+
+ self.assertTrue(self.__find_all_called)
+ self.assertEqual(name, self.__find_all_name)
+ self.assertEqual(options, self.__find_all_options)
if __name__ == "__main__":
isc.log.init("bind10")
More information about the bind10-changes
mailing list