1717from django .db .utils import DEFAULT_DB_ALIAS
1818from django .test .testcases import TransactionTestCase
1919
20-
21- try :
22- from importlib import reload
23- except ImportError : # Python < 3
24- pass
20+ from importlib import reload
2521import sys
2622import unittest
2723
3329from django .test .client import RequestFactory , Client
3430from django .test .utils import override_settings
3531
36- from mock import patch
32+ from unittest . mock import patch
3733
3834from watchman import checks , views
3935
40- PYTHON_VERSION = sys .version_info [0 ]
41-
4236
4337class AuthenticatedUser (AnonymousUser ):
4438 @property
@@ -55,12 +49,11 @@ def __bool__(self):
5549 return CallableTrue ()
5650
5751
58- if django .VERSION >= (1 , 7 ):
59- # Initialize Django
60- django .setup ()
52+ # Initialize Django
53+ django .setup ()
6154
62- # Silence MIDDLEWARE_CLASSES warning as this is not an actual Django project
63- settings .SILENCED_SYSTEM_CHECKS = ['1_7.W001' ]
55+ # Silence MIDDLEWARE_CLASSES warning as this is not an actual Django project
56+ settings .SILENCED_SYSTEM_CHECKS = ['1_7.W001' ]
6457
6558
6659def reload_settings ():
@@ -85,23 +78,16 @@ def test_response_contains_expected_checks(self):
8578 request = RequestFactory ().get ('/' )
8679 response = views .status (request )
8780
88- if PYTHON_VERSION == 2 :
89- content = json .loads (response .content )
90- self .assertItemsEqual (expected_checks , content .keys ())
91- else :
92- content = json .loads (response .content .decode ('utf-8' ))
93- self .assertCountEqual (expected_checks , content .keys ())
81+ content = json .loads (response .content .decode ('utf-8' ))
82+ self .assertCountEqual (expected_checks , content .keys ())
9483
9584 def test_check_database_handles_exception (self ):
9685 response = checks ._check_database ('foo' )
9786 self .assertFalse (response ['foo' ]['ok' ])
9887 self .assertEqual (response ['foo' ]['error' ], "The connection foo doesn't exist" )
9988
10089 def test_check_cache_handles_exception (self ):
101- if django .VERSION < (1 , 7 ):
102- expected_error = "Could not find backend 'foo': Could not find backend 'foo': foo doesn't look like a module path"
103- else :
104- expected_error = "Could not find config for 'foo' in settings.CACHES"
90+ expected_error = "Could not find config for 'foo' in settings.CACHES"
10591
10692 response = checks ._check_cache ('foo' )
10793 self .assertFalse (response ['foo' ]['ok' ])
@@ -114,12 +100,8 @@ def test_response_skipped_checks(self):
114100 })
115101 response = views .status (request )
116102
117- if PYTHON_VERSION == 2 :
118- content = json .loads (response .content )
119- self .assertItemsEqual (expected_checks , content .keys ())
120- else :
121- content = json .loads (response .content .decode ('utf-8' ))
122- self .assertCountEqual (expected_checks , content .keys ())
103+ content = json .loads (response .content .decode ('utf-8' ))
104+ self .assertCountEqual (expected_checks , content .keys ())
123105
124106 def test_response_is_404_for_checked_and_skipped_check (self ):
125107 # This is a bit of a weird one, basically if you explicitly include and
@@ -141,12 +123,8 @@ def test_response_only_single_check(self, patched_check_databases):
141123 response = views .status (request )
142124 self .assertEqual (response .status_code , 200 )
143125
144- if PYTHON_VERSION == 2 :
145- content = json .loads (response .content )
146- self .assertItemsEqual ({'databases' : []}, content )
147- else :
148- content = json .loads (response .content .decode ('utf-8' ))
149- self .assertCountEqual ({'databases' : []}, content )
126+ content = json .loads (response .content .decode ('utf-8' ))
127+ self .assertCountEqual ({'databases' : []}, content )
150128
151129 def test_response_404_when_none_specified (self ):
152130 request = RequestFactory ().get ('/' , data = {
@@ -155,12 +133,8 @@ def test_response_404_when_none_specified(self):
155133 response = views .status (request )
156134 self .assertEqual (response .status_code , 404 )
157135
158- if PYTHON_VERSION == 2 :
159- content = json .loads (response .content )
160- self .assertItemsEqual ({'message' : 'No checks found' , 'error' : 404 }, content )
161- else :
162- content = json .loads (response .content .decode ('utf-8' ))
163- self .assertCountEqual ({'message' : 'No checks found' , 'error' : 404 }, content )
136+ content = json .loads (response .content .decode ('utf-8' ))
137+ self .assertCountEqual ({'message' : 'No checks found' , 'error' : 404 }, content )
164138
165139 @override_settings (WATCHMAN_TOKEN = 'ABCDE' )
166140 @override_settings (WATCHMAN_AUTH_DECORATOR = 'watchman.decorators.token_required' )
0 commit comments