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
f3225da1
Commit
f3225da1
authored
2 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Support arbitrary job IDs in RetrieveJob and DestroyJob
parent
a364d72f
No related branches found
No related tags found
1 merge request
!1955
Support arbitrary job IDs in RetrieveJob and DestroyJob
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex/project/api_v1.py
+1
-1
1 addition, 1 deletion
arkindex/project/api_v1.py
arkindex/users/serializers.py
+1
-1
1 addition, 1 deletion
arkindex/users/serializers.py
arkindex/users/tests/test_jobs.py
+46
-0
46 additions, 0 deletions
arkindex/users/tests/test_jobs.py
with
48 additions
and
2 deletions
arkindex/project/api_v1.py
+
1
−
1
View file @
f3225da1
...
...
@@ -332,7 +332,7 @@ api = [
# Asynchronous jobs
path
(
'
jobs/
'
,
JobList
.
as_view
(),
name
=
'
jobs-list
'
),
path
(
'
jobs/<
uuid
:pk>/
'
,
JobRetrieve
.
as_view
(),
name
=
'
jobs-retrieve
'
),
path
(
'
jobs/<
path
:pk>/
'
,
JobRetrieve
.
as_view
(),
name
=
'
jobs-retrieve
'
),
# OpenAPI Schema
path
(
'
openapi/
'
,
OpenApiSchemaView
.
as_view
(),
name
=
'
openapi-schema
'
),
...
...
This diff is collapsed.
Click to expand it.
arkindex/users/serializers.py
+
1
−
1
View file @
f3225da1
...
...
@@ -230,7 +230,7 @@ class JobSerializer(serializers.Serializer):
"""
Serializers a RQ job.
"""
id
=
serializers
.
UUID
Field
(
read_only
=
True
)
id
=
serializers
.
Char
Field
(
read_only
=
True
)
description
=
serializers
.
CharField
(
read_only
=
True
)
progress
=
serializers
.
FloatField
(
min_value
=
0
,
max_value
=
1
,
read_only
=
True
,
allow_null
=
True
)
status
=
serializers
.
SerializerMethodField
()
...
...
This diff is collapsed.
Click to expand it.
arkindex/users/tests/test_jobs.py
+
46
−
0
View file @
f3225da1
...
...
@@ -180,6 +180,34 @@ class TestJobs(FixtureAPITestCase):
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_count
,
1
)
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_args
,
call
(
self
.
user_mocked_job
.
id
))
@patch
(
'
arkindex.users.api.get_queue
'
)
def
test_retrieve_custom_id
(
self
,
get_queue_mock
):
"""
Job IDs can be any string, including one with slashes, so we should allow any string in RetrieveJob
"""
job
=
MockedJob
(
user_id
=
self
.
user
.
id
,
id
=
'
a/b/c/d
'
)
get_queue_mock
.
return_value
.
fetch_job
.
return_value
=
job
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
2
):
response
=
self
.
client
.
get
(
reverse
(
'
api:jobs-retrieve
'
,
kwargs
=
{
'
pk
'
:
'
a/b/c/d
'
}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
id
'
:
'
a/b/c/d
'
,
'
status
'
:
'
queued
'
,
'
enqueued_at
'
:
'
2020-01-01T13:37:42Z
'
,
'
started_at
'
:
None
,
'
ended_at
'
:
None
,
'
progress
'
:
None
,
'
description
'
:
'
something
'
})
self
.
assertEqual
(
get_queue_mock
.
call_count
,
1
)
self
.
assertEqual
(
get_queue_mock
.
call_args
,
call
(
'
default
'
))
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_count
,
1
)
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_args
,
call
(
'
a/b/c/d
'
))
@patch
(
'
arkindex.users.api.get_queue
'
)
def
test_retrieve_not_found
(
self
,
get_queue_mock
):
get_queue_mock
.
return_value
.
fetch_job
.
return_value
=
None
...
...
@@ -300,3 +328,21 @@ class TestJobs(FixtureAPITestCase):
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_count
,
1
)
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_args
,
call
(
started_job
.
id
))
self
.
assertFalse
(
started_job
.
delete
.
called
)
@patch
(
'
arkindex.users.api.get_queue
'
)
def
test_destroy_custom_id
(
self
,
get_queue_mock
):
"""
Job IDs can be any string, including one with slashes, so we should allow any string in DestroyJob
"""
job
=
MockedJob
(
user_id
=
self
.
user
.
id
,
id
=
'
a/b/c/d
'
)
get_queue_mock
.
return_value
.
fetch_job
.
return_value
=
job
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
2
):
response
=
self
.
client
.
delete
(
reverse
(
'
api:jobs-retrieve
'
,
kwargs
=
{
'
pk
'
:
'
a/b/c/d
'
}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
self
.
assertEqual
(
get_queue_mock
.
call_count
,
1
)
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_count
,
1
)
self
.
assertEqual
(
get_queue_mock
().
fetch_job
.
call_args
,
call
(
'
a/b/c/d
'
))
self
.
assertEqual
(
job
.
delete
.
call_count
,
1
)
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