|
1 |
| -from django.test import TestCase |
2 |
| - |
3 |
| -from mirrors.tests import create_mirror_url |
4 | 1 | from mirrors.models import Mirror
|
5 | 2 |
|
| 3 | +# TODO(jelle): add test for https/rsync mirrors |
| 4 | + |
| 5 | + |
| 6 | +def test_mirrorlist(client, mirrorurl): |
| 7 | + response = client.get('/mirrorlist/') |
| 8 | + assert response.status_code == 200 |
| 9 | + |
| 10 | + |
| 11 | +def test_mirrorlist_tier_last(client, mirrorurl): |
| 12 | + last_tier = Mirror.TIER_CHOICES[-1][0] |
| 13 | + response = client.get('/mirrorlist/tier/{}/'.format(last_tier + 1)) |
| 14 | + assert response.status_code == 404 |
| 15 | + |
| 16 | + |
| 17 | +def test_mirrorlist_all(client, mirrorurl): |
| 18 | + response = client.get('/mirrorlist/all/') |
| 19 | + assert response.status_code == 200 |
| 20 | + assert mirrorurl.hostname in response.content.decode() |
| 21 | + |
| 22 | + |
| 23 | +def test_mirrorlist_all_https(client, mirrorurl): |
| 24 | + response = client.get('/mirrorlist/all/https/') |
| 25 | + assert response.status_code == 200 |
| 26 | + assert mirrorurl.hostname in response.content.decode() |
| 27 | + |
| 28 | + |
| 29 | +def test_mirrorlist_all_http(client, mirrorurl): |
| 30 | + # First test that without any http mirrors, we get a 404. |
| 31 | + response = client.get('/mirrorlist/all/http/') |
| 32 | + assert response.status_code == 404 |
| 33 | + |
| 34 | + |
| 35 | +def test_mirrorlist_status(client, mirrorurl): |
| 36 | + response = client.get('/mirrorlist/?country=all&use_mirror_status=on') |
| 37 | + assert response.status_code == 200 |
| 38 | + |
| 39 | + |
| 40 | +def test_mirrorlist_filter(client, create_mirrorurl): |
| 41 | + mirror1 = create_mirrorurl('JP', 'https://jp.org') |
| 42 | + mirror2 = create_mirrorurl() |
| 43 | + |
| 44 | + # First test that we correctly see the above mirror. |
| 45 | + response = client.get('/mirrorlist/?country=JP&protocol=https') |
| 46 | + assert response.status_code == 200 |
| 47 | + assert mirror1.hostname in response.content.decode() |
6 | 48 |
|
7 |
| -class MirrorListTest(TestCase): |
8 |
| - def setUp(self): |
9 |
| - self.mirror_url = create_mirror_url() |
10 |
| - |
11 |
| - def tearDown(self): |
12 |
| - self.mirror_url.delete() |
13 |
| - |
14 |
| - def test_mirrorlist(self): |
15 |
| - response = self.client.get('/mirrorlist/') |
16 |
| - self.assertEqual(response.status_code, 200) |
17 |
| - |
18 |
| - def test_mirrorlist_tier_last(self): |
19 |
| - last_tier = Mirror.TIER_CHOICES[-1][0] |
20 |
| - response = self.client.get('/mirrorlist/tier/{}/'.format(last_tier + 1)) |
21 |
| - self.assertEqual(response.status_code, 404) |
22 |
| - |
23 |
| - def test_mirrorlist_all(self): |
24 |
| - response = self.client.get('/mirrorlist/all/') |
25 |
| - self.assertEqual(response.status_code, 200) |
26 |
| - self.assertIn(self.mirror_url.hostname, response.content.decode()) |
27 |
| - |
28 |
| - def test_mirrorlist_all_http(self): |
29 |
| - response = self.client.get('/mirrorlist/all/http/') |
30 |
| - self.assertEqual(response.status_code, 200) |
31 |
| - self.assertIn(self.mirror_url.hostname, response.content.decode()) |
32 |
| - |
33 |
| - def test_mirrorlist_all_https(self): |
34 |
| - # First test that without any https mirrors, we get a 404. |
35 |
| - response = self.client.get('/mirrorlist/all/https/') |
36 |
| - self.assertEqual(response.status_code, 404) |
37 |
| - |
38 |
| - # Now, after adding an HTTPS mirror, we expect to succeed. |
39 |
| - https_mirror_url = create_mirror_url( |
40 |
| - name='https_mirror', |
41 |
| - protocol='https', |
42 |
| - url='https://wikipedia.org') |
43 |
| - response = self.client.get('/mirrorlist/all/https/') |
44 |
| - self.assertEqual(response.status_code, 200) |
45 |
| - https_mirror_url.delete() |
46 |
| - |
47 |
| - def test_mirrorlist_filter(self): |
48 |
| - jp_mirror_url = create_mirror_url( |
49 |
| - name='jp_mirror', |
50 |
| - country='JP', |
51 |
| - protocol='https', |
52 |
| - url='https://wikipedia.jp') |
53 |
| - |
54 |
| - # First test that we correctly see the above mirror. |
55 |
| - response = self.client.get('/mirrorlist/?country=JP&protocol=https') |
56 |
| - self.assertEqual(response.status_code, 200) |
57 |
| - self.assertIn(jp_mirror_url.hostname, response.content.decode()) |
58 |
| - |
59 |
| - # Now confirm that the US mirror did not show up. |
60 |
| - self.assertNotIn(self.mirror_url.hostname, response.content.decode()) |
61 |
| - |
62 |
| - jp_mirror_url.delete() |
63 |
| - |
64 |
| - def test_mirrorlist_status(self): |
65 |
| - response = self.client.get('/mirrorlist/?country=all&use_mirror_status=on') |
66 |
| - self.assertEqual(response.status_code, 200) |
| 49 | + # Now confirm that the US mirror did not show up. |
| 50 | + assert not mirror2.hostname in response.content.decode() |
0 commit comments