bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5060.3.1
by Martin Pool
Handle "Directory not empty" from ftp as DirectoryNotEmpty. |
1 |
# Copyright (C) 2006, 2010 Canonical Ltd
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
2 |
#
|
1952.1.1
by John Arbash Meinel
Ghozzy: Fix Bzr's support of Active FTP (aftp://) |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1952.1.1
by John Arbash Meinel
Ghozzy: Fix Bzr's support of Active FTP (aftp://) |
16 |
|
2900.2.5
by Vincent Ladeuil
ake ftp aware of authentication config. |
17 |
from cStringIO import StringIO |
5060.3.1
by Martin Pool
Handle "Directory not empty" from ftp as DirectoryNotEmpty. |
18 |
import ftplib |
4222.3.14
by Jelmer Vernooij
Fix missing import. |
19 |
import getpass |
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
20 |
import sys |
21 |
||
2790.1.2
by Vincent Ladeuil
Review feedback. |
22 |
from bzrlib import ( |
2900.2.5
by Vincent Ladeuil
ake ftp aware of authentication config. |
23 |
config, |
5060.3.1
by Martin Pool
Handle "Directory not empty" from ftp as DirectoryNotEmpty. |
24 |
errors, |
2790.1.2
by Vincent Ladeuil
Review feedback. |
25 |
tests, |
26 |
transport, |
|
27 |
ui, |
|
28 |
)
|
|
29 |
||
5060.3.1
by Martin Pool
Handle "Directory not empty" from ftp as DirectoryNotEmpty. |
30 |
from bzrlib.transport import ftp |
31 |
||
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
32 |
from bzrlib.tests import ftp_server |
33 |
||
2790.1.2
by Vincent Ladeuil
Review feedback. |
34 |
|
35 |
class TestCaseWithFTPServer(tests.TestCaseWithTransport): |
|
2413.1.1
by John Arbash Meinel
Implement TestCaseWithFTPServer using the new shiny Feature mechanism. |
36 |
|
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
37 |
_test_needs_features = [ftp_server.FTPServerFeature] |
2413.1.1
by John Arbash Meinel
Implement TestCaseWithFTPServer using the new shiny Feature mechanism. |
38 |
|
39 |
def setUp(self): |
|
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
40 |
self.transport_server = ftp_server.FTPTestServer |
2413.1.1
by John Arbash Meinel
Implement TestCaseWithFTPServer using the new shiny Feature mechanism. |
41 |
super(TestCaseWithFTPServer, self).setUp() |
42 |
||
43 |
||
2790.1.2
by Vincent Ladeuil
Review feedback. |
44 |
class TestCaseAFTP(tests.TestCaseWithTransport): |
2413.1.2
by John Arbash Meinel
Clean up test ordering |
45 |
"""Test aftp transport.""" |
46 |
||
47 |
def test_aftp_degrade(self): |
|
2790.1.2
by Vincent Ladeuil
Review feedback. |
48 |
t = transport.get_transport('aftp://host/path') |
2413.1.2
by John Arbash Meinel
Clean up test ordering |
49 |
self.failUnless(t.is_active) |
50 |
parent = t.clone('..') |
|
51 |
self.failUnless(parent.is_active) |
|
52 |
||
53 |
self.assertEqual('aftp://host/path', t.abspath('')) |
|
54 |
||
55 |
||
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
56 |
class TestFTPTestServer(TestCaseWithFTPServer): |
2413.1.1
by John Arbash Meinel
Implement TestCaseWithFTPServer using the new shiny Feature mechanism. |
57 |
|
58 |
def test_basic_exists(self): |
|
59 |
url = self.get_url() |
|
60 |
self.assertStartsWith(url, 'ftp://') |
|
61 |
||
62 |
t = self.get_transport() |
|
63 |
t.put_bytes('foo', 'test bytes\n') |
|
64 |
self.assertEqual('test bytes\n', t.get_bytes('foo')) |
|
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
65 |
|
2917.1.1
by Vincent Ladeuil
Reproduce the bug. |
66 |
def test__reconnect(self): |
67 |
t = self.get_transport() |
|
68 |
t.put_bytes('foo', 'test bytes\n') |
|
69 |
self.assertEqual('test bytes\n', t.get_bytes('foo')) |
|
70 |
t._reconnect() |
|
2917.1.3
by Vincent Ladeuil
Review feedback. |
71 |
t.put_bytes('foo', 'test more bytes\n') |
72 |
self.assertEqual('test more bytes\n', t.get_bytes('foo')) |
|
2917.1.1
by Vincent Ladeuil
Reproduce the bug. |
73 |
|
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
74 |
|
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
75 |
class TestFTPTestServerUI(TestCaseWithFTPServer): |
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
76 |
|
3508.1.13
by Vincent Ladeuil
Fix last failing tests under python2.6. |
77 |
def setUp(self): |
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
78 |
super(TestFTPTestServerUI, self).setUp() |
3508.1.13
by Vincent Ladeuil
Fix last failing tests under python2.6. |
79 |
self.user = 'joe' |
80 |
self.password = 'secret' |
|
81 |
self.get_server().add_user(self.user, self.password) |
|
82 |
||
83 |
def get_url(self, relpath=None): |
|
84 |
"""Overrides get_url to inject our user.""" |
|
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
85 |
base = super(TestFTPTestServerUI, self).get_url(relpath) |
3508.1.13
by Vincent Ladeuil
Fix last failing tests under python2.6. |
86 |
(scheme, user, password, |
87 |
host, port, path) = transport.ConnectedTransport._split_url(base) |
|
88 |
url = transport.ConnectedTransport._unsplit_url( |
|
89 |
scheme, self.user, self.password, host, port, path) |
|
90 |
return url |
|
2900.2.15
by Vincent Ladeuil
AuthenticationConfig can be queried for logins too (first step). |
91 |
|
4222.3.13
by Jelmer Vernooij
Add tests to ensure sftp and ftp don't prompt for usernames. |
92 |
def test_no_prompt_for_username(self): |
93 |
"""ensure getpass.getuser() is used if there's no username in the |
|
94 |
configuration.""", |
|
95 |
self.get_server().add_user(getpass.getuser(), self.password) |
|
96 |
t = self.get_transport() |
|
4449.3.46
by Martin Pool
Update ftp tests to use CannedInputUIFactory |
97 |
ui.ui_factory = ui.CannedInputUIFactory([self.password]) |
4222.3.13
by Jelmer Vernooij
Add tests to ensure sftp and ftp don't prompt for usernames. |
98 |
# Issue a request to the server to connect
|
99 |
t.put_bytes('foo', 'test bytes\n') |
|
100 |
self.assertEqual('test bytes\n', t.get_bytes('foo')) |
|
101 |
# Only the password should've been read
|
|
4449.3.46
by Martin Pool
Update ftp tests to use CannedInputUIFactory |
102 |
ui.ui_factory.assert_all_input_consumed() |
4222.3.13
by Jelmer Vernooij
Add tests to ensure sftp and ftp don't prompt for usernames. |
103 |
|
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
104 |
def test_prompt_for_password(self): |
105 |
t = self.get_transport() |
|
4449.3.46
by Martin Pool
Update ftp tests to use CannedInputUIFactory |
106 |
ui.ui_factory = ui.CannedInputUIFactory([self.password]) |
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
107 |
# Issue a request to the server to connect
|
108 |
t.has('whatever/not/existing') |
|
109 |
# stdin should be empty (the provided password have been consumed)
|
|
4449.3.46
by Martin Pool
Update ftp tests to use CannedInputUIFactory |
110 |
ui.ui_factory.assert_all_input_consumed() |
2900.2.5
by Vincent Ladeuil
ake ftp aware of authentication config. |
111 |
|
112 |
def test_no_prompt_for_password_when_using_auth_config(self): |
|
113 |
t = self.get_transport() |
|
4449.3.46
by Martin Pool
Update ftp tests to use CannedInputUIFactory |
114 |
ui.ui_factory = ui.CannedInputUIFactory([]) |
2900.2.5
by Vincent Ladeuil
ake ftp aware of authentication config. |
115 |
# Create a config file with the right password
|
116 |
conf = config.AuthenticationConfig() |
|
2900.2.14
by Vincent Ladeuil
More tests. |
117 |
conf._get_config().update({'ftptest': {'scheme': 'ftp', |
3508.1.13
by Vincent Ladeuil
Fix last failing tests under python2.6. |
118 |
'user': self.user, |
119 |
'password': self.password}}) |
|
2900.2.5
by Vincent Ladeuil
ake ftp aware of authentication config. |
120 |
conf._save() |
121 |
# Issue a request to the server to connect
|
|
122 |
t.put_bytes('foo', 'test bytes\n') |
|
123 |
self.assertEqual('test bytes\n', t.get_bytes('foo')) |
|
3508.1.17
by Vincent Ladeuil
Allows empty passwords with pyftpdlib ftp test server. |
124 |
|
125 |
def test_empty_password(self): |
|
126 |
# Override the default user/password from setUp
|
|
127 |
self.user = 'jim' |
|
128 |
self.password = '' |
|
129 |
self.get_server().add_user(self.user, self.password) |
|
130 |
t = self.get_transport() |
|
4449.3.47
by Martin Pool
Typo correction |
131 |
ui.ui_factory = ui.CannedInputUIFactory([self.password]) |
3508.1.17
by Vincent Ladeuil
Allows empty passwords with pyftpdlib ftp test server. |
132 |
# Issue a request to the server to connect
|
133 |
t.has('whatever/not/existing') |
|
134 |
# stdin should be empty (the provided password have been consumed),
|
|
135 |
# even if the password is empty, it's followed by a newline.
|
|
4449.3.46
by Martin Pool
Update ftp tests to use CannedInputUIFactory |
136 |
ui.ui_factory.assert_all_input_consumed() |
5060.3.1
by Martin Pool
Handle "Directory not empty" from ftp as DirectoryNotEmpty. |
137 |
|
138 |
||
139 |
class TestFTPErrorTranslation(tests.TestCase): |
|
140 |
||
141 |
def test_translate_directory_not_empty(self): |
|
142 |
# https://bugs.launchpad.net/bugs/528722
|
|
143 |
||
144 |
t = ftp.FtpTransport("ftp://none/") |
|
145 |
||
146 |
try: |
|
147 |
raise ftplib.error_temp("Rename/move failure: Directory not empty") |
|
148 |
except Exception, e: |
|
149 |
e = self.assertRaises(errors.DirectoryNotEmpty, |
|
150 |
t._translate_ftp_error, e, "/path") |