/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
1
# Copyright (C) 2008 Canonical Ltd
0.152.1 by Vincent Ladeuil
Empty shell
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
17
import os
18
19
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
20
from bzrlib import (
0.152.8 by Vincent Ladeuil
Handle uploading directories.
21
    bzrdir,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
22
    errors,
23
    revisionspec,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
24
    tests,
0.152.8 by Vincent Ladeuil
Handle uploading directories.
25
    transport,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
26
    )
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
27
from bzrlib.tests import test_transport_implementations
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
28
29
from bzrlib.plugins.upload import cmd_upload
0.152.1 by Vincent Ladeuil
Empty shell
30
31
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
32
class TransportAdapter(
33
    test_transport_implementations.TransportTestProviderAdapter):
34
    """A tool to generate a suite testing all transports for a single test.
35
36
    We restrict the transports to the ones we want to support.
37
    """
38
39
    def _test_permutations(self):
40
        """Return a list of the klass, server_factory pairs to test."""
41
        result = []
42
        transport_modules =['bzrlib.transport.ftp',
43
                            'bzrlib.transport.sftp']
44
        for module in transport_modules:
45
            try:
46
                permutations = self.get_transport_test_permutations(
47
                    reduce(getattr, (module).split('.')[1:],
48
                           __import__(module)))
49
                for (klass, server_factory) in permutations:
50
                    scenario = (server_factory.__name__,
51
                        {"transport_class":klass,
52
                         "transport_server":server_factory})
53
                    result.append(scenario)
54
            except errors.DependencyNotPresent, e:
55
                # Continue even if a dependency prevents us 
56
                # from adding this test
57
                pass
58
        return result
59
60
61
def load_tests(standard_tests, module, loader):
62
    """Multiply tests for tranport implementations."""
63
    result = loader.suiteClass()
64
    adapter = TransportAdapter()
65
    for test in tests.iter_suite_tests(standard_tests):
66
        result.addTests(adapter.adapt(test))
67
    return result
68
69
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
70
class TestUpload(tests.TestCaseWithTransport):
71
72
    def _create_branch(self):
0.152.8 by Vincent Ladeuil
Handle uploading directories.
73
        # We need a local branch not a remote one
74
        t = transport.get_transport('branch')
75
        t.ensure_base()
76
        branch = bzrdir.BzrDir.create_branch_convenience(
77
            t.base,
78
            format=bzrdir.format_registry.make_bzrdir('default'),
79
            force_new_tree=False)
80
        tree = branch.bzrdir.create_workingtree()
81
        return tree
82
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
83
    def build_branch_contents(self, reltree, relpath='branch/'):
84
        """Build the tree content at relpath."""
85
        abstree = []
86
        for relitem in reltree:
87
            abstree.append((relpath + relitem[0],) + relitem[1:])
88
        self.build_tree_contents(abstree)
89
90
    def assertUpFileEqual(self, content, path, relpath='upload/'):
91
        self.assertFileEqual(content, relpath + path)
92
93
    def failIfUpFileExists(self, path, relpath='upload/'):
94
        self.failIfExists(relpath + path)
95
96
    def full_upload(self, *args, **kwargs):
97
        upload = cmd_upload()
98
        up_url = self.get_transport('upload').external_url()
99
        if kwargs.get('working_dir', None) is None:
100
            kwargs['working_dir'] = 'branch'
101
        kwargs['full'] = True
102
        upload.run(up_url, *args, **kwargs)
103
104
    def incremental_upload(self, *args, **kwargs):
105
        upload = cmd_upload()
106
        up_url = self.get_transport('upload').external_url()
107
        if kwargs.get('working_dir', None) is None:
108
            kwargs['working_dir'] = 'branch'
109
        upload.run(up_url, *args, **kwargs)
110
0.152.8 by Vincent Ladeuil
Handle uploading directories.
111
    def _add_hello(self, tree):
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
112
        self.build_branch_contents([('hello', 'foo')])
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
113
        tree.add('hello')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
114
        tree.commit('add hello')
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
115
0.152.8 by Vincent Ladeuil
Handle uploading directories.
116
    def _modify_hello_add_goodbye(self, tree):
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
117
        self.build_branch_contents([('hello', 'bar'),
118
                                  ('dir/',),
119
                                  ('dir/goodbye', 'baz')])
0.152.8 by Vincent Ladeuil
Handle uploading directories.
120
        tree.add('dir')
121
        tree.add('dir/goodbye')
122
        tree.commit('modify hello, add goodbye')
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
123
124
    def test_full_upload(self):
0.152.8 by Vincent Ladeuil
Handle uploading directories.
125
        tree = self._create_branch()
126
        self._add_hello(tree)
127
        self._modify_hello_add_goodbye(tree)
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
128
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
129
        self.full_upload()
130
131
        self.assertUpFileEqual('bar', 'hello')
132
        self.assertUpFileEqual('baz', 'dir/goodbye')
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
133
134
    def test_incremental_upload(self):
0.152.8 by Vincent Ladeuil
Handle uploading directories.
135
        tree = self._create_branch()
136
        self._add_hello(tree)
137
        self._modify_hello_add_goodbye(tree)
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
138
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
139
        # Upload revision 1 only
140
        revspec = revisionspec.RevisionSpec.from_string('1')
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
141
        self.full_upload(revision=[revspec])
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
142
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
143
        self.assertUpFileEqual('foo', 'hello')
144
        self.failIfUpFileExists('upload/dir/goodbye')
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
145
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
146
        # Upload current revision
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
147
        self.incremental_upload()
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
148
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
149
        self.assertUpFileEqual('bar', 'hello')
150
        self.assertUpFileEqual('baz', 'dir/goodbye')
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
151
152
    def test_invalid_revspec(self):
0.152.8 by Vincent Ladeuil
Handle uploading directories.
153
        tree = self._create_branch()
154
        self._add_hello(tree)
155
        self._modify_hello_add_goodbye(tree)
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
156
        rev1 = revisionspec.RevisionSpec.from_string('1')
157
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
158
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
159
        self.incremental_upload()
0.152.8 by Vincent Ladeuil
Handle uploading directories.
160
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
161
        self.assertRaises(errors.BzrCommandError,
162
                          self.incremental_upload, revision=[rev1, rev2])
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
163