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