Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LSO
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
LSO
Commits
87a58ef4
Verified
Commit
87a58ef4
authored
1 year ago
by
Karel van Klink
Browse files
Options
Downloads
Patches
Plain Diff
update unit test cases to expect JSON responses
parent
b46fd0d5
No related branches found
No related tags found
No related merge requests found
Pipeline
#84800
failed
1 year ago
Stage: tox
Stage: documentation
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lso/playbook.py
+1
-1
1 addition, 1 deletion
lso/playbook.py
test/routes/test_ip_trunk.py
+14
-21
14 additions, 21 deletions
test/routes/test_ip_trunk.py
test/routes/test_router.py
+4
-8
4 additions, 8 deletions
test/routes/test_router.py
with
19 additions
and
30 deletions
lso/playbook.py
+
1
−
1
View file @
87a58ef4
...
@@ -147,7 +147,7 @@ def _run_playbook_proc(
...
@@ -147,7 +147,7 @@ def _run_playbook_proc(
}
}
request_result
=
requests
.
post
(
callback
,
json
=
payload
,
timeout
=
DEFAULT_REQUEST_TIMEOUT
)
request_result
=
requests
.
post
(
callback
,
json
=
payload
,
timeout
=
DEFAULT_REQUEST_TIMEOUT
)
if
request_result
.
status_code
!=
status
.
HTTP_20
0_OK
:
if
request_result
.
status_code
!=
status
.
HTTP_20
1_CREATED
:
msg
=
f
"
Callback failed:
{
request_result
.
text
}
"
msg
=
f
"
Callback failed:
{
request_result
.
text
}
"
logger
.
error
(
msg
)
logger
.
error
(
msg
)
...
...
This diff is collapsed.
Click to expand it.
test/routes/test_ip_trunk.py
+
14
−
21
View file @
87a58ef4
...
@@ -2,15 +2,12 @@ import time
...
@@ -2,15 +2,12 @@ import time
from
collections.abc
import
Callable
from
collections.abc
import
Callable
from
unittest.mock
import
patch
from
unittest.mock
import
patch
import
jsonschema
import
pytest
import
pytest
import
responses
import
responses
from
faker
import
Faker
from
faker
import
Faker
from
fastapi
import
status
from
fastapi
import
status
from
starlette.testclient
import
TestClient
from
starlette.testclient
import
TestClient
from
lso.playbook
import
PlaybookLaunchResponse
TEST_CALLBACK_URL
=
"
https://fqdn.abc.xyz/api/resume
"
TEST_CALLBACK_URL
=
"
https://fqdn.abc.xyz/api/resume
"
...
@@ -171,7 +168,7 @@ def test_ip_trunk_provisioning(
...
@@ -171,7 +168,7 @@ def test_ip_trunk_provisioning(
subscription_object
:
dict
,
subscription_object
:
dict
,
mocked_ansible_runner_run
:
Callable
,
mocked_ansible_runner_run
:
Callable
,
)
->
None
:
)
->
None
:
responses
.
post
(
url
=
TEST_CALLBACK_URL
,
status
=
20
0
)
responses
.
post
(
url
=
TEST_CALLBACK_URL
,
status
=
20
1
)
params
=
{
params
=
{
"
callback
"
:
TEST_CALLBACK_URL
,
"
callback
"
:
TEST_CALLBACK_URL
,
...
@@ -185,16 +182,15 @@ def test_ip_trunk_provisioning(
...
@@ -185,16 +182,15 @@ def test_ip_trunk_provisioning(
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
rv
=
client
.
post
(
"
/api/ip_trunk/
"
,
json
=
params
)
rv
=
client
.
post
(
"
/api/ip_trunk/
"
,
json
=
params
)
assert
rv
.
status_code
==
status
.
HTTP_20
0_OK
assert
rv
.
status_code
==
status
.
HTTP_20
1_CREATED
response
=
rv
.
json
()
response
=
rv
.
json
()
# wait a second for the run thread to finish
# wait a second for the run thread to finish
time
.
sleep
(
1
)
time
.
sleep
(
1
)
jsonschema
.
validate
(
response
,
PlaybookLaunchResponse
.
model_json_schema
())
assert
isinstance
(
response
,
dict
)
assert
isinstance
(
response
[
"
job_id
"
],
str
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
assert
response
[
"
status
"
]
==
"
ok
"
@responses.activate
@responses.activate
def
test_ip_trunk_modification
(
def
test_ip_trunk_modification
(
...
@@ -202,7 +198,7 @@ def test_ip_trunk_modification(
...
@@ -202,7 +198,7 @@ def test_ip_trunk_modification(
subscription_object
:
dict
,
subscription_object
:
dict
,
mocked_ansible_runner_run
:
Callable
,
mocked_ansible_runner_run
:
Callable
,
)
->
None
:
)
->
None
:
responses
.
post
(
url
=
TEST_CALLBACK_URL
,
status
=
20
0
)
responses
.
post
(
url
=
TEST_CALLBACK_URL
,
status
=
20
1
)
params
=
{
params
=
{
"
callback
"
:
TEST_CALLBACK_URL
,
"
callback
"
:
TEST_CALLBACK_URL
,
...
@@ -216,16 +212,15 @@ def test_ip_trunk_modification(
...
@@ -216,16 +212,15 @@ def test_ip_trunk_modification(
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
rv
=
client
.
put
(
"
/api/ip_trunk/
"
,
json
=
params
)
rv
=
client
.
put
(
"
/api/ip_trunk/
"
,
json
=
params
)
assert
rv
.
status_code
==
status
.
HTTP_20
0_OK
assert
rv
.
status_code
==
status
.
HTTP_20
1_CREATED
response
=
rv
.
json
()
response
=
rv
.
json
()
# wait a second for the run thread to finish
# wait a second for the run thread to finish
time
.
sleep
(
1
)
time
.
sleep
(
1
)
jsonschema
.
validate
(
response
,
PlaybookLaunchResponse
.
model_json_schema
())
assert
isinstance
(
response
,
dict
)
assert
isinstance
(
response
[
"
job_id
"
],
str
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
assert
response
[
"
status
"
]
==
"
ok
"
@responses.activate
@responses.activate
def
test_ip_trunk_deletion
(
client
:
TestClient
,
subscription_object
:
dict
,
mocked_ansible_runner_run
:
Callable
)
->
None
:
def
test_ip_trunk_deletion
(
client
:
TestClient
,
subscription_object
:
dict
,
mocked_ansible_runner_run
:
Callable
)
->
None
:
...
@@ -242,16 +237,15 @@ def test_ip_trunk_deletion(client: TestClient, subscription_object: dict, mocked
...
@@ -242,16 +237,15 @@ def test_ip_trunk_deletion(client: TestClient, subscription_object: dict, mocked
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
rv
=
client
.
request
(
url
=
"
/api/ip_trunk/
"
,
method
=
responses
.
DELETE
,
json
=
params
)
rv
=
client
.
request
(
url
=
"
/api/ip_trunk/
"
,
method
=
responses
.
DELETE
,
json
=
params
)
assert
rv
.
status_code
==
status
.
HTTP_20
0_OK
assert
rv
.
status_code
==
status
.
HTTP_20
1_CREATED
response
=
rv
.
json
()
response
=
rv
.
json
()
# wait a second for the run thread to finish
# wait a second for the run thread to finish
time
.
sleep
(
1
)
time
.
sleep
(
1
)
jsonschema
.
validate
(
response
,
PlaybookLaunchResponse
.
model_json_schema
())
assert
isinstance
(
response
,
dict
)
assert
isinstance
(
response
[
"
job_id
"
],
str
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
assert
response
[
"
status
"
]
==
"
ok
"
@responses.activate
@responses.activate
def
test_ip_trunk_migration
(
def
test_ip_trunk_migration
(
...
@@ -275,12 +269,11 @@ def test_ip_trunk_migration(
...
@@ -275,12 +269,11 @@ def test_ip_trunk_migration(
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
rv
=
client
.
post
(
url
=
"
/api/ip_trunk/migrate
"
,
json
=
params
)
rv
=
client
.
post
(
url
=
"
/api/ip_trunk/migrate
"
,
json
=
params
)
assert
rv
.
status_code
==
status
.
HTTP_20
0_OK
assert
rv
.
status_code
==
status
.
HTTP_20
1_CREATED
response
=
rv
.
json
()
response
=
rv
.
json
()
# Wait a second for the run to finish
# Wait a second for the run to finish
time
.
sleep
(
1
)
time
.
sleep
(
1
)
jsonschema
.
validate
(
response
,
PlaybookLaunchResponse
.
model_json_schema
())
assert
isinstance
(
response
,
dict
)
assert
isinstance
(
response
[
"
job_id
"
],
str
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
assert
response
[
"
status
"
]
==
"
ok
"
This diff is collapsed.
Click to expand it.
test/routes/test_router.py
+
4
−
8
View file @
87a58ef4
...
@@ -2,20 +2,17 @@ import time
...
@@ -2,20 +2,17 @@ import time
from
collections.abc
import
Callable
from
collections.abc
import
Callable
from
unittest.mock
import
patch
from
unittest.mock
import
patch
import
jsonschema
import
responses
import
responses
from
faker
import
Faker
from
faker
import
Faker
from
fastapi
import
status
from
fastapi
import
status
from
starlette.testclient
import
TestClient
from
starlette.testclient
import
TestClient
from
lso.playbook
import
PlaybookLaunchResponse
TEST_CALLBACK_URL
=
"
https://fqdn.abc.xyz/api/resume
"
TEST_CALLBACK_URL
=
"
https://fqdn.abc.xyz/api/resume
"
@responses.activate
@responses.activate
def
test_router_provisioning
(
client
:
TestClient
,
faker
:
Faker
,
mocked_ansible_runner_run
:
Callable
)
->
None
:
def
test_router_provisioning
(
client
:
TestClient
,
faker
:
Faker
,
mocked_ansible_runner_run
:
Callable
)
->
None
:
responses
.
put
(
url
=
TEST_CALLBACK_URL
,
status
=
20
0
)
responses
.
put
(
url
=
TEST_CALLBACK_URL
,
status
=
20
1
)
params
=
{
params
=
{
"
callback
"
:
TEST_CALLBACK_URL
,
"
callback
"
:
TEST_CALLBACK_URL
,
...
@@ -48,12 +45,11 @@ def test_router_provisioning(client: TestClient, faker: Faker, mocked_ansible_ru
...
@@ -48,12 +45,11 @@ def test_router_provisioning(client: TestClient, faker: Faker, mocked_ansible_ru
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
with
patch
(
"
lso.playbook.ansible_runner.run
"
,
new
=
mocked_ansible_runner_run
)
as
_
:
rv
=
client
.
post
(
"
/api/router/
"
,
json
=
params
)
rv
=
client
.
post
(
"
/api/router/
"
,
json
=
params
)
assert
rv
.
status_code
==
status
.
HTTP_20
0_OK
assert
rv
.
status_code
==
status
.
HTTP_20
1_CREATED
response
=
rv
.
json
()
response
=
rv
.
json
()
# wait two seconds for the run thread to finish
# wait two seconds for the run thread to finish
time
.
sleep
(
2
)
time
.
sleep
(
2
)
jsonschema
.
validate
(
response
,
PlaybookLaunchResponse
.
model_json_schema
())
assert
isinstance
(
response
,
dict
)
assert
isinstance
(
response
[
"
job_id
"
],
str
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
responses
.
assert_call_count
(
TEST_CALLBACK_URL
,
1
)
assert
response
[
"
status
"
]
==
"
ok
"
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