Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
72b40ed0
Commit
72b40ed0
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
updated unit tests with new response formats
parent
fe1f8fb6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_job_routes.py
+21
-18
21 additions, 18 deletions
test/test_job_routes.py
with
21 additions
and
18 deletions
test/test_job_routes.py
+
21
−
18
View file @
72b40ed0
...
...
@@ -7,10 +7,14 @@ DEFAULT_REQUEST_HEADERS = {
"
Accept
"
:
[
"
application/json
"
]
}
TASK_ID_
LIST
_SCHEMA
=
{
TASK_ID_
RESPONSE
_SCHEMA
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
string
"
}
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
task id
"
:
{
"
type
"
:
"
string
"
}
},
"
required
"
:
[
"
task id
"
],
"
additionalProperties
"
:
False
}
TASK_STATUS_SCHEMA
=
{
...
...
@@ -22,7 +26,7 @@ TASK_STATUS_SCHEMA = {
"
exception
"
:
{
"
type
"
:
"
boolean
"
},
"
ready
"
:
{
"
type
"
:
"
boolean
"
},
"
success
"
:
{
"
type
"
:
"
boolean
"
},
"
result
"
:
{
"
type
"
:
"
object
"
}
"
result
"
:
{
"
type
"
:
[
"
object
"
,
"
null
"
]
}
},
"
required
"
:
[
"
id
"
,
"
status
"
,
"
exception
"
,
"
ready
"
,
"
success
"
],
"
additionalProperties
"
:
False
...
...
@@ -30,25 +34,25 @@ TASK_STATUS_SCHEMA = {
def
test_job_update_all
(
client
,
mocker
):
expected_task_id
s
=
[
'
abc
'
,
'
def
'
,
'
xyz@123#456
'
]
expected_task_id
=
'
xyz@123#456
'
launch_refresh_cache_all
=
mocker
.
patch
(
'
inventory_provider.tasks.worker.launch_refresh_cache_all
'
)
launch_refresh_cache_all
.
return_value
=
expected_task_id
s
launch_refresh_cache_all
.
return_value
=
expected_task_id
rv
=
client
.
post
(
'
jobs/update
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
task_id_list
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
task_id_list
,
TASK_ID_
LIST
_SCHEMA
)
assert
set
(
task
_
id
_list
)
==
set
(
expected_task_id
s
)
refresh_task_response
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
refresh_task_response
,
TASK_ID_
RESPONSE
_SCHEMA
)
assert
refresh_task_response
[
'
task
id
'
]
==
expected_task_id
def
test_job_update_force_pending
(
client
,
mocker
):
expected_task_id
s
=
[
'
22
'
,
'
agfafg
'
,
'
asf#asdf%111
'
,
'
234
'
]
expected_task_id
=
'
asf#asdf%111
'
launch_refresh_cache_all
=
mocker
.
patch
(
'
inventory_provider.tasks.worker.launch_refresh_cache_all
'
)
launch_refresh_cache_all
.
return_value
=
expected_task_id
s
launch_refresh_cache_all
.
return_value
=
expected_task_id
mocked_get_latch
=
mocker
.
patch
(
'
inventory_provider.routes.jobs.get_latch
'
)
...
...
@@ -58,9 +62,9 @@ def test_job_update_force_pending(client, mocker):
'
jobs/update?force=true
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
task_id_list
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
task_id_list
,
TASK_ID_
LIST
_SCHEMA
)
assert
set
(
task
_
id
_list
)
==
set
(
expected_task_id
s
)
refresh_task_response
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
refresh_task_response
,
TASK_ID_
RESPONSE
_SCHEMA
)
assert
refresh_task_response
[
'
task
id
'
]
==
expected_task_id
def
test_job_update_pending_force_false
(
client
,
mocker
):
...
...
@@ -114,9 +118,9 @@ def test_reload_router_config(client, mocker):
'
jobs/reload-router-config/ignored###123
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
task_id_list
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
task_id_list
,
TASK_ID_
LIST
_SCHEMA
)
assert
task_id_list
==
[
'
bogus task id
'
]
refresh_task_response
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
refresh_task_response
,
TASK_ID_
RESPONSE
_SCHEMA
)
assert
refresh_task_response
[
'
task id
'
]
==
'
bogus task id
'
def
test_check_task_status_success
(
client
,
mocker
):
...
...
@@ -156,7 +160,6 @@ def test_check_task_status_custom_status(client, mocker):
assert
not
status
[
'
exception
'
]
assert
not
status
[
'
ready
'
]
assert
not
status
[
'
success
'
]
assert
'
result
'
not
in
status
def
test_check_task_status_exception
(
client
,
mocker
):
...
...
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