source: trunk/src/allmydata/test/web/matchers.py

Last change on this file was 1cfe843d, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-22T23:40:25Z

more python2 removal

  • Property mode set to 100644
File size: 773 bytes
Line 
1"""
2Ported to Python 3.
3"""
4
5import attr
6
7from testtools.matchers import Mismatch
8
9@attr.s
10class _HasResponseCode(object):
11    match_expected_code = attr.ib()
12
13    def match(self, response):
14        actual_code = response.code
15        mismatch = self.match_expected_code.match(actual_code)
16        if mismatch is None:
17            return None
18        return Mismatch(
19            u"Response {} code: {}".format(
20                response,
21                mismatch.describe(),
22            ),
23            mismatch.get_details(),
24        )
25
26def has_response_code(match_expected_code):
27    """
28    Match a Treq response with the given code.
29
30    :param int expected_code: The HTTP response code expected of the response.
31    """
32    return _HasResponseCode(match_expected_code)
Note: See TracBrowser for help on using the repository browser.