test_web test_bad_method: remove a client.getPage

Add WebErrorMixin.assertHTTPError, to replace (getPage + shouldHTTPError)
This commit is contained in:
Brian Warner 2017-07-24 16:02:31 -05:00
parent bee05e883c
commit 202a9714c4
2 changed files with 18 additions and 5 deletions

View File

@ -1,6 +1,8 @@
import os, random, struct
import treq
from zope.interface import implementer
from twisted.internet import defer
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.interfaces import IPullProducer
from twisted.python import failure
from twisted.application import service
@ -509,6 +511,18 @@ class WebErrorMixin:
d.addBoth(self._shouldHTTPError, which, _validate)
return d
@inlineCallbacks
def assertHTTPError(self, url, code, response_substring,
method="get", persistent=False,
**args):
response = yield treq.request(method, url, persistent=persistent,
**args)
body = yield response.content()
self.assertEquals(response.code, code)
if response_substring is not None:
self.assertIn(response_substring, body)
returnValue(body)
class ErrorMixin(WebErrorMixin):
def explain_error(self, f):
if f.check(defer.FirstError):

View File

@ -4437,13 +4437,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d
@inlineCallbacks
def test_bad_method(self):
url = self.webish_url + self.public_url + "/foo/bar.txt"
d = self.shouldHTTPError("bad_method",
501, "Not Implemented",
"I don't know how to treat a BOGUS request.",
client.getPage, url, method="BOGUS")
return d
yield self.assertHTTPError(url, 501,
"I don't know how to treat a BOGUS request.",
method="BOGUS")
def test_short_url(self):
url = self.webish_url + "/uri"