Skip to content

Commit aeffc02

Browse files
committed
mirrors: tests: convert test_models to pytest
1 parent 26201b6 commit aeffc02

File tree

1 file changed

+41
-51
lines changed

1 file changed

+41
-51
lines changed

mirrors/tests/test_models.py

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,60 @@
1-
from django.test import TestCase
1+
from mirrors.tests.conftest import NAME, HOSTNAME, PROTOCOL, URL
22

3-
from mirrors.models import Mirror, CheckLocation
4-
from mirrors.tests import create_mirror_url
53

4+
def test_mirrorurl_address_families(mirrorurl):
5+
assert not mirrorurl.address_families() is None
66

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
109

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
1314

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()
1619

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()
2122

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
2628

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)
3031

31-
def tearDown(self):
32-
self.mirror_url.delete()
3332

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')
3436

35-
class MirrorTest(TestCase):
36-
def setUp(self):
37-
self.mirror = Mirror.objects.create(name='mirror1',
38-
admin_email='[email protected]')
37+
def test_mirror_downstream(mirror):
38+
assert list(mirror.downstream()) == []
3939

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
4244

43-
def test_downstream(self):
44-
self.assertEqual(list(self.mirror.downstream()), [])
45+
def test_mirror_rer(mirror):
46+
assert NAME in repr(mirror)
4547

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)
5048

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)
5451

52+
def test_checklocation_ip_version(checklocation):
53+
assert isinstance(checklocation.ip_version, int)
5554

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)
6157

62-
def tearDown(self):
63-
self.checkloc.delete()
6458

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

Comments
 (0)