Commit 32fd5464 authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

mirrors: tests: add exception test cases

Add test cases for 404 and 404 variant url exceptions.
parent 632a5073
import mock
import time
from urllib.error import HTTPError, URLError
from django.utils.timezone import now
from datetime import timedelta
......@@ -57,6 +59,32 @@ def test_valid_olddate(self, urlopen, Request):
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')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment