summaryrefslogtreecommitdiffstats
path: root/mirrors
diff options
context:
space:
mode:
authorJelle van der Waa <jelle@vdwaa.nl>2019-01-21 20:50:14 +0100
committerJelle van der Waa <jelle@vdwaa.nl>2019-01-21 21:20:19 +0100
commit32fd54646f0fe60f5165f49a95d21dfbfdb930e6 (patch)
tree901f35b3699495f951ef070177392500a5f73530 /mirrors
parent632a5073d9afea08ceb80cf47621640824cbc895 (diff)
downloadarchweb-32fd54646f0fe60f5165f49a95d21dfbfdb930e6.tar.gz
archweb-32fd54646f0fe60f5165f49a95d21dfbfdb930e6.zip
mirrors: tests: add exception test cases
Add test cases for 404 and 404 variant url exceptions.
Diffstat (limited to 'mirrors')
-rw-r--r--mirrors/tests/test_mirrorcheck.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/mirrors/tests/test_mirrorcheck.py b/mirrors/tests/test_mirrorcheck.py
index 9bee3b3d..ad4e8d25 100644
--- a/mirrors/tests/test_mirrorcheck.py
+++ b/mirrors/tests/test_mirrorcheck.py
@@ -1,6 +1,8 @@
import mock
import time
+from urllib.error import HTTPError, URLError
+
from django.utils.timezone import now
from datetime import timedelta
@@ -57,6 +59,32 @@ class MirrorCheckTest(TestCase):
call_command('mirrorcheck')
self.assertEqual(len(MirrorLog.objects.all()), 1)
+ @mock.patch('urllib.request.Request')
+ @mock.patch('urllib.request.urlopen')
+ def test_not_found(self, urlopen, Request):
+ excp = HTTPError('https://archlinux.org/404.txt', 404, 'Not Found', '', None)
+ urlopen.return_value.read.side_effect = excp
+ Request.get_host.return_value = 'archlinux.org'
+ Request.type.return_value = 'https'
+
+ call_command('mirrorcheck')
+ mirrorlog = MirrorLog.objects.first()
+ self.assertEqual(mirrorlog.error, str(excp))
+ self.assertEqual(mirrorlog.is_success, False)
+
+ @mock.patch('urllib.request.Request')
+ @mock.patch('urllib.request.urlopen')
+ def test_not_found_variant(self, urlopen, Request):
+ excp = URLError('550 No such file', '550.txt')
+ urlopen.return_value.read.side_effect = excp
+ Request.get_host.return_value = 'archlinux.org'
+ Request.type.return_value = 'https'
+
+ call_command('mirrorcheck')
+ mirrorlog = MirrorLog.objects.first()
+ self.assertIn(excp.reason, mirrorlog.error)
+ self.assertEqual(mirrorlog.is_success, False)
+
def test_checklocation(self):
with self.assertRaises(CheckLocation.DoesNotExist) as e:
call_command('mirrorcheck', '-l', '1')