Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jelle van der Waa
Archweb
Commits
32fd5464
Commit
32fd5464
authored
Jan 21, 2019
by
Jelle van der Waa
🚧
Browse files
mirrors: tests: add exception test cases
Add test cases for 404 and 404 variant url exceptions.
parent
632a5073
Changes
1
Hide whitespace changes
Inline
Side-by-side
mirrors/tests/test_mirrorcheck.py
View file @
32fd5464
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'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment