bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
1 |
# Copyright (C) 2006 Canonical Ltd
|
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
17 |
import sys |
18 |
||
|
2790.1.2
by Vincent Ladeuil
Review feedback. |
19 |
from bzrlib import ( |
20 |
tests, |
|
21 |
transport, |
|
22 |
ui, |
|
23 |
)
|
|
24 |
||
25 |
||
26 |
class _MedusaFeature(tests.Feature): |
|
|
2413.1.1
by John Arbash Meinel
Implement TestCaseWithFTPServer using the new shiny Feature mechanism. |
27 |
"""Some tests want an FTP Server, check if one is available. |
28 |
||
29 |
Right now, the only way this is available is if 'medusa' is installed.
|
|
30 |
"""
|
|
31 |
||
32 |
def _probe(self): |
|
33 |
try: |
|
34 |
import medusa |
|
35 |
import medusa.filesys |
|
36 |
import medusa.ftp_server |
|
37 |
return True |
|
38 |
except ImportError: |
|
39 |
return False |
|
40 |
||
41 |
def feature_name(self): |
|
42 |
return 'medusa' |
|
43 |
||
44 |
MedusaFeature = _MedusaFeature() |
|
45 |
||
46 |
||
|
2790.1.2
by Vincent Ladeuil
Review feedback. |
47 |
class TestCaseWithFTPServer(tests.TestCaseWithTransport): |
|
2413.1.1
by John Arbash Meinel
Implement TestCaseWithFTPServer using the new shiny Feature mechanism. |
48 |
|
49 |
_test_needs_features = [MedusaFeature] |
|
50 |
||
51 |
def setUp(self): |
|
52 |
from bzrlib.transport.ftp import FtpServer |
|
53 |
self.transport_server = FtpServer |
|
54 |
super(TestCaseWithFTPServer, self).setUp() |
|
55 |
||
56 |
||
57 |
||
|
2790.1.2
by Vincent Ladeuil
Review feedback. |
58 |
class TestCaseAFTP(tests.TestCaseWithTransport): |
|
2413.1.2
by John Arbash Meinel
Clean up test ordering |
59 |
"""Test aftp transport.""" |
60 |
||
61 |
def test_aftp_degrade(self): |
|
|
2790.1.2
by Vincent Ladeuil
Review feedback. |
62 |
t = transport.get_transport('aftp://host/path') |
|
2413.1.2
by John Arbash Meinel
Clean up test ordering |
63 |
self.failUnless(t.is_active) |
64 |
parent = t.clone('..') |
|
65 |
self.failUnless(parent.is_active) |
|
66 |
||
67 |
self.assertEqual('aftp://host/path', t.abspath('')) |
|
68 |
||
69 |
||
|
2413.1.1
by John Arbash Meinel
Implement TestCaseWithFTPServer using the new shiny Feature mechanism. |
70 |
class TestFTPServer(TestCaseWithFTPServer): |
71 |
||
72 |
def test_basic_exists(self): |
|
73 |
url = self.get_url() |
|
74 |
self.assertStartsWith(url, 'ftp://') |
|
75 |
||
76 |
t = self.get_transport() |
|
77 |
t.put_bytes('foo', 'test bytes\n') |
|
78 |
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. |
79 |
|
80 |
||
81 |
class TestFTPServerUI(TestCaseWithFTPServer): |
|
82 |
||
83 |
def setUp(self): |
|
84 |
super(TestFTPServerUI, self).setUp() |
|
85 |
self.old_factory = ui.ui_factory |
|
86 |
# The following has the unfortunate side-effect of hiding any ouput
|
|
87 |
# during the tests (including pdb prompts). Feel free to comment them
|
|
88 |
# for debugging purposes but leave them in place, there are needed to
|
|
89 |
# run the tests without any console
|
|
90 |
self.old_stdout = sys.stdout |
|
|
2790.1.2
by Vincent Ladeuil
Review feedback. |
91 |
sys.stdout = tests.StringIOWrapper() |
|
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
92 |
self.addCleanup(self.restoreUIFactory) |
93 |
||
94 |
def restoreUIFactory(self): |
|
95 |
ui.ui_factory = self.old_factory |
|
96 |
sys.stdout = self.old_stdout |
|
97 |
||
98 |
def test_prompt_for_password(self): |
|
99 |
t = self.get_transport() |
|
100 |
# Ensure that the test framework set the password
|
|
101 |
self.assertIsNot(t._password, None) |
|
102 |
# Reset the password (get_url set the password to 'bar' so we
|
|
103 |
# reset it to None in the transport before the connection).
|
|
104 |
password = t._password |
|
105 |
t._password = None |
|
|
2790.1.2
by Vincent Ladeuil
Review feedback. |
106 |
ui.ui_factory = tests.TestUIFactory(stdin=password+'\n') |
|
2790.1.1
by Vincent Ladeuil
Fix #137044 by prompting for a password if *none* is provided for ftp. |
107 |
# Ask the server to check the password
|
108 |
server = self.get_server() |
|
109 |
# FIXME: There should be a better way to declare authorized users and
|
|
110 |
# passwords to the server
|
|
111 |
authorizer = server._ftp_server.authorizer |
|
112 |
authorizer.secured_user = t._user |
|
113 |
authorizer.secured_password = password |
|
114 |
# Issue a request to the server to connect
|
|
115 |
t.has('whatever/not/existing') |
|
116 |
# stdin should be empty (the provided password have been consumed)
|
|
117 |
self.assertEqual('', ui.ui_factory.stdin.readline()) |