/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 tests/test_server.py

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 14:59:43 UTC
  • mto: (0.200.1913 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180402145943-s5jmpbvvf1x42pao
Just don't touch the URL if it's already a valid URL.

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 __future__ import absolute_import
 
20
 
 
21
from dulwich.client import TCPGitClient
 
22
from dulwich.repo import Repo
 
23
import threading
 
24
 
 
25
from ....transport import transport_server_registry
 
26
from ....tests import (
 
27
    TestCase,
 
28
    TestCaseWithTransport,
 
29
    )
 
30
 
 
31
from ..server import (
 
32
    BzrBackend,
 
33
    BzrTCPGitServer,
 
34
    )
 
35
 
 
36
class TestPresent(TestCase):
 
37
 
 
38
    def test_present(self):
 
39
        # Just test that the server is registered.
 
40
        transport_server_registry.get('git')
 
41
 
 
42
 
 
43
class GitServerTestCase(TestCaseWithTransport):
 
44
 
 
45
    def start_server(self, t):
 
46
        backend = BzrBackend(t)
 
47
        server = BzrTCPGitServer(backend, 'localhost', port=0)
 
48
        self.addCleanup(server.shutdown)
 
49
        thread = threading.Thread(target=server.serve).start()
 
50
        self._server = server
 
51
        _, port = self._server.socket.getsockname()
 
52
        return port
 
53
 
 
54
 
 
55
class TestPlainFetch(GitServerTestCase):
 
56
 
 
57
    def test_fetch_simple(self):
 
58
        wt = self.make_branch_and_tree('t')
 
59
        self.build_tree(['t/foo'])
 
60
        wt.add('foo')
 
61
        revid = wt.commit(message="some data")
 
62
        wt.branch.tags.set_tag("atag", revid)
 
63
        t = self.get_transport('t')
 
64
        port = self.start_server(t)
 
65
        c = TCPGitClient('localhost', port=port)
 
66
        gitrepo = Repo.init('gitrepo', mkdir=True)
 
67
        result = c.fetch('/', gitrepo)
 
68
        self.assertEquals(
 
69
            set(result.refs.keys()),
 
70
            set(["refs/tags/atag", "HEAD"]))
 
71
 
 
72
    def test_fetch_nothing(self):
 
73
        wt = self.make_branch_and_tree('t')
 
74
        self.build_tree(['t/foo'])
 
75
        wt.add('foo')
 
76
        revid = wt.commit(message="some data")
 
77
        wt.branch.tags.set_tag("atag", revid)
 
78
        t = self.get_transport('t')
 
79
        port = self.start_server(t)
 
80
        c = TCPGitClient('localhost', port=port)
 
81
        gitrepo = Repo.init('gitrepo', mkdir=True)
 
82
        result = c.fetch('/', gitrepo, determine_wants=lambda x: [])
 
83
        self.assertEquals(
 
84
            set(result.refs.keys()),
 
85
            set(["refs/tags/atag", "HEAD"]))