Blob Blame History Raw
From d7e7dbb02ec1512cc26b01b20564a6528d401efd Mon Sep 17 00:00:00 2001
From: Timur Sufiev <tsufiev@mirantis.com>
Date: Fri, 31 Jul 2015 13:56:30 +0300
Subject: [PATCH] Do not call _assertNotContains override in Django newer than
 1.6

Prior to Django 1.7, assertContains and assertNotContains test helper
methods behaved differently regarding the 'streaming' flag of a
response. This patch fixes the override I made earlier by calling it
conditionally only for the Django version prior to 1.7. This should
prevent problems with response._charset attribute that no longer works
in Django 1.8

Partially Implements: blueprint django18

Change-Id: I10cbc016e51b1ec7b959623989e8c4aec5899cbf
(cherry picked from commit 2f5e163338d33600507cfd8bb99af8d63757c2ce)
---
 horizon/test/helpers.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/horizon/test/helpers.py b/horizon/test/helpers.py
index ebe0100..7e5053b 100644
--- a/horizon/test/helpers.py
+++ b/horizon/test/helpers.py
@@ -218,12 +218,24 @@ class TestCase(django_test.TestCase):
 
     def assertNotContains(self, response, text, status_code=200,
                           msg_prefix='', html=False):
+        # Prior to Django 1.7 assertContains and assertNotContains behaved
+        # differently regarding response's 'streaming' flag
+        if django.VERSION < (1, 7):
+            return self._assertNotContains(response, text, status_code,
+                                           msg_prefix, html)
+        else:
+            return super(TestCase, self).assertNotContains(
+                response, text, status_code, msg_prefix, html)
+
+    def _assertNotContains(self, response, text, status_code=200,
+                           msg_prefix='', html=False):
         """Asserts that a response indicates that some content was retrieved
         successfully, (i.e., the HTTP status code was as expected), and that
         ``text`` doesn't occurs in the content of the response.
 
         This is an override of django_test.TestCase.assertNotContains method,
-        which is able to work with StreamingHttpResponse.
+        which is able to work with StreamingHttpResponse. Should be called
+        for Django versions prior to 1.7.
         """
         # If the response supports deferred rendering and hasn't been rendered
         # yet, then ensure that it does get rendered before proceeding further.