Rev 2373: Complete tests. in file:///v/home/vila/src/bugs/72792/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Apr 13 17:16:56 BST 2007
At file:///v/home/vila/src/bugs/72792/
------------------------------------------------------------
revno: 2373
revision-id: v.ladeuil+lp at free.fr-20070413161654-kp4kajrrr23jge2f
parent: v.ladeuil+lp at free.fr-20070413121740-mnwzf1656e31aenj
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 72792
timestamp: Fri 2007-04-13 18:16:54 +0200
message:
Complete tests.
* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.__init__): Be more strict on valid users.
(HttpTransport_urllib._ask_password): Delete John's TODO. See ? I
didn't forget ! :-)
* bzrlib/tests/test_ui.py:
Fix some inconsistencies.
* bzrlib/tests/test_http.py:
Add more tests.
(TestHTTPBasicAuth.setUp): Setup a private ui_factory.
modified:
BRANCH.TODO BRANCH.TODO-20060103052123-79ac4969351c03a9
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/tests/test_ui.py test_ui.py-20051130162854-458e667a7414af09
bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
-------------- next part --------------
=== modified file 'BRANCH.TODO'
--- a/BRANCH.TODO 2007-04-12 13:09:53 +0000
+++ b/BRANCH.TODO 2007-04-13 16:16:54 +0000
@@ -3,6 +3,3 @@
#
#
-* in test_http.py, add tests for :
-- wrong password supplied
-- no double prompting
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2007-04-13 08:11:01 +0000
+++ b/bzrlib/tests/test_http.py 2007-04-13 16:16:54 +0000
@@ -24,6 +24,7 @@
import select
import socket
import threading
+from cStringIO import StringIO
import bzrlib
from bzrlib import (
@@ -33,7 +34,9 @@
)
from bzrlib.tests import (
TestCase,
+ TestUIFactory,
TestSkipped,
+ StringIOWrapper,
)
from bzrlib.tests.HttpServer import (
HttpServer,
@@ -68,6 +71,7 @@
)
from bzrlib.transport.http._urllib import HttpTransport_urllib
+import bzrlib.ui
class FakeManager(object):
@@ -1161,13 +1165,14 @@
('b', 'contents of b\n'),])
self.server = self.get_readonly_server()
- def get_user_url(self, user, password=None):
+ self.old_factory = bzrlib.ui.ui_factory
+ self.addCleanup(self.restoreUIFactory)
+
+ def restoreUIFactory(self):
+ bzrlib.ui.ui_factory = self.old_factory
+
+ def get_user_url(self, user=None, password=None):
"""Build an url embedding user and password"""
- user_pass = None
- if user is not None:
- userpass = user
- if password is not None:
- userpass += ':' + password
url = '%s://' % self.server._url_protocol
if user is not None:
url += user
@@ -1180,10 +1185,26 @@
def test_empty_pass(self):
self.server.add_user('joe', '')
t = self._transport(self.get_user_url('joe', ''))
- self.assertEqual(t.get('a').read(), 'contents of a\n')
+ self.assertEqual('contents of a\n', t.get('a').read())
def test_user_pass(self):
self.server.add_user('joe', 'foo')
t = self._transport(self.get_user_url('joe', 'foo'))
- self.assertEqual(t.get('a').read(), 'contents of a\n')
-
+ self.assertEqual('contents of a\n', t.get('a').read())
+
+ def test_wrong_pass(self):
+ self.server.add_user('joe', 'foo')
+ t = self._transport(self.get_user_url('joe', 'bar'))
+ self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
+
+ def test_prompt_for_password(self):
+ self.server.add_user('joe', 'foo')
+ t = self._transport(self.get_user_url('joe'))
+ bzrlib.ui.ui_factory = TestUIFactory(stdin='foo\n',
+ stdout=StringIOWrapper())
+ self.assertEqual('contents of a\n',t.get('a').read())
+ # stdin should be empty
+ self.assertEqual('', bzrlib.ui.ui_factory.stdin.readline())
+ # And we shouldn't prompt again for a different request
+ # against the same transport.
+ self.assertEqual('contents of b\n',t.get('b').read())
=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py 2007-04-12 14:28:00 +0000
+++ b/bzrlib/tests/test_ui.py 2007-04-13 16:16:54 +0000
@@ -24,14 +24,21 @@
import bzrlib
import bzrlib.errors as errors
-from bzrlib.progress import DotsProgressBar, TTYProgressBar, ProgressBarStack
+from bzrlib.progress import (
+ DotsProgressBar,
+ ProgressBarStack,
+ TTYProgressBar,
+ )
from bzrlib.tests import (
+ TestCase,
TestUIFactory,
StringIOWrapper,
- TestCase,
)
from bzrlib.tests.test_progress import _TTYStringIO
-from bzrlib.ui import SilentUIFactory
+from bzrlib.ui import (
+ CLIUIFactory,
+ SilentUIFactory,
+ )
from bzrlib.ui.text import TextUIFactory
@@ -166,13 +173,13 @@
def test_text_factory_setting_progress_bar(self):
# we should be able to choose the progress bar type used.
- factory = bzrlib.ui.text.TextUIFactory(bar_type=DotsProgressBar)
+ factory = TextUIFactory(bar_type=DotsProgressBar)
bar = factory.nested_progress_bar()
bar.finished()
self.assertIsInstance(bar, DotsProgressBar)
def test_cli_stdin_is_default_stdin(self):
- factory = bzrlib.ui.CLIUIFactory()
+ factory = CLIUIFactory()
self.assertEqual(sys.stdin, factory.stdin)
def assert_get_bool_acceptance_of_user_input(self, factory):
@@ -190,11 +197,11 @@
self.assertEqual('', factory.stdin.readline())
def test_silent_ui_getbool(self):
- factory = bzrlib.ui.SilentUIFactory()
+ factory = SilentUIFactory()
self.assert_get_bool_acceptance_of_user_input(factory)
def test_silent_factory_prompts_silently(self):
- factory = bzrlib.ui.SilentUIFactory()
+ factory = SilentUIFactory()
stdout = StringIO()
factory.stdin = StringIO("y\n")
self.assertEqual(True,
@@ -205,12 +212,12 @@
self.assertEqual('', factory.stdin.readline())
def test_text_ui_getbool(self):
- factory = bzrlib.ui.text.TextUIFactory()
+ factory = TextUIFactory()
self.assert_get_bool_acceptance_of_user_input(factory)
def test_text_factory_prompts_and_clears(self):
# a get_boolean call should clear the pb before prompting
- factory = bzrlib.ui.text.TextUIFactory(bar_type=DotsProgressBar)
+ factory = TextUIFactory(bar_type=DotsProgressBar)
factory.stdout = _TTYStringIO()
factory.stdin = StringIO("yada\ny\n")
pb = self.apply_redirected(factory.stdin, factory.stdout,
=== modified file 'bzrlib/transport/http/_urllib.py'
--- a/bzrlib/transport/http/_urllib.py 2007-04-13 12:17:40 +0000
+++ b/bzrlib/transport/http/_urllib.py 2007-04-13 16:16:54 +0000
@@ -68,15 +68,13 @@
self._user = user
self._password = password
self._opener = self._opener_class()
- if password is not None: # '' is a valid password
+ if user and password is not None: # '' is a valid password
# Make the (user, password) available to urllib2
pm = self._opener.password_manager
pm.add_password(None, self.base, self._user, self._password)
def _ask_password(self):
"""Ask for a password if none is already available"""
- # TODO: jam 20060915 There should be a test that asserts we ask
- # for a password at the right time.
if self._password is None:
# We can't predict realm, let's try None, we'll get a
# 401 if we are wrong anyway
@@ -128,7 +126,7 @@
if self._connection is not None:
# Give back shared info
request.connection = self._connection
- elif self._user is not None:
+ elif self._user:
# We will issue our first request, time to ask for a
# password if needed
self._ask_password()
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2007-04-13 12:17:40 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2007-04-13 16:16:54 +0000
@@ -28,10 +28,11 @@
We have a custom Response class, which lets us maintain a keep-alive
connection even for requests that urllib2 doesn't expect to contain body data.
-And a custom Request class that lets us track redirections, and (soon) send
-authentication data without requiring an extra round trip to get rejected by
-the server. We also create a Request hierarchy, to make it clear what type
-of request is being made.
+And a custom Request class that lets us track redirections, and
+handle authentification schemes.
+
+We also create a Request hierarchy, to make it clear what type of
+request is being made.
"""
DEBUG = 0
@@ -769,7 +770,6 @@
# of a better magic value.
raise errors.InvalidRange(req.get_full_url(),0)
else:
- # TODO: A test is needed to exercise that code path
raise errors.InvalidHttpResponse(req.get_full_url(),
'Unable to handle http code %d: %s'
% (code, msg))
More information about the bazaar-commits
mailing list