Explorar o código

Fix server and web tests for capabilities() conversion to instance method

Jelmer Vernooij hai 1 mes
pai
achega
bfe524d295
Modificáronse 3 ficheiros con 57 adicións e 20 borrados
  1. 2 5
      tests/compat/server_utils.py
  2. 21 5
      tests/compat/test_server.py
  3. 34 10
      tests/compat/test_web.py

+ 2 - 5
tests/compat/server_utils.py

@@ -350,12 +350,9 @@ class ServerTests:
 class NoSideBand64kReceivePackHandler(ReceivePackHandler):
     """ReceivePackHandler that does not support side-band-64k."""
 
-    @classmethod
-    def capabilities(cls):
+    def capabilities(self):
         return [
-            c
-            for c in ReceivePackHandler.capabilities()
-            if c != CAPABILITY_SIDE_BAND_64K
+            c for c in super().capabilities() if c != CAPABILITY_SIDE_BAND_64K
         ]
 
 

+ 21 - 5
tests/compat/test_server.py

@@ -54,15 +54,23 @@ class GitServerTestCase(ServerTests, CompatTestCase):
     def _handlers(self):
         return {b"git-receive-pack": NoSideBand64kReceivePackHandler}
 
-    def _check_server(self, dul_server) -> None:
+    def _check_server(self, dul_server, repo) -> None:
+        from dulwich.protocol import Protocol
+
         receive_pack_handler_cls = dul_server.handlers[b"git-receive-pack"]
-        caps = receive_pack_handler_cls.capabilities()
+        # Create a handler instance to check capabilities
+        handler = receive_pack_handler_cls(
+            dul_server.backend,
+            [b"/"],
+            Protocol(lambda x: b"", lambda x: None),
+        )
+        caps = handler.capabilities()
         self.assertNotIn(b"side-band-64k", caps)
 
     def _start_server(self, repo):
         backend = DictBackend({b"/": repo})
         dul_server = TCPGitServer(backend, b"localhost", 0, handlers=self._handlers())
-        self._check_server(dul_server)
+        self._check_server(dul_server, repo)
 
         # Start server in a thread
         server_thread = threading.Thread(target=dul_server.serve)
@@ -100,9 +108,17 @@ class GitServerSideBand64kTestCase(GitServerTestCase):
     def _handlers(self) -> None:
         return None  # default handlers include side-band-64k
 
-    def _check_server(self, server) -> None:
+    def _check_server(self, server, repo) -> None:
+        from dulwich.protocol import Protocol
+
         receive_pack_handler_cls = server.handlers[b"git-receive-pack"]
-        caps = receive_pack_handler_cls.capabilities()
+        # Create a handler instance to check capabilities
+        handler = receive_pack_handler_cls(
+            server.backend,
+            [b"/"],
+            Protocol(lambda x: b"", lambda x: None),
+        )
+        caps = handler.capabilities()
         self.assertIn(b"side-band-64k", caps)
 
 

+ 34 - 10
tests/compat/test_web.py

@@ -85,8 +85,16 @@ class SmartWebTestCase(WebTests, CompatTestCase):
         return {b"git-receive-pack": NoSideBand64kReceivePackHandler}
 
     def _check_app(self, app) -> None:
+        from dulwich.protocol import Protocol
+
         receive_pack_handler_cls = app.handlers[b"git-receive-pack"]
-        caps = receive_pack_handler_cls.capabilities()
+        # Create a handler instance to check capabilities
+        handler = receive_pack_handler_cls(
+            app.backend,
+            [b"/"],
+            Protocol(lambda x: b"", lambda x: None),
+        )
+        caps = handler.capabilities()
         self.assertNotIn(b"side-band-64k", caps)
 
     def _make_app(self, backend):
@@ -101,16 +109,16 @@ class SmartWebTestCase(WebTests, CompatTestCase):
 
 def patch_capabilities(handler, caps_removed):
     # Patch a handler's capabilities by specifying a list of them to be
-    # removed, and return the original classmethod for restoration.
+    # removed, and return the original method for restoration.
     original_capabilities = handler.capabilities
-    filtered_capabilities = [
-        i for i in original_capabilities() if i not in caps_removed
-    ]
 
-    def capabilities(cls):
-        return filtered_capabilities
+    def capabilities(self):
+        # Call original to get base capabilities (including object-format)
+        base_caps = original_capabilities(self)
+        # Filter out the capabilities we want to remove
+        return [i for i in base_caps if i not in caps_removed]
 
-    handler.capabilities = classmethod(capabilities)
+    handler.capabilities = capabilities
     return original_capabilities
 
 
@@ -135,8 +143,16 @@ class SmartWebSideBand64kTestCase(SmartWebTestCase):
         return None  # default handlers include side-band-64k
 
     def _check_app(self, app) -> None:
+        from dulwich.protocol import Protocol
+
         receive_pack_handler_cls = app.handlers[b"git-receive-pack"]
-        caps = receive_pack_handler_cls.capabilities()
+        # Create a handler instance to check capabilities
+        handler = receive_pack_handler_cls(
+            app.backend,
+            [b"/"],
+            Protocol(lambda x: b"", lambda x: None),
+        )
+        caps = handler.capabilities()
         self.assertIn(b"side-band-64k", caps)
         self.assertNotIn(b"no-done", caps)
 
@@ -153,8 +169,16 @@ class SmartWebSideBand64kNoDoneTestCase(SmartWebTestCase):
         return None  # default handlers include side-band-64k
 
     def _check_app(self, app) -> None:
+        from dulwich.protocol import Protocol
+
         receive_pack_handler_cls = app.handlers[b"git-receive-pack"]
-        caps = receive_pack_handler_cls.capabilities()
+        # Create a handler instance to check capabilities
+        handler = receive_pack_handler_cls(
+            app.backend,
+            [b"/"],
+            Protocol(lambda x: b"", lambda x: None),
+        )
+        caps = handler.capabilities()
         self.assertIn(b"side-band-64k", caps)
         self.assertIn(b"no-done", caps)