~jelmer/loggerhead/breezy-compat

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_http_head.py

  • Committer: Colin Watson
  • Date: 2019-09-19 08:10:36 UTC
  • mfrom: (491.2.62 breezy)
  • Revision ID: cjwatson@canonical.com-20190919081036-q1symc2h2iedtlh3
[r=cjwatson] Switch loggerhead over to using the Breezy rather than Bazaar APIs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the HeadMiddleware app."""
18
18
 
19
 
from cStringIO import StringIO
20
 
 
21
 
from bzrlib import tests
22
 
 
23
 
from loggerhead.apps import http_head
24
 
 
25
 
 
26
 
content = ["<html>",
27
 
           "<head><title>Listed</title></head>",
28
 
           "<body>Content</body>",
29
 
           "</html>",
 
19
from io import BytesIO
 
20
 
 
21
from breezy import tests
 
22
 
 
23
from ..apps import http_head
 
24
 
 
25
 
 
26
content = [b"<html>",
 
27
           b"<head><title>Listed</title></head>",
 
28
           b"<body>Content</body>",
 
29
           b"</html>",
30
30
          ]
31
31
headers = {'X-Ignored-Header': 'Value'}
32
32
 
51
51
class TestHeadMiddleware(tests.TestCase):
52
52
 
53
53
    def _trap_start_response(self, status, response_headers, exc_info=None):
54
 
        self._write_buffer = StringIO()
 
54
        self._write_buffer = BytesIO()
55
55
        self._start_response_passed = (status, response_headers, exc_info)
56
56
        return self._write_buffer.write
57
57
 
64
64
        app = http_head.HeadMiddleware(app)
65
65
        self._consume_app(app, 'GET')
66
66
        self.assertEqual(('200 OK', headers, None), self._start_response_passed)
67
 
        self.assertEqualDiff(''.join(content), self._write_buffer.getvalue())
 
67
        self.assertEqualDiff(b''.join(content), self._write_buffer.getvalue())
68
68
 
69
69
    def _verify_head_no_body(self, app):
70
70
        app = http_head.HeadMiddleware(app)
71
71
        self._consume_app(app, 'HEAD')
72
72
        self.assertEqual(('200 OK', headers, None), self._start_response_passed)
73
 
        self.assertEqualDiff('', self._write_buffer.getvalue())
 
73
        self.assertEqualDiff(b'', self._write_buffer.getvalue())
74
74
 
75
75
    def test_get_passthrough_yielding(self):
76
76
        self._verify_get_passthrough(yielding_app)