Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
a6822c71
Commit
a6822c71
authored
5 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle HTTP errors on image checks
parent
02de936e
No related branches found
No related tags found
1 merge request
!654
Handle HTTP errors on image checks
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/images/serializers.py
+5
-2
5 additions, 2 deletions
arkindex/images/serializers.py
arkindex/images/tests/test_image_api.py
+21
-0
21 additions, 0 deletions
arkindex/images/tests/test_image_api.py
with
26 additions
and
2 deletions
arkindex/images/serializers.py
+
5
−
2
View file @
a6822c71
...
...
@@ -4,6 +4,7 @@ from arkindex.images.models import ImageServer, Image, Zone
from
arkindex.dataimport.models
import
DataFile
from
arkindex.project.aws
import
S3FileStatus
from
django.db.models
import
F
,
Value
,
CharField
from
requests.exceptions
import
RequestException
from
rest_framework.exceptions
import
ValidationError
,
APIException
from
rest_framework
import
serializers
import
re
...
...
@@ -59,10 +60,12 @@ class ImageSerializer(serializers.ModelSerializer):
elif
value
==
S3FileStatus
.
Checked
:
# Perform image validation if we are updating an existing image to Checked
try
:
if
not
self
.
instance
.
server
.
read_only
:
if
self
.
instance
.
server
.
s3_bucket
and
not
self
.
instance
.
server
.
read_only
:
self
.
instance
.
check_hash
(
raise_exc
=
True
)
self
.
instance
.
perform_check
(
raise_exc
=
True
)
except
(
AssertionError
,
ValueError
)
as
e
:
except
(
AssertionError
,
ValueError
,
RequestException
)
as
e
:
self
.
instance
.
status
=
S3FileStatus
.
Error
self
.
instance
.
save
()
raise
ValidationError
(
str
(
e
))
return
value
...
...
This diff is collapsed.
Click to expand it.
arkindex/images/tests/test_image_api.py
+
21
−
0
View file @
a6822c71
...
...
@@ -7,6 +7,7 @@ from django.test import override_settings
from
django.urls
import
reverse
from
unittest.mock
import
patch
,
call
import
random
import
responses
class
ImageMethods
:
...
...
@@ -229,6 +230,26 @@ class TestImageApi(FixtureAPITestCase):
self
.
assertEqual
(
check_hash_mock
.
call_args
,
call
(
raise_exc
=
True
))
self
.
assertEqual
(
perform_check_mock
.
call_args
,
call
(
raise_exc
=
True
))
@responses.activate
def
test_update_image_check_fail
(
self
):
"""
Test setting an image
'
s status to Checked runs the image checks
"""
url
=
'
https://test-server.eu/images/notfound/info.json
'
responses
.
add
(
responses
.
GET
,
url
,
status
=
404
)
img
=
self
.
server
.
images
.
create
(
status
=
S3FileStatus
.
Unchecked
,
path
=
'
notfound
'
,
)
response
=
self
.
client
.
put
(
reverse
(
'
api:image-retrieve
'
,
kwargs
=
{
'
pk
'
:
str
(
img
.
id
)}),
{
'
status
'
:
'
checked
'
},
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
json
(),
{
'
status
'
:
[
f
'
404 Client Error: Not Found for url:
{
url
}
'
]})
img
.
refresh_from_db
()
self
.
assertEqual
(
img
.
status
,
S3FileStatus
.
Error
)
@patch
(
'
arkindex.images.serializers.Image.perform_check
'
)
@patch
(
'
arkindex.images.serializers.Image.check_hash
'
)
def
test_update_image_server_read_only
(
self
,
check_hash_mock
,
perform_check_mock
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment