| Line | |
|---|
| 1 | """ |
|---|
| 2 | Ported to Python 3. |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | import attr |
|---|
| 6 | |
|---|
| 7 | from testtools.matchers import Mismatch |
|---|
| 8 | |
|---|
| 9 | @attr.s |
|---|
| 10 | class _HasResponseCode: |
|---|
| 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 | |
|---|
| 26 | def 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.