diff options
author | jelle van der Waa <jelle@vdwaa.nl> | 2018-04-23 14:50:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-23 14:50:02 +0200 |
commit | 0e44ca120c9d92e4344a8301f607e4f11c211150 (patch) | |
tree | ad1cd6287ab5695f1d8d1eada4767a04f8763da5 | |
parent | 7a76e222c5de52c54b8ece5bc185112093962f41 (diff) | |
parent | a33fd7e26594a72fa1e1a9c056cb17524f7c9363 (diff) | |
download | archweb-0e44ca120c9d92e4344a8301f607e4f11c211150.tar.gz archweb-0e44ca120c9d92e4344a8301f607e4f11c211150.zip |
Merge pull request #97 from jelly/form
Form
-rw-r--r-- | mirrors/tests/__init__.py | 11 | ||||
-rw-r--r-- | mirrors/tests/test_mirrorlist.py | 30 | ||||
-rw-r--r-- | mirrors/views/mirrorlist.py | 3 |
3 files changed, 31 insertions, 13 deletions
diff --git a/mirrors/tests/__init__.py b/mirrors/tests/__init__.py index fb6c10df..a1d3c2c9 100644 --- a/mirrors/tests/__init__.py +++ b/mirrors/tests/__init__.py @@ -1,12 +1,13 @@ from mirrors.models import MirrorUrl, MirrorProtocol, Mirror -def create_mirror_url(): - mirror = Mirror.objects.create(name='mirror1', +def create_mirror_url(name='mirror1', country='US', + protocol='http', url='https://archlinux.org'): + mirror = Mirror.objects.create(name=name, admin_email='admin@archlinux.org') - mirror_protocol = MirrorProtocol.objects.create(protocol='http') - mirror_url = MirrorUrl.objects.create(url='https://archlinux.org', + mirror_protocol = MirrorProtocol.objects.create(protocol=protocol) + mirror_url = MirrorUrl.objects.create(url=url, protocol=mirror_protocol, mirror=mirror, - country='US') + country=country) return mirror_url diff --git a/mirrors/tests/test_mirrorlist.py b/mirrors/tests/test_mirrorlist.py index 5590a966..9e208125 100644 --- a/mirrors/tests/test_mirrorlist.py +++ b/mirrors/tests/test_mirrorlist.py @@ -25,16 +25,32 @@ class MirrorListTest(TestCase): self.assertIn(self.mirror_url.hostname, response.content) def test_mirrorlist_all_https(self): + # First test that without any https mirrors, we get a 404. response = self.client.get('/mirrorlist/all/https/') self.assertEqual(response.status_code, 404) - # TODO: test 200 case - def test_mirrorlist_filter(self): - response = self.client.get('/mirrorlist/?country=all&protocol=http&ip_version=4') + # Now, after adding an HTTPS mirror, we expect to succeed. + https_mirror_url = create_mirror_url( + name='https_mirror', + protocol='https', + url='https://wikipedia.org') + response = self.client.get('/mirrorlist/all/https/') self.assertEqual(response.status_code, 200) - self.assertIn(self.mirror_url.hostname, response.content) + https_mirror_url.delete() - def test_generate(self): - response = self.client.get('/mirrorlist/?country=all&protocol=http&ip_version=4') + def test_mirrorlist_filter(self): + jp_mirror_url = create_mirror_url( + name='jp_mirror', + country='JP', + protocol='https', + url='https://wikipedia.jp') + + # First test that we correctly see the above mirror. + response = self.client.get('/mirrorlist/?country=JP&protocol=https') self.assertEqual(response.status_code, 200) - self.assertIn(self.mirror_url.hostname, response.content) + self.assertIn(jp_mirror_url.hostname, response.content) + + # Now confirm that the US mirror did not show up. + self.assertNotIn(self.mirror_url.hostname, response.content) + + jp_mirror_url.delete() diff --git a/mirrors/views/mirrorlist.py b/mirrors/views/mirrorlist.py index 35d59e82..45c01819 100644 --- a/mirrors/views/mirrorlist.py +++ b/mirrors/views/mirrorlist.py @@ -55,7 +55,8 @@ class MirrorlistForm(forms.Form): @csrf_exempt def generate_mirrorlist(request): if request.method == 'POST' or len(request.GET) > 0: - form = MirrorlistForm(data=request.POST) + data = request.POST if request.method == 'POST' else request.GET + form = MirrorlistForm(data=data) if form.is_valid(): countries = form.cleaned_data['country'] protocols = form.cleaned_data['protocol'] |