File: test_wsgi_errors.py

package info (click to toggle)
python-falcon 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 33,608; javascript: 92; sh: 50; makefile: 50
file content (45 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import io

import pytest

import falcon
from falcon import testing

unicode_message = 'Unicode: \x80'


@pytest.fixture
def client():
    app = falcon.App()

    tehlogger = LoggerResource()
    app.add_route('/logger', tehlogger)
    return testing.TestClient(app)


class LoggerResource:
    def on_get(self, req, resp):
        req.log_error(unicode_message)

    def on_head(self, req, resp):
        req.log_error(unicode_message.encode('utf-8'))


class TestWSGIError:
    def setup_method(self, method):
        self.wsgierrors_buffer = io.BytesIO()

        # Simulate Gunicorn's behavior under Python 3
        self.wsgierrors = io.TextIOWrapper(
            self.wsgierrors_buffer, line_buffering=True, encoding='utf-8'
        )

    def test_responder_logged_bytestring(self, client):
        client.simulate_request(
            path='/logger', wsgierrors=self.wsgierrors, query_string='amount=10'
        )

        log = self.wsgierrors_buffer.getvalue()

        assert unicode_message.encode('utf-8') in log
        assert b'?amount=10' in log