Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
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
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
6efd4f85
Commit
6efd4f85
authored
7 months ago
by
Karel van Klink
Browse files
Options
Downloads
Patches
Plain Diff
Add MockedKentikClient for unit testing
parent
20ca3ebd
No related branches found
Branches containing commit
Tags
2.26
Tags containing commit
1 merge request
!257
Feature/add kentik workflow
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/services/conftest.py
+60
-0
60 additions, 0 deletions
test/services/conftest.py
test/workflows/router/test_promote_p_to_pe.py
+4
-7
4 additions, 7 deletions
test/workflows/router/test_promote_p_to_pe.py
with
64 additions
and
7 deletions
test/services/conftest.py
+
60
−
0
View file @
6efd4f85
from
typing
import
Any
from
gso.services.kentik_client
import
NewKentikDevice
class
MockedNetboxClient
:
class
BaseMockObject
:
def
__init__
(
self
,
**
kwargs
):
...
...
@@ -57,3 +62,58 @@ class MockedSharePointClient:
@staticmethod
def
add_list_item
(
list_name
:
str
,
fields
:
dict
[
str
,
str
])
->
str
:
return
f
"
http://
{
list_name
}
/
{
fields
.
popitem
()
}
"
class
MockedKentikClient
:
class
BaseMockObject
:
def
__init__
(
self
,
**
kwargs
):
for
key
,
value
in
kwargs
.
items
():
setattr
(
self
,
key
,
value
)
@staticmethod
def
get_devices
()
->
list
[
dict
[
str
,
Any
]]:
return
[{
"
id
"
:
0
,
"
device_name
"
:
"
device-1.internal
"
},
{
"
id
"
:
1
,
"
device_name
"
:
"
device-2.internal
"
}]
@staticmethod
def
get_device
(
device_id
:
str
)
->
dict
[
str
,
Any
]:
return
{
"
id
"
:
device_id
,
"
device_name
"
:
"
device-1.internal
"
}
@staticmethod
def
get_device_by_name
(
fqdn
:
str
)
->
dict
[
str
,
Any
]:
return
{
"
id
"
:
0
,
"
device_name
"
:
fqdn
}
@staticmethod
def
get_sites
()
->
list
[
dict
[
str
,
Any
]]:
return
[{
"
id
"
:
0
,
"
site_name
"
:
"
AMS
"
},
{
"
id
"
:
1
,
"
site_name
"
:
"
BRU
"
},
{
"
id
"
:
2
,
"
site_name
"
:
"
LUX
"
}]
@staticmethod
def
get_site_by_name
(
site_name
:
str
)
->
dict
[
str
,
Any
]:
return
{
"
id
"
:
0
,
"
site_name
"
:
site_name
}
@staticmethod
def
get_plans
()
->
list
[
dict
[
str
,
Any
]]:
return
[{
"
id
"
:
0
,
"
plan_name
"
:
"
kentik-plan-1
"
},
{
"
id
"
:
1
,
"
plan_name
"
:
"
kentik-plan-2
"
}]
@staticmethod
def
get_plan
(
plan_id
:
int
)
->
dict
[
str
,
Any
]:
return
{
"
id
"
:
plan_id
,
"
plan_name
"
:
"
kentik-mocked-plan
"
}
@staticmethod
def
get_plan_by_name
(
plan_name
:
str
)
->
dict
[
str
,
Any
]:
return
{
"
id
"
:
0
,
"
plan_name
"
:
plan_name
}
@staticmethod
def
create_device
(
device
:
NewKentikDevice
)
->
dict
[
str
,
Any
]:
return
device
.
model_dump
()
@staticmethod
def
update_device
(
device_id
:
int
,
updated_device
:
dict
[
str
,
Any
])
->
dict
[
str
,
Any
]:
return
{
"
id
"
:
device_id
,
**
updated_device
}
@staticmethod
def
remove_device
(
device_id
:
int
,
*
,
archive
:
bool
)
->
None
:
pass
@staticmethod
def
remove_device_by_fqdn
(
fqdn
:
str
,
*
,
archive
:
bool
)
->
None
:
pass
This diff is collapsed.
Click to expand it.
test/workflows/router/test_promote_p_to_pe.py
+
4
−
7
View file @
6efd4f85
...
...
@@ -6,6 +6,7 @@ from pydantic_forms.exceptions import FormValidationError
from
gso.products.product_blocks.router
import
RouterRole
from
test
import
USER_CONFIRM_EMPTY_FORM
from
test.services.conftest
import
MockedKentikClient
from
test.workflows
import
(
assert_complete
,
assert_lso_interaction_success
,
...
...
@@ -17,19 +18,16 @@ from test.workflows import (
@pytest.mark.workflow
()
@patch
(
"
gso.workflows.router.promote_p_to_pe.lso_client.execute_playbook
"
)
@patch
(
"
gso.workflows.router.promote_p_to_pe.KentikClient.create_device
"
)
@patch
(
"
gso.workflows.router.promote_p_to_pe.KentikClient.get_site_by_name
"
)
@patch
(
"
gso.workflows.router.promote_p_to_pe.KentikClient
"
)
def
test_promote_p_to_pe_success
(
mock_kentik_create_device
,
mock_kentik_get_site_by_name
,
mock_kentik_client
,
mock_execute_playbook
,
nokia_router_subscription_factory
,
data_config_filename
,
faker
,
):
"""
Test the successful promotion of a Nokia P router to a PE router.
"""
mock_kentik_create_device
.
return_value
=
{
"
id
"
:
faker
.
pyint
()}
mock_kentik_get_site_by_name
.
return_value
=
{
"
id
"
:
faker
.
pyint
()}
mock_kentik_client
.
return_value
=
MockedKentikClient
router_id
=
nokia_router_subscription_factory
(
router_role
=
RouterRole
.
P
,
status
=
SubscriptionLifecycle
.
ACTIVE
)
input_data
=
[{
"
subscription_id
"
:
router_id
},
{
"
tt_number
"
:
faker
.
tt_number
()}]
result
,
process_stat
,
step_log
=
run_workflow
(
"
promote_p_to_pe
"
,
input_data
)
...
...
@@ -41,7 +39,6 @@ def test_promote_p_to_pe_success(
state
=
extract_state
(
result
)
assert_complete
(
result
)
assert
mock_execute_playbook
.
call_count
==
22
assert
mock_kentik_create_device
.
call_count
==
1
assert
state
[
"
subscription
"
][
"
router
"
][
"
router_role
"
]
==
RouterRole
.
PE
...
...
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