Merge Dave's fixes for the compatibility tests and web.
[jelmer/dulwich-libgit2.git] / dulwich / tests / test_web.py
index 0a4817fa8e8e6b4be8cf8a89feccbad0c18529fc..17bf499dff32f2ad8a9e33a61cd67927e35b7448 100644 (file)
@@ -109,24 +109,18 @@ class DumbHandlersTestCase(WebTestCase):
 
         tag1 = TestTag('aaa', Blob, '222')
 
 
         tag1 = TestTag('aaa', Blob, '222')
 
-        class TestBackend(object):
+        class TestRepo(object):
 
 
-            def __init__(self):
-                objects = [blob1, blob2, blob3, tag1]
+            def __init__(self, objects, peeled):
                 self._objects = dict((o.sha(), o) for o in objects)
                 self._objects = dict((o.sha(), o) for o in objects)
-                self._peeled = {
-                    'HEAD': '000',
-                    'refs/heads/master': blob1.sha(),
-                    'refs/tags/tag-tag': blob2.sha(),
-                    'refs/tags/blob-tag': blob3.sha(),
-                    }
-
-            def __getitem__(self, sha):
-                return self._objects[sha]
+                self._peeled = peeled
 
             def get_peeled(self, sha):
                 return self._peeled[sha]
 
 
             def get_peeled(self, sha):
                 return self._peeled[sha]
 
+            def __getitem__(self, sha):
+                return self._objects[sha]
+
             def get_refs(self):
                 return {
                     'HEAD': '000',
             def get_refs(self):
                 return {
                     'HEAD': '000',
@@ -135,11 +129,26 @@ class DumbHandlersTestCase(WebTestCase):
                     'refs/tags/blob-tag': blob3.sha(),
                     }
 
                     'refs/tags/blob-tag': blob3.sha(),
                     }
 
+        class TestBackend(object):
+            def __init__(self):
+                objects = [blob1, blob2, blob3, tag1]
+                self.repo = TestRepo(objects, {
+                    'HEAD': '000',
+                    'refs/heads/master': blob1.sha(),
+                    'refs/tags/tag-tag': blob2.sha(),
+                    'refs/tags/blob-tag': blob3.sha(),
+                    })
+
+            def open_repository(self, path):
+                assert path == '/'
+                return self.repo
+
+        mat = re.search('.*', '//info/refs')
         self.assertEquals(['111\trefs/heads/master\n',
                            '333\trefs/tags/blob-tag\n',
                            'aaa\trefs/tags/tag-tag\n',
                            '222\trefs/tags/tag-tag^{}\n'],
         self.assertEquals(['111\trefs/heads/master\n',
                            '333\trefs/tags/blob-tag\n',
                            'aaa\trefs/tags/tag-tag\n',
                            '222\trefs/tags/tag-tag^{}\n'],
-                          list(get_info_refs(self._req, TestBackend(), None)))
+                          list(get_info_refs(self._req, TestBackend(), mat)))
 
 
 class SmartHandlersTestCase(WebTestCase):
 
 
 class SmartHandlersTestCase(WebTestCase):
@@ -155,8 +164,9 @@ class SmartHandlersTestCase(WebTestCase):
                 self._handler.write('pkt-line: %s' % line)
 
     class _TestUploadPackHandler(object):
                 self._handler.write('pkt-line: %s' % line)
 
     class _TestUploadPackHandler(object):
-        def __init__(self, backend, read, write, stateless_rpc=False,
+        def __init__(self, backend, args, read, write, stateless_rpc=False,
                      advertise_refs=False):
                      advertise_refs=False):
+            self.args = args
             self.read = read
             self.write = write
             self.proto = SmartHandlersTestCase.TestProtocol(self)
             self.read = read
             self.write = write
             self.proto = SmartHandlersTestCase.TestProtocol(self)
@@ -209,7 +219,8 @@ class SmartHandlersTestCase(WebTestCase):
         self._environ['wsgi.input'] = StringIO('foo')
         self._environ['QUERY_STRING'] = 'service=git-upload-pack'
 
         self._environ['wsgi.input'] = StringIO('foo')
         self._environ['QUERY_STRING'] = 'service=git-upload-pack'
 
-        output = ''.join(get_info_refs(self._req, 'backend', None,
+        mat = re.search('.*', '/git-upload-pack')
+        output = ''.join(get_info_refs(self._req, 'backend', mat,
                                        services=self.services()))
         self.assertEquals(('pkt-line: # service=git-upload-pack\n'
                            'flush-pkt\n'
                                        services=self.services()))
         self.assertEquals(('pkt-line: # service=git-upload-pack\n'
                            'flush-pkt\n'