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
10bae7d9
Commit
10bae7d9
authored
7 months ago
by
Erwan Rouchet
Committed by
Valentin Rigal
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Save Process.template_id when applying a template
parent
62fb3d63
No related branches found
No related tags found
1 merge request
!2412
Save Process.template_id when applying a template
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/process/serializers/imports.py
+1
-0
1 addition, 0 deletions
arkindex/process/serializers/imports.py
arkindex/process/tests/test_templates.py
+22
-12
22 additions, 12 deletions
arkindex/process/tests/test_templates.py
with
23 additions
and
12 deletions
arkindex/process/serializers/imports.py
+
1
−
0
View file @
10bae7d9
...
...
@@ -507,6 +507,7 @@ class ApplyProcessTemplateSerializer(ProcessACLMixin, serializers.Serializer):
# Apply the template by copying all the worker runs on to the new process
template_process
.
copy_runs
(
target_process
)
target_process
.
template_id
=
template_process
.
id
target_process
.
save
(
update_fields
=
[
"
template_id
"
])
return
target_process
def
validate_process_id
(
self
,
process
):
...
...
This diff is collapsed.
Click to expand it.
arkindex/process/tests/test_templates.py
+
22
−
12
View file @
10bae7d9
...
...
@@ -397,7 +397,7 @@ class TestTemplates(FixtureAPITestCase):
def
test_apply
(
self
):
self
.
assertIsNotNone
(
self
.
version_2
.
docker_image_iid
)
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
1
0
):
with
self
.
assertNumQueries
(
1
1
):
response
=
self
.
client
.
post
(
reverse
(
"
api:apply-process-template
"
,
kwargs
=
{
"
pk
"
:
str
(
self
.
template
.
id
)}),
data
=
{
"
process_id
"
:
str
(
self
.
process
.
id
)},
...
...
@@ -406,7 +406,10 @@ class TestTemplates(FixtureAPITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
json
()[
"
template_id
"
],
str
(
self
.
template
.
id
))
child_run
,
parent_run
=
WorkerRun
.
objects
.
select_related
(
"
version__worker
"
).
filter
(
process__id
=
response
.
json
()[
"
id
"
]).
order_by
(
"
version__worker__slug
"
).
all
()
self
.
process
.
refresh_from_db
()
self
.
assertEqual
(
self
.
process
.
template
,
self
.
template
)
child_run
,
parent_run
=
self
.
process
.
worker_runs
.
select_related
(
"
version__worker
"
).
order_by
(
"
version__worker__slug
"
)
self
.
assertEqual
(
parent_run
.
process_id
,
self
.
process
.
id
)
self
.
assertEqual
(
parent_run
.
version_id
,
self
.
version_1
.
id
)
...
...
@@ -426,22 +429,26 @@ class TestTemplates(FixtureAPITestCase):
self
.
template_run_1
.
save
()
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
9
):
with
self
.
assertNumQueries
(
10
):
response
=
self
.
client
.
post
(
reverse
(
"
api:apply-process-template
"
,
kwargs
=
{
"
pk
"
:
str
(
self
.
template
.
id
)}),
data
=
{
"
process_id
"
:
str
(
self
.
process
.
id
)},
format
=
"
json
"
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
json
()[
"
template_id
"
],
str
(
self
.
template
.
id
))
created_process_id
=
response
.
json
()[
"
id
"
]
data
=
response
.
json
()
self
.
assertEqual
(
data
[
"
id
"
],
str
(
self
.
process
.
id
))
self
.
assertEqual
(
data
[
"
template_id
"
],
str
(
self
.
template
.
id
))
self
.
process
.
refresh_from_db
()
self
.
assertEqual
(
self
.
process
.
template
,
self
.
template
)
# Only two workers runs in the
created
process
# Only two workers runs in the process
self
.
assertEqual
(
self
.
template
.
worker_runs
.
count
(),
3
)
self
.
assertEqual
(
Process
.
objects
.
get
(
id
=
created_
process
_id
)
.
worker_runs
.
count
(),
2
)
self
.
assertEqual
(
self
.
process
.
worker_runs
.
count
(),
2
)
child_run
,
parent_run
=
WorkerRun
.
object
s
.
select_related
(
"
version__worker
"
).
filter
(
process__id
=
created_process_id
).
order_by
(
"
version__worker__slug
"
)
.
all
()
child_run
,
parent_run
=
self
.
process
.
worker_run
s
.
select_related
(
"
version__worker
"
).
order_by
(
"
version__worker__slug
"
)
self
.
assertEqual
(
parent_run
.
process_id
,
self
.
process
.
id
)
self
.
assertEqual
(
parent_run
.
version_id
,
self
.
version_1
.
id
)
...
...
@@ -456,7 +463,7 @@ class TestTemplates(FixtureAPITestCase):
self
.
assertListEqual
(
child_run
.
parents
,
[
parent_run
.
id
])
# No elements initialisation run in the created process
self
.
assertFalse
(
WorkerRun
.
objects
.
filter
(
process_id
=
created_process_id
,
version_id
=
WorkerVersion
.
objects
.
init_elements_version
))
self
.
assertFalse
(
self
.
process
.
worker_runs
.
filter
(
version_id
=
WorkerVersion
.
objects
.
init_elements_version
)
.
exists
()
)
def
test_apply_delete_previous_worker_runs
(
self
):
self
.
client
.
force_login
(
self
.
user
)
...
...
@@ -469,7 +476,7 @@ class TestTemplates(FixtureAPITestCase):
parents
=
[],
)
# Apply a template that has two other worker runs
with
self
.
assertNumQueries
(
1
2
):
with
self
.
assertNumQueries
(
1
3
):
response
=
self
.
client
.
post
(
reverse
(
"
api:apply-process-template
"
,
kwargs
=
{
"
pk
"
:
str
(
self
.
template
.
id
)}),
data
=
{
"
process_id
"
:
str
(
process
.
id
)},
...
...
@@ -478,8 +485,11 @@ class TestTemplates(FixtureAPITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
json
()[
"
template_id
"
],
str
(
self
.
template
.
id
))
process
.
refresh_from_db
()
self
.
assertEqual
(
process
.
template
,
self
.
template
)
# Assert that the previous worker runs was deleted and the template was correctly applied
child_run
,
parent_run
=
WorkerRun
.
object
s
.
select_related
(
"
version__worker
"
).
filter
(
process__id
=
response
.
json
()[
"
id
"
]).
order_by
(
"
version__worker__slug
"
)
.
all
()
child_run
,
parent_run
=
process
.
worker_run
s
.
select_related
(
"
version__worker
"
).
order_by
(
"
version__worker__slug
"
)
self
.
assertEqual
(
parent_run
.
process_id
,
process
.
id
)
self
.
assertEqual
(
parent_run
.
version_id
,
self
.
version_1
.
id
)
...
...
@@ -518,7 +528,7 @@ class TestTemplates(FixtureAPITestCase):
(
FeatureUsage
.
Supported
,
True
),
])
with
self
.
assertNumQueries
(
1
0
):
with
self
.
assertNumQueries
(
1
1
):
response
=
self
.
client
.
post
(
reverse
(
"
api:apply-process-template
"
,
kwargs
=
{
"
pk
"
:
str
(
self
.
template
.
id
)}),
{
"
process_id
"
:
str
(
self
.
process
.
id
)},
...
...
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