Skip to content

Commit f3b53e4

Browse files
committed
mirrors: convert mirrorstatus to pytest
1 parent 9444cdd commit f3b53e4

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

mirrors/tests/test_mirrorstatus.py

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1-
from django.test import TestCase
1+
def test_mirror_status(db, client):
2+
response = client.get('/mirrors/status/')
3+
assert response.status_code == 200
24

3-
from mirrors.tests import create_mirror_url
45

6+
def test_json_endpoint(client, settings, mirrorurl):
7+
settings.CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
8+
# Disables the cache_function's cache
59

6-
class MirrorStatusTest(TestCase):
7-
def test_status(self):
8-
response = self.client.get('/mirrors/status/')
9-
self.assertEqual(response.status_code, 200)
10+
response = client.get('/mirrors/status/json/')
11+
assert response.status_code == 200
12+
data = response.json()
1013

11-
def test_json_endpoint(self):
12-
# Disables the cache_function's cache
13-
with self.settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}):
14-
response = self.client.get('/mirrors/status/json/')
15-
self.assertEqual(response.status_code, 200)
16-
data = response.json()
17-
self.assertEqual(data['urls'], [])
14+
assert len(data['urls']) == 1
15+
mirror = data['urls'][0]
16+
assert mirror['url'] == mirrorurl.url
1817

19-
mirror_url = create_mirror_url()
2018

21-
response = self.client.get('/mirrors/status/json/')
22-
self.assertEqual(response.status_code, 200)
23-
data = response.json()
19+
def test_json_endpoint_empty(db, client, settings):
20+
# Disables the cache_function's cache
21+
settings.CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
2422

25-
self.assertEqual(len(data['urls']), 1)
26-
mirror = data['urls'][0]
27-
self.assertEqual(mirror['url'], mirror_url.url)
23+
response = client.get('/mirrors/status/json/')
24+
assert response.status_code == 200
25+
data = response.json()
26+
assert data['urls'] == []
2827

29-
mirror_url.delete()
3028

31-
def test_json_tier(self):
32-
response = self.client.get('/mirrors/status/tier/99/json/')
33-
self.assertEqual(response.status_code, 404)
29+
def test_json_tier_not_found(db, client, settings):
30+
response = client.get('/mirrors/status/tier/99/json/')
31+
assert response.status_code == 404
3432

35-
response = self.client.get('/mirrors/status/tier/1/json/')
36-
self.assertEqual(response.status_code, 200)
37-
data = response.json()
38-
self.assertEqual(data['urls'], [])
3933

40-
mirror_url = create_mirror_url()
34+
def test_json_tier_empty_cache(db, client, settings):
35+
response = client.get('/mirrors/status/tier/1/json/')
36+
assert response.status_code == 200
37+
data = response.json()
38+
assert data['urls'] == []
4139

42-
# Disables the cache_function's cache
43-
with self.settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}):
44-
response = self.client.get('/mirrors/status/json/')
45-
self.assertEqual(response.status_code, 200)
46-
data = response.json()
47-
self.assertNotEqual(data['urls'], [])
4840

49-
mirror_url.delete()
41+
def test_json_tier(client, settings, mirrorurl):
42+
# Disables the cache_function's cache
43+
settings.CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
44+
45+
response = client.get('/mirrors/status/json/')
46+
assert response.status_code == 200
47+
data = response.json()
48+
assert data['urls'] != []

0 commit comments

Comments
 (0)