/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_server.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011-2018 Jelmer Vernooij <jelmer@jelmer.uk>
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Test for git server."""
18
 
 
19
 
from dulwich.client import TCPGitClient
20
 
from dulwich.repo import Repo
21
 
import threading
22
 
 
23
 
from ...transport import transport_server_registry
24
 
from ...tests import (
25
 
    TestCase,
26
 
    TestCaseWithTransport,
27
 
    )
28
 
 
29
 
from ..server import (
30
 
    BzrBackend,
31
 
    BzrTCPGitServer,
32
 
    )
33
 
 
34
 
 
35
 
class TestPresent(TestCase):
36
 
 
37
 
    def test_present(self):
38
 
        # Just test that the server is registered.
39
 
        transport_server_registry.get('git')
40
 
 
41
 
 
42
 
class GitServerTestCase(TestCaseWithTransport):
43
 
 
44
 
    def start_server(self, t):
45
 
        backend = BzrBackend(t)
46
 
        server = BzrTCPGitServer(backend, 'localhost', port=0)
47
 
        self.addCleanup(server.shutdown)
48
 
        thread = threading.Thread(target=server.serve).start()
49
 
        self._server = server
50
 
        _, port = self._server.socket.getsockname()
51
 
        return port
52
 
 
53
 
 
54
 
class TestPlainFetch(GitServerTestCase):
55
 
 
56
 
    def test_fetch_from_native_git(self):
57
 
        wt = self.make_branch_and_tree('t', format='git')
58
 
        self.build_tree(['t/foo'])
59
 
        wt.add('foo')
60
 
        revid = wt.commit(message="some data")
61
 
        wt.branch.tags.set_tag("atag", revid)
62
 
        t = self.get_transport('t')
63
 
        port = self.start_server(t)
64
 
        c = TCPGitClient('localhost', port=port)
65
 
        gitrepo = Repo.init('gitrepo', mkdir=True)
66
 
        result = c.fetch('/', gitrepo)
67
 
        self.assertEqual(
68
 
            set(result.refs.keys()),
69
 
            set([b"refs/tags/atag", b'refs/heads/master', b"HEAD"]))
70
 
 
71
 
    def test_fetch_nothing(self):
72
 
        wt = self.make_branch_and_tree('t')
73
 
        self.build_tree(['t/foo'])
74
 
        wt.add('foo')
75
 
        revid = wt.commit(message="some data")
76
 
        wt.branch.tags.set_tag("atag", revid)
77
 
        t = self.get_transport('t')
78
 
        port = self.start_server(t)
79
 
        c = TCPGitClient('localhost', port=port)
80
 
        gitrepo = Repo.init('gitrepo', mkdir=True)
81
 
        result = c.fetch('/', gitrepo, determine_wants=lambda x: [])
82
 
        self.assertEqual(
83
 
            set(result.refs.keys()),
84
 
            set([b"refs/tags/atag", b"HEAD"]))
85
 
 
86
 
    def test_fetch_from_non_git(self):
87
 
        wt = self.make_branch_and_tree('t', format='bzr')
88
 
        self.build_tree(['t/foo'])
89
 
        wt.add('foo')
90
 
        revid = wt.commit(message="some data")
91
 
        wt.branch.tags.set_tag("atag", revid)
92
 
        t = self.get_transport('t')
93
 
        port = self.start_server(t)
94
 
        c = TCPGitClient('localhost', port=port)
95
 
        gitrepo = Repo.init('gitrepo', mkdir=True)
96
 
        result = c.fetch('/', gitrepo)
97
 
        self.assertEqual(
98
 
            set(result.refs.keys()),
99
 
            set([b"refs/tags/atag", b"HEAD"]))