~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
                                             auth_scheme_scenarios)
144
144
    tests.multiply_tests(tpa_tests, tpa_scenarios, result)
145
145
 
146
 
    # activity: activity on all http versions on all implementations
 
146
    # activity: on all http[s] versions on all implementations
147
147
    tpact_tests, remaining_tests = tests.split_suite_by_condition(
148
148
        remaining_tests, tests.condition_isinstance((
149
149
                TestActivity,
150
150
                )))
151
151
    activity_scenarios = [
152
 
        ('http', dict(_activity_server=ActivityHTTPServer)),
 
152
        ('urllib,http', dict(_activity_server=ActivityHTTPServer,
 
153
                             _transport=_urllib.HttpTransport_urllib,)),
153
154
        ]
154
155
    if tests.HTTPSServerFeature.available():
155
156
        activity_scenarios.append(
156
 
            ('https', dict(_activity_server=ActivityHTTPSServer)))
157
 
    tpact_scenarios = tests.multiply_scenarios(tp_scenarios,
158
 
        activity_scenarios)
 
157
            ('urllib,https', dict(_activity_server=ActivityHTTPSServer,
 
158
                                  _transport=_urllib.HttpTransport_urllib,)),)
 
159
    if pycurl_present:
 
160
        activity_scenarios.append(
 
161
            ('pycurl,http', dict(_activity_server=ActivityHTTPServer,
 
162
                                 _transport=PyCurlTransport,)),)
 
163
        if tests.HTTPSServerFeature.available():
 
164
            from bzrlib.tests import (
 
165
                ssl_certs,
 
166
                )
 
167
            # FIXME: Until we have a better way to handle self-signed
 
168
            # certificates (like allowing them in a test specific
 
169
            # authentication.conf for example), we need some specialized pycurl
 
170
            # transport for tests.
 
171
            class HTTPS_pycurl_transport(PyCurlTransport):
 
172
 
 
173
                def __init__(self, base, _from_transport=None):
 
174
                    super(HTTPS_pycurl_transport, self).__init__(
 
175
                        base, _from_transport)
 
176
                    self.cabundle = str(ssl_certs.build_path('ca.crt'))
 
177
 
 
178
            activity_scenarios.append(
 
179
                ('pycurl,https', dict(_activity_server=ActivityHTTPSServer,
 
180
                                      _transport=HTTPS_pycurl_transport,)),)
 
181
 
 
182
    tpact_scenarios = tests.multiply_scenarios(activity_scenarios,
 
183
                                               protocol_scenarios)
159
184
    tests.multiply_tests(tpact_tests, tpact_scenarios, result)
160
185
 
161
186
    # No parametrization for the remaining tests
1544
1569
        self.server.add_user('joe', 'foo')
1545
1570
        t = self.get_user_transport(None, None)
1546
1571
        stdout = tests.StringIOWrapper()
1547
 
        ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n', stdout=stdout)
 
1572
        stderr = tests.StringIOWrapper()
 
1573
        ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n',
 
1574
                                            stdout=stdout, stderr=stderr)
1548
1575
        self.assertEqual('contents of a\n',t.get('a').read())
1549
1576
        # stdin should be empty
1550
1577
        self.assertEqual('', ui.ui_factory.stdin.readline())
1551
 
        stdout.seek(0)
 
1578
        stderr.seek(0)
1552
1579
        expected_prompt = self._expected_username_prompt(t._unqualified_scheme)
1553
 
        self.assertEquals(expected_prompt, stdout.read(len(expected_prompt)))
 
1580
        self.assertEquals(expected_prompt, stderr.read(len(expected_prompt)))
 
1581
        self.assertEquals('', stdout.getvalue())
1554
1582
        self._check_password_prompt(t._unqualified_scheme, 'joe',
1555
 
                                    stdout.readline())
 
1583
                                    stderr.readline())
1556
1584
 
1557
1585
    def test_prompt_for_password(self):
1558
1586
        if self._testing_pycurl():
1563
1591
        self.server.add_user('joe', 'foo')
1564
1592
        t = self.get_user_transport('joe', None)
1565
1593
        stdout = tests.StringIOWrapper()
1566
 
        ui.ui_factory = tests.TestUIFactory(stdin='foo\n', stdout=stdout)
1567
 
        self.assertEqual('contents of a\n',t.get('a').read())
 
1594
        stderr = tests.StringIOWrapper()
 
1595
        ui.ui_factory = tests.TestUIFactory(stdin='foo\n',
 
1596
                                            stdout=stdout, stderr=stderr)
 
1597
        self.assertEqual('contents of a\n', t.get('a').read())
1568
1598
        # stdin should be empty
1569
1599
        self.assertEqual('', ui.ui_factory.stdin.readline())
1570
1600
        self._check_password_prompt(t._unqualified_scheme, 'joe',
1571
 
                                    stdout.getvalue())
 
1601
                                    stderr.getvalue())
 
1602
        self.assertEquals('', stdout.getvalue())
1572
1603
        # And we shouldn't prompt again for a different request
1573
1604
        # against the same transport.
1574
1605
        self.assertEqual('contents of b\n',t.get('b').read())