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
55f8492a
Commit
55f8492a
authored
2 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix handling of unknown user IDs and user emails in UserArgument
parent
f12736fa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1921
Fix handling of unknown user IDs and user emails in UserArgument
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/process/tests/commands/test_fake_worker_run.py
+29
-0
29 additions, 0 deletions
arkindex/process/tests/commands/test_fake_worker_run.py
arkindex/project/argparse.py
+3
-1
3 additions, 1 deletion
arkindex/project/argparse.py
with
32 additions
and
1 deletion
arkindex/process/tests/commands/test_fake_worker_run.py
+
29
−
0
View file @
55f8492a
...
...
@@ -6,6 +6,7 @@ from django.core.management.base import CommandError
from
arkindex.process.models
import
Process
,
ProcessMode
,
WorkerVersion
from
arkindex.project.tests
import
FixtureTestCase
from
arkindex.users.models
import
User
class
TestFakeWorkerRun
(
FixtureTestCase
):
...
...
@@ -83,3 +84,31 @@ class TestFakeWorkerRun(FixtureTestCase):
self
.
fake_worker_run
([
'
--user
'
,
str
(
self
.
user
.
id
),
'
--worker-version
'
,
str
(
worker_version_id
)])
self
.
assertEqual
(
str
(
ctx
.
exception
),
'
WorkerVersion
"
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
"
does not exist
'
)
def
test_unknown_user
(
self
):
user_id
=
12345
self
.
assertFalse
(
User
.
objects
.
filter
(
id
=
user_id
).
exists
())
with
self
.
assertRaises
(
CommandError
)
as
ctx
:
self
.
fake_worker_run
([
'
--user
'
,
str
(
user_id
),
'
--worker-version
'
,
str
(
self
.
worker_version
.
id
)])
self
.
assertEqual
(
str
(
ctx
.
exception
),
'
User
"
12345
"
does not exist
'
)
def
test_email
(
self
):
self
.
assertFalse
(
Process
.
objects
.
filter
(
mode
=
ProcessMode
.
Local
,
creator
=
self
.
user
).
exists
())
output
=
self
.
fake_worker_run
([
'
--user
'
,
str
(
self
.
user
.
email
),
'
--worker-version
'
,
str
(
self
.
worker_version
.
id
)])
process
=
Process
.
objects
.
get
(
mode
=
ProcessMode
.
Local
,
creator
=
self
.
user
)
worker_run
=
process
.
worker_runs
.
get
()
self
.
assertEqual
(
worker_run
.
version
,
self
.
worker_version
)
self
.
assertIsNone
(
worker_run
.
configuration_id
)
self
.
assertIsNone
(
worker_run
.
model_version_id
)
self
.
assertListEqual
(
worker_run
.
parents
,
[])
self
.
assertEqual
(
output
,
dedent
(
f
"""
Created local process
{
process
.
id
}
Created WorkerRun
{
worker_run
.
id
}
(Worker Recognizer @ 6bdc26)
"""
).
strip
())
This diff is collapsed.
Click to expand it.
arkindex/project/argparse.py
+
3
−
1
View file @
55f8492a
...
...
@@ -10,6 +10,7 @@ from arkindex.users.models import User
class
ModelArgument
(
object
):
model
=
None
text_search_field
=
'
name
'
text_search_lookup
=
'
icontains
'
def
__init__
(
self
,
many
=
False
,
**
filters
):
assert
issubclass
(
self
.
model
,
Model
)
...
...
@@ -33,7 +34,7 @@ class ModelArgument(object):
def
text_search
(
self
,
qs
,
arg
):
if
not
self
.
text_search_field
:
raise
self
.
model
.
DoesNotExist
text_filter
=
{
'
{
}__icontains
'
.
format
(
self
.
text_search_field
)
:
arg
}
text_filter
=
{
f
'
{
self
.
text_search_field
}
__
{
self
.
text_search_lookup
}
'
:
arg
}
if
self
.
many
:
return
qs
.
filter
(
**
text_filter
)
else
:
...
...
@@ -61,6 +62,7 @@ class RepositoryArgument(ModelArgument):
class
UserArgument
(
ModelArgument
):
model
=
User
text_search_field
=
'
email
'
text_search_lookup
=
'
exact
'
class
WorkerVersionArgument
(
ModelArgument
):
...
...
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