Use DummyRequest in storage tests

Using twisted.web.server.Request causes test_new_style_classes to
fail like so:

  Traceback (most recent call last):
  Failure: testtools.testresult.real._StringException: Traceback (most recent call last):
    File ".tox/coverage/lib/python2.7/site-packages/allmydata/test/test_python2_regressions.py", line 69, in test_new_style_classes
      "Expected to find no classic classes.",
    File ".tox/coverage/lib/python2.7/site-packages/testtools/testcase.py", line 502, in assertThat
      raise mismatch_error
  testtools.matchers._impl.MismatchError: !=:
  reference = set([])
  actual    = set([<class allmydata.test.test_storage.JSONRequest at 0x7fd938040bb0>])
  : Expected to find no classic classes.

Seems that `DummyRequest` is an acceptable new style class.
This commit is contained in:
Sajith Sasidharan 2020-04-06 21:48:49 -04:00
parent b2b7061980
commit 82cd5a87fe

View File

@ -11,8 +11,8 @@ from twisted.web.template import flattenString
# web/common.py, we can use `twisted.web.iweb.IRequest` here.
from nevow.inevow import IRequest
from twisted.web.server import Request
from twisted.web.test.test_web import DummyChannel
# from twisted.web.server import Request
from twisted.web.test.test_web import DummyRequest
from zope.interface import implements
from foolscap.api import fireEventually
@ -2990,7 +2990,7 @@ def renderDeferred(ss):
elem = StorageStatusElement(ss._storage, ss._nickname)
return flattenString(None, elem)
class JSONRequest(Request):
class JSONRequest(DummyRequest):
"""
A Request with t=json argument added to it.
@ -2999,7 +2999,7 @@ class JSONRequest(Request):
implements(IRequest)
def __init__(self, **kwargs):
Request.__init__(self, DummyChannel(), **kwargs)
DummyRequest.__init__(self, b"/", **kwargs)
self.args = {"t": ["json"]}
self.fields = {}