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
1429f1a7
Commit
1429f1a7
authored
2 years ago
by
ml bonhomme
Committed by
Erwan Rouchet
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Block applying a template if it has unavailable worker version(s)
parent
6d778096
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1882
Block applying a template if it has unavailable worker version(s)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/process/serializers/imports.py
+9
-1
9 additions, 1 deletion
arkindex/process/serializers/imports.py
arkindex/process/tests/test_templates.py
+18
-3
18 additions, 3 deletions
arkindex/process/tests/test_templates.py
with
27 additions
and
4 deletions
arkindex/process/serializers/imports.py
+
9
−
1
View file @
1429f1a7
from
django.conf
import
settings
from
django.db.models
import
Q
from
rest_framework
import
serializers
from
rest_framework.exceptions
import
PermissionDenied
,
ValidationError
from
arkindex.documents.models
import
Corpus
,
Element
,
ElementType
from
arkindex.process.models
import
ActivityState
,
DataFile
,
Process
,
ProcessMode
,
WorkerRun
from
arkindex.process.models
import
ActivityState
,
DataFile
,
Process
,
ProcessMode
,
WorkerRun
,
WorkerVersionState
from
arkindex.process.serializers.git
import
RevisionSerializer
from
arkindex.project.mixins
import
ProcessACLMixin
from
arkindex.project.serializer_fields
import
EnumField
,
LinearRingField
...
...
@@ -311,6 +312,13 @@ class ApplyProcessTemplateSerializer(ProcessACLMixin, serializers.Serializer):
raise
PermissionDenied
(
detail
=
'
You do not have a contributor access to this process.
'
)
return
process
def
validate
(
self
,
data
):
template_process
=
self
.
context
[
"
template
"
]
unavailable
=
template_process
.
versions
.
filter
(
~
Q
(
state
=
WorkerVersionState
.
Available
)
|
Q
(
docker_image_id
=
None
))
if
unavailable
.
exists
():
raise
ValidationError
(
detail
=
'
This template contains one or more unavailable worker versions and cannot be applied.
'
)
return
data
class
ElementsWorkflowSerializer
(
serializers
.
Serializer
):
...
...
This diff is collapsed.
Click to expand it.
arkindex/process/tests/test_templates.py
+
18
−
3
View file @
1429f1a7
...
...
@@ -4,7 +4,7 @@ from rest_framework import status
from
rest_framework.reverse
import
reverse
from
arkindex.documents.models
import
Corpus
from
arkindex.process.models
import
ProcessMode
,
WorkerConfiguration
,
WorkerRun
,
WorkerVersion
from
arkindex.process.models
import
ProcessMode
,
WorkerConfiguration
,
WorkerRun
,
WorkerVersion
,
WorkerVersionState
from
arkindex.project.tests
import
FixtureAPITestCase
from
arkindex.users.models
import
Role
,
User
...
...
@@ -254,7 +254,7 @@ class TestTemplates(FixtureAPITestCase):
def
test_apply_process_template
(
self
):
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
1
7
):
with
self
.
assertNumQueries
(
1
8
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
self
.
process
.
id
)}),
...
...
@@ -282,7 +282,7 @@ class TestTemplates(FixtureAPITestCase):
parents
=
[],
)
# Apply a template that has two other worker runs
with
self
.
assertNumQueries
(
1
7
):
with
self
.
assertNumQueries
(
1
8
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
process
.
id
)}),
...
...
@@ -300,6 +300,21 @@ class TestTemplates(FixtureAPITestCase):
self
.
assertTrue
(
self
.
template
.
worker_runs
.
filter
(
version
=
parent_run
.
version
).
exists
())
self
.
assertTrue
(
self
.
template
.
worker_runs
.
filter
(
version
=
child_run
.
version
).
exists
())
def
test_apply_process_template_unavailable_worker_version
(
self
):
self
.
version_2
.
state
=
WorkerVersionState
.
Error
self
.
version_2
.
save
()
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
15
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
self
.
process
.
id
)}),
content_type
=
'
application/json
'
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
non_field_errors
'
:
[
'
This template contains one or more unavailable worker versions and cannot be applied.
'
]})
self
.
process
.
refresh_from_db
()
self
.
assertEqual
(
self
.
process
.
template
,
None
)
def
test_list_templates_ignores_configuration_filter
(
self
):
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
7
):
...
...
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