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
d707bbca
Commit
d707bbca
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added jobs/check-update-status tests
parent
4ca49774
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
+94
-35
94 additions, 35 deletions
test/test_job_routes.py
with
94 additions
and
35 deletions
test/test_job_routes.py
+
94
−
35
View file @
d707bbca
import
json
import
jsonschema
from
inventory_provider.tasks.common
import
DB_LATCH_SCHEMA
from
inventory_provider.tasks.common
import
_get_redis
,
DB_LATCH_SCHEMA
DEFAULT_REQUEST_HEADERS
=
{
"
Content-type
"
:
"
application/json
"
,
"
Accept
"
:
[
"
application/json
"
]
...
...
@@ -19,20 +20,39 @@ TASK_ID_RESPONSE_SCHEMA = {
TASK_STATUS_SCHEMA
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
id
"
:
{
"
type
"
:
"
string
"
},
"
status
"
:
{
"
type
"
:
"
string
"
},
"
exception
"
:
{
"
type
"
:
"
boolean
"
},
"
ready
"
:
{
"
type
"
:
"
boolean
"
},
"
success
"
:
{
"
type
"
:
"
boolean
"
},
"
result
"
:
{
"
type
"
:
[
"
object
"
,
"
null
"
]}
"
definitions
"
:
{
"
task
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
id
"
:
{
"
type
"
:
"
string
"
},
"
status
"
:
{
"
type
"
:
"
string
"
},
"
exception
"
:
{
"
type
"
:
"
boolean
"
},
"
ready
"
:
{
"
type
"
:
"
boolean
"
},
"
success
"
:
{
"
type
"
:
"
boolean
"
},
"
result
"
:
{
"
type
"
:
[
"
object
"
,
"
null
"
]},
"
parent
"
:
{
"
type
"
:
[
"
string
"
,
"
null
"
]}
},
"
required
"
:
[
"
id
"
,
"
status
"
,
"
exception
"
,
"
ready
"
,
"
success
"
,
"
parent
"
],
"
additionalProperties
"
:
False
}
},
"
required
"
:
[
"
id
"
,
"
status
"
,
"
exception
"
,
"
ready
"
,
"
success
"
],
"
additionalProperties
"
:
False
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/task
"
}
}
def
backend_db
():
return
_get_redis
({
'
redis
'
:
{
'
hostname
'
:
None
,
'
port
'
:
None
},
'
redis-databases
'
:
[
0
,
7
]
}).
db
def
test_job_update_all
(
client
,
mocker
):
expected_task_id
=
'
xyz@123#456
'
launch_refresh_cache_all
=
mocker
.
patch
(
...
...
@@ -123,6 +143,42 @@ def test_reload_router_config(client, mocker):
assert
refresh_task_response
[
'
task id
'
]
==
'
bogus task id
'
def
test_check_update_status
(
client
,
mocker
):
db
=
backend_db
()
db
[
'
classifier-cache:update-task-id
'
]
=
'
zz55
'
mocker
.
patch
(
'
inventory_provider.tasks.worker.AsyncResult
'
,
MockedAsyncResult
)
MockedAsyncResult
.
status
=
'
SUCCESS
'
# celery.states.SUCCESS
MockedAsyncResult
.
result
=
{
'
absab
'
:
1
,
'
def
'
:
'
aaabbb
'
}
rv
=
client
.
post
(
'
jobs/check-update-status
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
result
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
result
,
TASK_STATUS_SCHEMA
)
for
status
in
result
:
assert
status
[
'
id
'
]
==
'
zz55
'
assert
status
[
'
status
'
]
==
'
SUCCESS
'
assert
not
status
[
'
exception
'
]
assert
status
[
'
ready
'
]
assert
status
[
'
success
'
]
assert
'
result
'
in
status
def
test_check_update_status_404
(
client
):
db
=
backend_db
()
db
.
pop
(
'
classifier-cache:update-task-id
'
,
None
)
rv
=
client
.
post
(
'
jobs/check-update-status
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
404
def
test_check_task_status_success
(
client
,
mocker
):
mocker
.
patch
(
'
inventory_provider.tasks.worker.AsyncResult
'
,
MockedAsyncResult
)
...
...
@@ -133,14 +189,15 @@ def test_check_task_status_success(client, mocker):
'
jobs/check-task-status/abc
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
status
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
status
,
TASK_STATUS_SCHEMA
)
assert
status
[
'
id
'
]
==
'
abc
'
assert
status
[
'
status
'
]
==
'
SUCCESS
'
assert
not
status
[
'
exception
'
]
assert
status
[
'
ready
'
]
assert
status
[
'
success
'
]
assert
'
result
'
in
status
result
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
result
,
TASK_STATUS_SCHEMA
)
for
status
in
result
:
assert
status
[
'
id
'
]
==
'
abc
'
assert
status
[
'
status
'
]
==
'
SUCCESS
'
assert
not
status
[
'
exception
'
]
assert
status
[
'
ready
'
]
assert
status
[
'
success
'
]
assert
'
result
'
in
status
def
test_check_task_status_custom_status
(
client
,
mocker
):
...
...
@@ -153,13 +210,14 @@ def test_check_task_status_custom_status(client, mocker):
'
jobs/check-task-status/xyz
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
status
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
status
,
TASK_STATUS_SCHEMA
)
assert
status
[
'
id
'
]
==
'
xyz
'
assert
status
[
'
status
'
]
==
'
custom
'
assert
not
status
[
'
exception
'
]
assert
not
status
[
'
ready
'
]
assert
not
status
[
'
success
'
]
result
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
result
,
TASK_STATUS_SCHEMA
)
for
status
in
result
:
assert
status
[
'
id
'
]
==
'
xyz
'
assert
status
[
'
status
'
]
==
'
custom
'
assert
not
status
[
'
exception
'
]
assert
not
status
[
'
ready
'
]
assert
not
status
[
'
success
'
]
def
test_check_task_status_exception
(
client
,
mocker
):
...
...
@@ -172,15 +230,16 @@ def test_check_task_status_exception(client, mocker):
'
jobs/check-task-status/123-xyz.ABC
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
status
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
status
,
TASK_STATUS_SCHEMA
)
assert
status
[
'
id
'
]
==
'
123-xyz.ABC
'
assert
status
[
'
status
'
]
==
'
FAILURE
'
assert
status
[
'
exception
'
]
assert
status
[
'
ready
'
]
assert
not
status
[
'
success
'
]
assert
status
[
'
result
'
][
'
error type
'
]
==
'
AssertionError
'
assert
status
[
'
result
'
][
'
message
'
]
==
'
test error message
'
result
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
result
,
TASK_STATUS_SCHEMA
)
for
status
in
result
:
assert
status
[
'
id
'
]
==
'
123-xyz.ABC
'
assert
status
[
'
status
'
]
==
'
FAILURE
'
assert
status
[
'
exception
'
]
assert
status
[
'
ready
'
]
assert
not
status
[
'
success
'
]
assert
status
[
'
result
'
][
'
error type
'
]
==
'
AssertionError
'
assert
status
[
'
result
'
][
'
message
'
]
==
'
test error message
'
def
test_latchdb
(
client
,
mocked_redis
):
...
...
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