4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2009, 2010 Canonical Ltd
|
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
16 |
|
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
17 |
"""
|
18 |
Facilities to use ftp test servers.
|
|
19 |
"""
|
|
20 |
||
5947.1.1
by Vincent Ladeuil
Support pyftplib-0.6.0 as an ftp test server |
21 |
import sys |
22 |
||
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
23 |
from bzrlib import tests |
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
24 |
from bzrlib.tests import ( |
25 |
features, |
|
26 |
)
|
|
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
27 |
|
28 |
||
29 |
try: |
|
5947.1.1
by Vincent Ladeuil
Support pyftplib-0.6.0 as an ftp test server |
30 |
from bzrlib.tests.ftp_server import medusa_based |
5947.1.2
by Vincent Ladeuil
Clarify policy about medusa. |
31 |
# medusa is bogus starting with python2.6, since we don't support earlier
|
32 |
# pythons anymore, it's currently useless. There is hope though that the
|
|
33 |
# unicode bugs get fixed in the future so we leave it disabled until
|
|
34 |
# then. Keeping the framework in place means that only the following line
|
|
35 |
# will need to be changed. The last tests were conducted with medusa-2.0
|
|
36 |
# -- vila 20110607
|
|
37 |
medusa_available = False |
|
5947.1.1
by Vincent Ladeuil
Support pyftplib-0.6.0 as an ftp test server |
38 |
except ImportError: |
39 |
medusa_available = False |
|
40 |
||
41 |
||
42 |
try: |
|
3508.1.10
by Vincent Ladeuil
Start supporting pyftpdlib as an ftp test server. |
43 |
from bzrlib.tests.ftp_server import pyftpdlib_based |
44 |
pyftpdlib_available = True |
|
45 |
except ImportError: |
|
46 |
pyftpdlib_available = False |
|
47 |
||
48 |
||
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
49 |
class _FTPServerFeature(features.Feature): |
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
50 |
"""Some tests want an FTP Server, check if one is available.
|
51 |
||
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
52 |
Right now, the only way this is available is if one of the following is
|
53 |
installed:
|
|
54 |
||
55 |
- 'medusa': http://www.amk.ca/python/code/medusa.html
|
|
56 |
- 'pyftpdlib': http://code.google.com/p/pyftpdlib/
|
|
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
57 |
"""
|
58 |
||
59 |
def _probe(self): |
|
5947.1.1
by Vincent Ladeuil
Support pyftplib-0.6.0 as an ftp test server |
60 |
return medusa_available or pyftpdlib_available |
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
61 |
|
62 |
def feature_name(self): |
|
63 |
return 'FTPServer' |
|
64 |
||
65 |
||
66 |
FTPServerFeature = _FTPServerFeature() |
|
67 |
||
68 |
||
4167.1.2
by Vincent Ladeuil
Fix UnavailableFTPTestServer for sites without medusa and pyftpdlib. |
69 |
class UnavailableFTPTestServer(object): |
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
70 |
"""Dummy ftp test server.
|
71 |
||
72 |
This allows the test suite report the number of tests needing that
|
|
73 |
feature. We raise UnavailableFeature from methods before the test server is
|
|
74 |
being used. Doing so in the setUp method has bad side-effects (tearDown is
|
|
75 |
never called).
|
|
76 |
"""
|
|
77 |
||
4934.3.3
by Martin Pool
Rename Server.setUp to Server.start_server |
78 |
def start_server(self, vfs_server=None): |
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
79 |
pass
|
80 |
||
4934.3.1
by Martin Pool
Rename Server.tearDown to .stop_server |
81 |
def stop_server(self): |
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
82 |
pass
|
83 |
||
84 |
def get_url(self): |
|
85 |
raise tests.UnavailableFeature(FTPServerFeature) |
|
86 |
||
87 |
def get_bogus_url(self): |
|
88 |
raise tests.UnavailableFeature(FTPServerFeature) |
|
89 |
||
90 |
||
5947.1.1
by Vincent Ladeuil
Support pyftplib-0.6.0 as an ftp test server |
91 |
if medusa_available: |
92 |
FTPTestServer = medusa_based.FTPTestServer |
|
93 |
elif pyftpdlib_available: |
|
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
94 |
FTPTestServer = pyftpdlib_based.FTPTestServer |
3508.1.7
by Vincent Ladeuil
Prepare test framework for pyftpdlib injection. |
95 |
else: |
3508.1.23
by Vincent Ladeuil
Fix as per Martin's review. |
96 |
FTPTestServer = UnavailableFTPTestServer |