|
1 |
| -from django.test import TestCase |
| 1 | +from mirrors.tests.conftest import NAME, HOSTNAME, PROTOCOL, URL |
2 | 2 |
|
3 |
| -from mirrors.models import Mirror, CheckLocation |
4 |
| -from mirrors.tests import create_mirror_url |
5 | 3 |
|
| 4 | +def test_mirrorurl_address_families(mirrorurl): |
| 5 | + assert not mirrorurl.address_families() is None |
6 | 6 |
|
7 |
| -class MirrorUrlTest(TestCase): |
8 |
| - def setUp(self): |
9 |
| - self.mirror_url = create_mirror_url() |
| 7 | +def test_mirrorurl_hostname(mirrorurl): |
| 8 | + assert mirrorurl.hostname == HOSTNAME |
10 | 9 |
|
11 |
| - def testAddressFamilies(self): |
12 |
| - self.assertIsNotNone(self.mirror_url.address_families()) |
| 10 | +def test_mirrorurl_get_absolute_url(mirrorurl): |
| 11 | + absolute_url = mirrorurl.get_absolute_url() |
| 12 | + expected = '/mirrors/%s/%d/' % (mirrorurl.mirror.name, mirrorurl.pk) |
| 13 | + assert absolute_url == expected |
13 | 14 |
|
14 |
| - def testHostname(self): |
15 |
| - self.assertEqual(self.mirror_url.hostname, 'archlinux.org') |
| 15 | +def test_mirrorurl_overview(client, mirrorurl): |
| 16 | + response = client.get('/mirrors/') |
| 17 | + assert response.status_code == 200 |
| 18 | + assert mirrorurl.mirror.name in response.content.decode() |
16 | 19 |
|
17 |
| - def testGetAbsoluteUrl(self): |
18 |
| - absolute_url = self.mirror_url.get_absolute_url() |
19 |
| - expected = '/mirrors/%s/%d/' % (self.mirror_url.mirror.name, self.mirror_url.pk) |
20 |
| - self.assertEqual(absolute_url, expected) |
| 20 | +def test_mirrorurl_get_full_url(mirrorurl): |
| 21 | + assert 'mirrors/{}'.format(mirrorurl.mirror.name) in mirrorurl.get_full_url() |
21 | 22 |
|
22 |
| - def test_mirror_overview(self): |
23 |
| - response = self.client.get('/mirrors/') |
24 |
| - self.assertEqual(response.status_code, 200) |
25 |
| - self.assertIn(self.mirror_url.mirror.name, response.content.decode()) |
| 23 | +def test_mirror_url_clean(mirrorurl): |
| 24 | + mirrorurl.clean() |
| 25 | + # TOOD(jelle): this expects HOSTNAME to resolve, maybe mock |
| 26 | + assert mirrorurl.has_ipv4 == True |
| 27 | + assert mirrorurl.has_ipv6 == True |
26 | 28 |
|
27 |
| - def testClean(self): |
28 |
| - # TODO: add test for self.mirror_url.clean() |
29 |
| - pass |
| 29 | +def test_mirrorurl_repr(mirrorurl): |
| 30 | + assert URL in repr(mirrorurl) |
30 | 31 |
|
31 |
| - def tearDown(self): |
32 |
| - self.mirror_url.delete() |
33 | 32 |
|
| 33 | +def test_mirror_get_full_url(mirror): |
| 34 | + assert mirror.get_absolute_url() in mirror.get_full_url() |
| 35 | + assert 'http' in mirror.get_full_url('http') |
34 | 36 |
|
35 |
| -class MirrorTest(TestCase): |
36 |
| - def setUp(self): |
37 |
| - self.mirror = Mirror.objects.create(name='mirror1', |
38 |
| - |
| 37 | +def test_mirror_downstream(mirror): |
| 38 | + assert list(mirror.downstream()) == [] |
39 | 39 |
|
40 |
| - def tearDown(self): |
41 |
| - self.mirror.delete() |
| 40 | +def test_mirror_get_absolute_url(mirror): |
| 41 | + absolute_url = mirror.get_absolute_url() |
| 42 | + expected = '/mirrors/{}/'.format(mirror.name) |
| 43 | + assert absolute_url == expected |
42 | 44 |
|
43 |
| - def test_downstream(self): |
44 |
| - self.assertEqual(list(self.mirror.downstream()), []) |
| 45 | +def test_mirror_rer(mirror): |
| 46 | + assert NAME in repr(mirror) |
45 | 47 |
|
46 |
| - def test_get_absolute_url(self): |
47 |
| - absolute_url = self.mirror.get_absolute_url() |
48 |
| - expected = '/mirrors/{}/'.format(self.mirror.name) |
49 |
| - self.assertEqual(absolute_url, expected) |
50 | 48 |
|
51 |
| - def test_get_full_url(self): |
52 |
| - self.assertIn(self.mirror.get_absolute_url(), self.mirror.get_full_url()) |
53 |
| - self.assertIn('http', self.mirror.get_full_url('http')) |
| 49 | +def test_checklocation_family(checklocation): |
| 50 | + assert isinstance(checklocation.family, int) |
54 | 51 |
|
| 52 | +def test_checklocation_ip_version(checklocation): |
| 53 | + assert isinstance(checklocation.ip_version, int) |
55 | 54 |
|
56 |
| -class CheckLocationTest(TestCase): |
57 |
| - def setUp(self): |
58 |
| - self.checkloc = CheckLocation.objects.create(hostname='arch.org', |
59 |
| - source_ip='127.0.0.1', |
60 |
| - country='US') |
| 55 | +def test_checklocation_repr(checklocation): |
| 56 | + assert HOSTNAME in repr(checklocation) |
61 | 57 |
|
62 |
| - def tearDown(self): |
63 |
| - self.checkloc.delete() |
64 | 58 |
|
65 |
| - def test_family(self): |
66 |
| - # TODO: mock socket.getaddrinfo in CheckLocation.family |
67 |
| - self.assertIsInstance(self.checkloc.family, int) |
68 |
| - |
69 |
| - def test_ip_version(self): |
70 |
| - self.assertIsInstance(self.checkloc.ip_version, int) |
| 59 | +def test_mirrorprotocol_repr(mirrorprotocol): |
| 60 | + assert PROTOCOL in repr(mirrorprotocol) |
0 commit comments