/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2011-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.1430 by Jelmer Vernooij
Add basic tests for server.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.1430 by Jelmer Vernooij
Add basic tests for server.
16
17
"""Test for git server."""
18
0.358.3 by Jelmer Vernooij
Enable absolute import.
19
from __future__ import absolute_import
20
0.200.1431 by Jelmer Vernooij
add test for fetching from 'bzr serve --git' server.
21
from dulwich.client import TCPGitClient
22
from dulwich.repo import Repo
23
import threading
24
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from ....transport import transport_server_registry
26
from ....tests import (
0.200.1430 by Jelmer Vernooij
Add basic tests for server.
27
    TestCase,
28
    TestCaseWithTransport,
29
    )
30
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
31
from ..server import (
0.200.1431 by Jelmer Vernooij
add test for fetching from 'bzr serve --git' server.
32
    BzrBackend,
0.271.2 by Jelmer Vernooij
use BzrTCPGitServer in tests.
33
    BzrTCPGitServer,
0.200.1431 by Jelmer Vernooij
add test for fetching from 'bzr serve --git' server.
34
    )
35
0.200.1430 by Jelmer Vernooij
Add basic tests for server.
36
class TestPresent(TestCase):
37
38
    def test_present(self):
39
        # Just test that the server is registered.
40
        transport_server_registry.get('git')
0.200.1431 by Jelmer Vernooij
add test for fetching from 'bzr serve --git' server.
41
42
43
class GitServerTestCase(TestCaseWithTransport):
44
45
    def start_server(self, t):
46
        backend = BzrBackend(t)
0.271.2 by Jelmer Vernooij
use BzrTCPGitServer in tests.
47
        server = BzrTCPGitServer(backend, 'localhost', port=0)
0.200.1431 by Jelmer Vernooij
add test for fetching from 'bzr serve --git' server.
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')
0.271.1 by Jelmer Vernooij
test tags
61
        revid = wt.commit(message="some data")
62
        wt.branch.tags.set_tag("atag", revid)
0.200.1431 by Jelmer Vernooij
add test for fetching from 'bzr serve --git' server.
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)
0.200.1666 by Jelmer Vernooij
Fix some tests.
67
        result = c.fetch('/', gitrepo)
0.271.1 by Jelmer Vernooij
test tags
68
        self.assertEquals(
0.200.1666 by Jelmer Vernooij
Fix some tests.
69
            set(result.refs.keys()),
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
70
            set(["refs/tags/atag", "HEAD"]))
0.271.3 by Jelmer Vernooij
test fetching nothing.
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)
0.200.1666 by Jelmer Vernooij
Fix some tests.
82
        result = c.fetch('/', gitrepo, determine_wants=lambda x: [])
0.271.3 by Jelmer Vernooij
test fetching nothing.
83
        self.assertEquals(
0.200.1666 by Jelmer Vernooij
Fix some tests.
84
            set(result.refs.keys()),
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
85
            set(["refs/tags/atag", "HEAD"]))