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
ed0a3e4d
Commit
ed0a3e4d
authored
5 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix HTTP 500 errors on wrong filter values in ListDataImports
parent
81ded3a9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/dataimport/api.py
+40
-2
40 additions, 2 deletions
arkindex/dataimport/api.py
arkindex/dataimport/tests/test_imports.py
+7
-0
7 additions, 0 deletions
arkindex/dataimport/tests/test_imports.py
with
47 additions
and
2 deletions
arkindex/dataimport/api.py
+
40
−
2
View file @
ed0a3e4d
...
...
@@ -31,6 +31,7 @@ from arkindex_common.ml_tool import MLTool
from
arkindex_common.enums
import
DataImportMode
from
ponos.models
import
State
from
datetime
import
datetime
from
uuid
import
UUID
import
hashlib
import
magic
import
os.path
...
...
@@ -45,6 +46,36 @@ class DataImportsList(CorpusACLMixin, ListAPIView):
openapi_overrides
=
{
'
operationId
'
:
'
ListDataImports
'
,
'
tags
'
:
[
'
imports
'
],
'
parameters
'
:
[
{
'
name
'
:
'
corpus
'
,
'
in
'
:
'
query
'
,
'
description
'
:
'
Filter imports by corpus ID
'
,
'
required
'
:
False
,
'
schema
'
:
{
'
type
'
:
'
string
'
,
'
format
'
:
'
uuid
'
,
}
},
{
'
name
'
:
'
mode
'
,
'
in
'
:
'
query
'
,
'
description
'
:
'
Filter imports by mode
'
,
'
required
'
:
False
,
'
schema
'
:
{
'
enum
'
:
[
mode
.
value
for
mode
in
DataImportMode
],
},
},
{
'
name
'
:
'
id
'
,
'
in
'
:
'
query
'
,
'
description
'
:
'
Filter imports by beginning of UUID
'
,
'
required
'
:
False
,
'
schema
'
:
{
'
type
'
:
'
string
'
,
},
}
]
}
def
get_queryset
(
self
):
...
...
@@ -53,13 +84,20 @@ class DataImportsList(CorpusACLMixin, ListAPIView):
}
if
'
corpus
'
in
self
.
request
.
query_params
:
filters
[
'
corpus
'
]
=
self
.
get_corpus
(
self
.
request
.
query_params
[
'
corpus
'
])
corpus_id
=
self
.
request
.
query_params
[
'
corpus
'
]
try
:
corpus_id
=
UUID
(
corpus_id
)
except
(
AttributeError
,
ValueError
):
raise
ValidationError
({
'
corpus
'
:
"'
{}
'
is not a valid UUID
"
.
format
(
corpus_id
)})
filters
[
'
corpus
'
]
=
self
.
get_corpus
(
corpus_id
)
if
'
mode
'
in
self
.
request
.
query_params
:
try
:
filters
[
'
mode
'
]
=
DataImportMode
(
self
.
request
.
query_params
[
'
mode
'
])
except
ValueError
:
raise
ValidationError
(
"
Mode
'
{}
'
does not exist
"
.
format
(
self
.
request
.
query_params
[
'
mode
'
]))
raise
ValidationError
({
'
mode
'
:
"
Mode
'
{}
'
does not exist
"
.
format
(
self
.
request
.
query_params
[
'
mode
'
]),
})
if
'
id
'
in
self
.
request
.
query_params
:
filters
[
'
id__startswith
'
]
=
self
.
request
.
query_params
[
'
id
'
]
...
...
This diff is collapsed.
Click to expand it.
arkindex/dataimport/tests/test_imports.py
+
7
−
0
View file @
ed0a3e4d
...
...
@@ -57,6 +57,12 @@ class TestImports(FixtureAPITestCase):
self
.
assertEqual
(
len
(
data
[
'
results
'
]),
1
)
self
.
assertEqual
(
data
[
'
results
'
][
0
][
'
id
'
],
str
(
dataimport2
.
id
))
def
test_list_filter_corpus_invalid
(
self
):
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
get
(
reverse
(
'
api:import-list
'
),
{
'
corpus
'
:
'
oh-no
'
})
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
json
(),
{
'
corpus
'
:
"'
oh-no
'
is not a valid UUID
"
})
def
test_list_filter_mode
(
self
):
self
.
client
.
force_login
(
self
.
user
)
dataimport2
=
self
.
corpus
.
imports
.
create
(
...
...
@@ -73,6 +79,7 @@ class TestImports(FixtureAPITestCase):
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
get
(
reverse
(
'
api:import-list
'
),
{
'
mode
'
:
'
unexisting_mode
'
})
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
json
(),
{
'
mode
'
:
"
Mode
'
unexisting_mode
'
does not exist
"
})
def
test_list_filter_id
(
self
):
self
.
client
.
force_login
(
self
.
user
)
...
...
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