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
437ef774
Commit
437ef774
authored
1 year ago
by
Hakan Calim
Browse files
Options
Downloads
Patches
Plain Diff
NAT-286: added attach interface to lag test
parent
354e314d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!89
Feature/nat 286 create unit tests for netbox client
Pipeline
#84266
failed
1 year ago
Stage: tox
Stage: documentation
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/services/test_netbox.py
+43
-0
43 additions, 0 deletions
test/services/test_netbox.py
with
43 additions
and
0 deletions
test/services/test_netbox.py
+
43
−
0
View file @
437ef774
...
@@ -64,6 +64,16 @@ def interface():
...
@@ -64,6 +64,16 @@ def interface():
return
Record
(
values
,
None
,
None
)
return
Record
(
values
,
None
,
None
)
@pytest.fixture
(
scope
=
"
module
"
)
def
lag
():
values
=
{
"
id
"
:
1
,
"
name
"
:
"
lag-1
"
,
"
type
"
:
"
lag
"
,
}
return
Record
(
values
,
None
,
None
)
@patch
(
"
gso.services.netbox_client.pynetbox.api
"
)
@patch
(
"
gso.services.netbox_client.pynetbox.api
"
)
def
test_create_device
(
def
test_create_device
(
mock_api
,
device
,
device_type
,
device_role
,
site
,
device_bay
,
card_type
,
data_config_filename
:
PathLike
mock_api
,
device
,
device_type
,
device_role
,
site
,
device_bay
,
card_type
,
data_config_filename
:
PathLike
...
@@ -255,3 +265,36 @@ def test_get_interfaces_by_device(mock_api, device, interface, data_config_filen
...
@@ -255,3 +265,36 @@ def test_get_interfaces_by_device(mock_api, device, interface, data_config_filen
assert
interfaces
is
not
None
assert
interfaces
is
not
None
assert
len
(
interfaces
)
==
2
assert
len
(
interfaces
)
==
2
@patch
(
"
gso.services.netbox_client.pynetbox.api
"
)
def
test_attach_interface_to_lag
(
mock_api
,
device
,
interface
,
lag
,
data_config_filename
:
PathLike
):
"""
Test if a interface is attached correctly to a lag interface
"""
# Define site effect function
def
get_side_effect
(
**
kwargs
):
if
kwargs
.
get
(
"
device_id
"
)
==
1
and
kwargs
.
get
(
"
name
"
)
==
"
lag-1
"
:
return
lag
return
interface
# Define a description
description
=
"
test123
"
# Mock netbox api
mock_api
.
return_value
.
dcim
.
devices
.
get
.
return_value
=
device
mock_api
.
return_value
.
dcim
.
interfaces
.
get
.
side_effect
=
get_side_effect
# mock save method
mock_save
=
Mock
()
mock_save
.
save
.
return_value
=
interface
interface
.
save
=
mock_save
# Check if interface attached to lag
lag_interface
=
NetboxClient
().
attach_interface_to_lag
(
device
.
name
,
lag
.
name
,
interface
.
name
,
description
)
assert
lag_interface
is
not
None
assert
lag_interface
.
lag
==
lag
.
id
assert
lag_interface
.
description
==
description
mock_save
.
assert_called_once
()
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