~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ftp_transport.py

Merge Robert and indirectly trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib import tests
18
 
import bzrlib.transport
 
17
import sys
 
18
 
 
19
from bzrlib import (
 
20
    tests,
 
21
    transport,
 
22
    ui,
 
23
    )
19
24
 
20
25
 
21
26
class _MedusaFeature(tests.Feature):
54
59
    """Test aftp transport."""
55
60
 
56
61
    def test_aftp_degrade(self):
57
 
        t = bzrlib.transport.get_transport('aftp://host/path')
 
62
        t = transport.get_transport('aftp://host/path')
58
63
        self.failUnless(t.is_active)
59
64
        parent = t.clone('..')
60
65
        self.failUnless(parent.is_active)
71
76
        t = self.get_transport()
72
77
        t.put_bytes('foo', 'test bytes\n')
73
78
        self.assertEqual('test bytes\n', t.get_bytes('foo'))
 
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
 
91
        sys.stdout = tests.StringIOWrapper()
 
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
 
106
        ui.ui_factory = tests.TestUIFactory(stdin=password+'\n')
 
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())