Rev 4002: Fix do_body NotImplementedError log spam, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Feb 12 02:40:04 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4002
revision-id: pqm at pqm.ubuntu.com-20090212024000-dvdhpm2mela5h6f7
parent: pqm at pqm.ubuntu.com-20090211033438-3yqumzd9miadfc7r
parent: andrew.bennetts at canonical.com-20090211095436-96dwxqkzc79iybxy
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-02-12 02:40:00 +0000
message:
  Fix do_body NotImplementedError log spam,
  	and remove a bit of test cruft. (Andrew Bennetts)
added:
  bzrlib/tests/test_smart_request.py test_smart_request.p-20090211070731-o38wayv3asm25d6a-1
modified:
  bzrlib/smart/request.py        request.py-20061108095550-gunadhxmzkdjfeek-1
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
    ------------------------------------------------------------
    revno: 3990.3.3
    revision-id: andrew.bennetts at canonical.com-20090211095436-96dwxqkzc79iybxy
    parent: andrew.bennetts at canonical.com-20090211094527-pdtj25e4748c2h67
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: request handler tests
    timestamp: Wed 2009-02-11 20:54:36 +1100
    message:
      Add a test that unexpected request bodies trigger a SmartProtocolError from request implementations.
    modified:
      bzrlib/smart/request.py        request.py-20061108095550-gunadhxmzkdjfeek-1
      bzrlib/tests/test_smart_request.py test_smart_request.p-20090211070731-o38wayv3asm25d6a-1
    ------------------------------------------------------------
    revno: 3990.3.2
    revision-id: andrew.bennetts at canonical.com-20090211094527-pdtj25e4748c2h67
    parent: andrew.bennetts at canonical.com-20090211070642-987ocatad8vcpo9n
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: request handler tests
    timestamp: Wed 2009-02-11 20:45:27 +1100
    message:
      Fix the do_body NotImplementedError log spam.
    added:
      bzrlib/tests/test_smart_request.py test_smart_request.p-20090211070731-o38wayv3asm25d6a-1
    modified:
      bzrlib/smart/request.py        request.py-20061108095550-gunadhxmzkdjfeek-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
    ------------------------------------------------------------
    revno: 3990.3.1
    revision-id: andrew.bennetts at canonical.com-20090211070642-987ocatad8vcpo9n
    parent: pqm at pqm.ubuntu.com-20090209210810-cq9lgqy519b7wfyi
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: Delete cruft
    timestamp: Wed 2009-02-11 18:06:42 +1100
    message:
      Remove some cruft from test_smart_transport.
    modified:
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2009-01-27 07:48:55 +0000
+++ b/bzrlib/smart/request.py	2009-02-11 09:54:36 +0000
@@ -104,7 +104,8 @@
         
         Must return a SmartServerResponse.
         """
-        raise NotImplementedError(self.do_body)
+        if body_bytes != '':
+            raise errors.SmartProtocolError('Request does not expect a body')
 
     def do_chunk(self, chunk_bytes):
         """Called with each body chunk if the request has a streamed body.

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-01-15 09:01:42 +0000
+++ b/bzrlib/tests/__init__.py	2009-02-11 09:45:27 +0000
@@ -2874,6 +2874,7 @@
                    'bzrlib.tests.test_shelf_ui',
                    'bzrlib.tests.test_smart',
                    'bzrlib.tests.test_smart_add',
+                   'bzrlib.tests.test_smart_request',
                    'bzrlib.tests.test_smart_transport',
                    'bzrlib.tests.test_smtp_connection',
                    'bzrlib.tests.test_source',

=== added file 'bzrlib/tests/test_smart_request.py'
--- a/bzrlib/tests/test_smart_request.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_smart_request.py	2009-02-11 09:54:36 +0000
@@ -0,0 +1,62 @@
+# Copyright (C) 2009 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for smart server request infrastructure (bzrlib.smart.request)."""
+
+from bzrlib import errors
+from bzrlib.smart import request
+from bzrlib.tests import TestCase
+
+
+class NoBodyRequest(request.SmartServerRequest):
+    """A request that does not implement do_body."""
+
+    def do(self):
+        return request.SuccessfulSmartServerResponse(('ok',))
+
+
+class TestSmartRequest(TestCase):
+
+    def test_request_class_without_do_body(self):
+        """If a request has no body data, and the request's implementation does
+        not override do_body, then no exception is raised.
+        """
+        # Create a SmartServerRequestHandler with a SmartServerRequest subclass
+        # that does not implement do_body.
+        handler = request.SmartServerRequestHandler(
+            None, {'foo': NoBodyRequest}, '/')
+        # Emulate a request with no body (i.e. just args).
+        handler.args_received(('foo',))
+        handler.end_received()
+        # Request done, no exception was raised.
+
+    def test_unexpected_body(self):
+        """If a request implementation receives an unexpected body, it
+        raises an error.
+        """
+        # Create a SmartServerRequestHandler with a SmartServerRequest subclass
+        # that does not implement do_body.
+        handler = request.SmartServerRequestHandler(
+            None, {'foo': NoBodyRequest}, '/')
+        # Emulate a request with a body
+        handler.args_received(('foo',))
+        handler.accept_body('some body bytes')
+        # Note that the exception currently occurs at the end of the request.
+        # In principle it would also be ok for it to happen earlier, during
+        # accept_body.
+        exc = self.assertRaises(errors.SmartProtocolError, handler.end_received)
+        self.assertEquals('Request does not expect a body', exc.details)
+

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2009-01-27 05:04:43 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2009-02-11 09:45:27 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, 2007 Canonical Ltd
+# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -2270,14 +2270,6 @@
         self.assertEqual(4, smart_protocol.next_read_size())
 
 
-class NoOpRequest(_mod_request.SmartServerRequest):
-
-    def do(self):
-        return _mod_request.SuccessfulSmartServerResponse(())
-
-dummy_registry = {'ARG': NoOpRequest}
-
-
 class LoggingMessageHandler(object):
 
     def __init__(self):
@@ -3555,34 +3547,3 @@
         self.assertNotEquals(type(r), type(t))
 
 
-# TODO: Client feature that does get_bundle and then installs that into a
-# branch; this can be used in place of the regular pull/fetch operation when
-# coming from a smart server.
-#
-# TODO: Eventually, want to do a 'branch' command by fetching the whole
-# history as one big bundle.  How?  
-#
-# The branch command does 'br_from.sprout', which tries to preserve the same
-# format.  We don't necessarily even want that.  
-#
-# It might be simpler to handle cmd_pull first, which does a simpler fetch()
-# operation from one branch into another.  It already has some code for
-# pulling from a bundle, which it does by trying to see if the destination is
-# a bundle file.  So it seems the logic for pull ought to be:
-# 
-#  - if it's a smart server, get a bundle from there and install that
-#  - if it's a bundle, install that
-#  - if it's a branch, pull from there
-#
-# Getting a bundle from a smart server is a bit different from reading a
-# bundle from a URL:
-#
-#  - we can reasonably remember the URL we last read from 
-#  - you can specify a revision number to pull, and we need to pass it across
-#    to the server as a limit on what will be requested
-#
-# TODO: Given a URL, determine whether it is a smart server or not (or perhaps
-# otherwise whether it's a bundle?)  Should this be a property or method of
-# the transport?  For the ssh protocol, we always know it's a smart server.
-# For http, we potentially need to probe.  But if we're explicitly given
-# bzr+http:// then we can skip that for now. 




More information about the bazaar-commits mailing list