diff options
author | Jelle van der Waa <jelle@vdwaa.nl> | 2018-06-17 22:02:16 +0200 |
---|---|---|
committer | Jelle van der Waa <jelle@vdwaa.nl> | 2018-06-17 22:02:16 +0200 |
commit | ed1f4ce0f3f0cb88f5adb859030ae68b255e7558 (patch) | |
tree | cde8d0cde056e31c97b8beacb91ffa3c02b3b3ff /mirrors | |
parent | 35512840c9c0e4527b667e545d540a375897d6ce (diff) | |
download | archweb-ed1f4ce0f3f0cb88f5adb859030ae68b255e7558.tar.gz archweb-ed1f4ce0f3f0cb88f5adb859030ae68b255e7558.zip |
test: use response.json()
Instead of importing json and loading the response.content using
json.loads use Django's response.json() method.
Diffstat (limited to 'mirrors')
-rw-r--r-- | mirrors/tests/test_mirrorlocations.py | 4 | ||||
-rw-r--r-- | mirrors/tests/test_mirrors.py | 4 | ||||
-rw-r--r-- | mirrors/tests/test_mirrorstatus.py | 12 |
3 files changed, 7 insertions, 13 deletions
diff --git a/mirrors/tests/test_mirrorlocations.py b/mirrors/tests/test_mirrorlocations.py index 92751669..d065e2ef 100644 --- a/mirrors/tests/test_mirrorlocations.py +++ b/mirrors/tests/test_mirrorlocations.py @@ -1,5 +1,3 @@ -import json - from django.test import TestCase from mirrors.models import CheckLocation @@ -14,7 +12,7 @@ class MirrorLocationsTest(TestCase): def test_mirrorlocations_json(self): response = self.client.get('/mirrors/locations/json/') self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = response.json() self.assertEqual(1, data['version']) location = data['locations'][0]['country_code'] self.assertEqual('US', location) diff --git a/mirrors/tests/test_mirrors.py b/mirrors/tests/test_mirrors.py index 9258ad7a..558f7ea5 100644 --- a/mirrors/tests/test_mirrors.py +++ b/mirrors/tests/test_mirrors.py @@ -1,5 +1,3 @@ -import json - from django.test import TestCase from mirrors.tests import create_mirror_url @@ -28,7 +26,7 @@ class MirrorTest(TestCase): response = self.client.get(url + 'json/') self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = response.json() self.assertNotEqual(data['urls'], []) def test_url_details(self): diff --git a/mirrors/tests/test_mirrorstatus.py b/mirrors/tests/test_mirrorstatus.py index f7864b66..b2d4d65f 100644 --- a/mirrors/tests/test_mirrorstatus.py +++ b/mirrors/tests/test_mirrorstatus.py @@ -1,5 +1,3 @@ -import json - from django.test import TestCase from mirrors.tests import create_mirror_url @@ -13,7 +11,7 @@ class MirrorStatusTest(TestCase): def test_json_endpoint(self): response = self.client.get('/mirrors/status/json/') self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = response.json() self.assertEqual(data['urls'], []) mirror_url = create_mirror_url() @@ -21,13 +19,13 @@ class MirrorStatusTest(TestCase): # Verify that the cache works response = self.client.get('/mirrors/status/json/') self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = response.json() # Disables the cache_function's cache with self.settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}): response = self.client.get('/mirrors/status/json/') self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = response.json() self.assertEqual(len(data['urls']), 1) mirror = data['urls'][0] @@ -41,7 +39,7 @@ class MirrorStatusTest(TestCase): response = self.client.get('/mirrors/status/tier/1/json/') self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = response.json() self.assertEqual(data['urls'], []) mirror_url = create_mirror_url() @@ -50,7 +48,7 @@ class MirrorStatusTest(TestCase): with self.settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}): response = self.client.get('/mirrors/status/json/') self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = response.json() self.assertNotEqual(data['urls'], []) mirror_url.delete() |