|
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 |
2 | 4 |
|
3 |
| -from mirrors.tests import create_mirror_url |
4 | 5 |
|
| 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 |
5 | 9 |
|
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() |
10 | 13 |
|
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 |
18 | 17 |
|
19 |
| - mirror_url = create_mirror_url() |
20 | 18 |
|
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'}} |
24 | 22 |
|
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'] == [] |
28 | 27 |
|
29 |
| - mirror_url.delete() |
30 | 28 |
|
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 |
34 | 32 |
|
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'], []) |
39 | 33 |
|
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'] == [] |
41 | 39 |
|
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'], []) |
48 | 40 |
|
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