Browse Source

[1261] made clear XfrinState().handle_rr() shouldn't be called directly
via an exception. added a test for that.

JINMEI Tatuya 13 years ago
parent
commit
3898b36a13
2 changed files with 14 additions and 2 deletions
  1. 9 0
      src/bin/xfrin/tests/xfrin_test.py
  2. 5 2
      src/bin/xfrin/xfrin.py.in

+ 9 - 0
src/bin/xfrin/tests/xfrin_test.py

@@ -267,6 +267,15 @@ class TestXfrinState(unittest.TestCase):
         self.conn._datasrc_client = MockDataSourceClient()
         self.conn._diff = Diff(MockDataSourceClient(), TEST_ZONE_NAME)
 
+class TestXfrinStateBase(TestXfrinState):
+    def setUp(self):
+        super().setUp()
+
+    def test_handle_rr_on_base(self):
+        # The base version of handle_rr() isn't supposed to be called
+        # directly (the argument doesn't matter in this test)
+        self.assertRaises(XfrinException, XfrinState().handle_rr, None)
+
 class TestXfrinInitialSOA(TestXfrinState):
     def setUp(self):
         super().setUp()

+ 5 - 2
src/bin/xfrin/xfrin.py.in

@@ -204,7 +204,9 @@ class XfrinState:
         sequence or completing the session.
 
         All subclass has their specific behaviors for this method, so
-        there is no default definition.
+        there is no default definition.  If the base class version
+        is called, it's a bug of the caller, and it's notified via
+        an XfrinException exception.
 
         This method returns a boolean value: True if the given RR was
         fully handled and the caller should go to the next RR; False
@@ -212,7 +214,8 @@ class XfrinState:
         state for the same RR again.
 
         '''
-        pass
+        raise XfrinException("Internal bug: " +
+                             "XfrinState.handle_rr() called directly")
 
     def finish_message(self, conn):
         '''Perform any final processing after handling all RRs of a response.