Opened 3 years ago

Closed 3 years ago

#17545 closed Bug (invalid)

Test raise an error with GZip middleware

Reported by: renolpilote@… Owned by: nobody
Component: HTTP handling Version: 1.3
Severity: Normal Keywords: gzip http
Cc: noria Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

With Gzip middleware and when running a simple view test like this :

def test_02_auth_non_requis(self):
    self.client.login(username='user1', password='pass1')
    response = self.client.get('/')
    self.assertEqual(response.status_code, 200)

It raises an

AttributeError: 'FakePayload' object has no attribute 'readline'

Here is the stack :

======================================================================
ERROR: test_02_auth_non_requis (****.auth.tests.LoginViewTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "****/auth/tests.py", line 20, in test_02_auth_non_requis
    response = self.client.get('/')
  File "/usr/lib/python2.7/site-packages/django/test/client.py", line 439, in get
    response = super(Client, self).get(path, data=data, **extra)
  File "/usr/lib/python2.7/site-packages/django/test/client.py", line 241, in get
    return self.request(**r)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response
    response = middleware_method(request, response)
  File "/usr/lib/python2.7/site-packages/django/middleware/gzip.py", line 16, in process_response
    if response.status_code != 200 or len(response.content) < 200:
  File "/usr/lib/python2.7/site-packages/django/http/__init__.py", line 601, in _get_content
    return smart_str(''.join(self._container), self._charset)
  File "/usr/lib/python2.7/site-packages/django/http/__init__.py", line 309, in xreadlines
    buf = self.readline()
  File "/usr/lib/python2.7/site-packages/django/http/__init__.py", line 305, in readline
    return self._stream.readline(*args, **kwargs)
AttributeError: 'FakePayload' object has no attribute 'readline'

All is fine without the Gzip middleware in test environnement or when running django server. So I have to overwrite installed middleware only for tests.

Change History (3)

comment:1 Changed 3 years ago by noria

  • Cc noria added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.3-rc1 to 1.3

comment:2 Changed 3 years ago by claudep

I'm trying hard to reproduce your problem in a test. However, I don't get how the FakePayload of the get request is suddenly the content of the response. I think that only another middleware or the view code can explain that.

comment:3 Changed 3 years ago by noria

  • Resolution set to invalid
  • Status changed from new to closed

Ok, I reviewed my code, and actually there was an error on the instantiation of an HttpResponse (with the request as the first argument).

I spent an hour on this stupid mistake (shame).

So I close this ticket, our good 'GZip middleware' is not to blame...

Sorry for the wrong ticket, and thank you 'claudep' for your time.

Note: See TracTickets for help on using tickets.
Back to Top