~bzr-pqm/bzr/bzr.dev

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
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
16
"""
17
Facilities to use ftp test servers.
18
"""
19
4063.3.2 by Vincent Ladeuil
Disable medusa under python2.6 until we find or replacement or it get fixed.
20
import sys
21
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
22
from bzrlib import tests
23
24
25
try:
26
    from bzrlib.tests.ftp_server import medusa_based
4063.3.2 by Vincent Ladeuil
Disable medusa under python2.6 until we find or replacement or it get fixed.
27
    # medusa is bogus under python2.6
3508.1.12 by Vincent Ladeuil
Don't require patched version for pyftpdlib.
28
    medusa_available = sys.version_info < (2, 6)
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
29
except ImportError:
30
    medusa_available = False
31
32
3508.1.10 by Vincent Ladeuil
Start supporting pyftpdlib as an ftp test server.
33
try:
34
    from bzrlib.tests.ftp_server import pyftpdlib_based
35
    pyftpdlib_available = True
36
except ImportError:
37
    pyftpdlib_available = False
38
39
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
40
class _FTPServerFeature(tests.Feature):
41
    """Some tests want an FTP Server, check if one is available.
42
3508.1.23 by Vincent Ladeuil
Fix as per Martin's review.
43
    Right now, the only way this is available is if one of the following is
44
    installed:
45
46
    - 'medusa': http://www.amk.ca/python/code/medusa.html
47
    - 'pyftpdlib': http://code.google.com/p/pyftpdlib/
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
48
    """
49
50
    def _probe(self):
3508.1.10 by Vincent Ladeuil
Start supporting pyftpdlib as an ftp test server.
51
        return medusa_available or pyftpdlib_available
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
52
53
    def feature_name(self):
54
        return 'FTPServer'
55
56
57
FTPServerFeature = _FTPServerFeature()
58
59
4167.1.2 by Vincent Ladeuil
Fix UnavailableFTPTestServer for sites without medusa and pyftpdlib.
60
class UnavailableFTPTestServer(object):
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
61
    """Dummy ftp test server.
62
63
    This allows the test suite report the number of tests needing that
64
    feature. We raise UnavailableFeature from methods before the test server is
65
    being used. Doing so in the setUp method has bad side-effects (tearDown is
66
    never called).
67
    """
68
4934.3.3 by Martin Pool
Rename Server.setUp to Server.start_server
69
    def start_server(self, vfs_server=None):
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
70
        pass
71
4934.3.1 by Martin Pool
Rename Server.tearDown to .stop_server
72
    def stop_server(self):
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
73
        pass
74
75
    def get_url(self):
76
        raise tests.UnavailableFeature(FTPServerFeature)
77
78
    def get_bogus_url(self):
79
        raise tests.UnavailableFeature(FTPServerFeature)
80
81
82
if medusa_available:
3508.1.23 by Vincent Ladeuil
Fix as per Martin's review.
83
    FTPTestServer = medusa_based.FTPTestServer
3508.1.10 by Vincent Ladeuil
Start supporting pyftpdlib as an ftp test server.
84
elif pyftpdlib_available:
3508.1.23 by Vincent Ladeuil
Fix as per Martin's review.
85
    FTPTestServer = pyftpdlib_based.FTPTestServer
3508.1.7 by Vincent Ladeuil
Prepare test framework for pyftpdlib injection.
86
else:
3508.1.23 by Vincent Ladeuil
Fix as per Martin's review.
87
    FTPTestServer = UnavailableFTPTestServer