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
Jira
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
f24c098e
Commit
f24c098e
authored
9 months ago
by
Karel van Klink
Committed by
Neda Moeini
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Update LibreNMS unit tests
parent
f759a865
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!253
LibreNMS retries
Pipeline
#88383
passed
9 months ago
Stage: tox
Stage: documentation
Stage: sonarqube
Stage: trigger_jenkins_build
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/services/test_librenms_client.py
+19
-19
19 additions, 19 deletions
test/services/test_librenms_client.py
with
19 additions
and
19 deletions
test/services/test_librenms_client.py
+
19
−
19
View file @
f24c098e
...
@@ -10,7 +10,7 @@ from gso.utils.helpers import SNMPVersion
...
@@ -10,7 +10,7 @@ from gso.utils.helpers import SNMPVersion
@pytest.fixture
()
@pytest.fixture
()
def
mock_get_device_success
(
faker
):
def
mock_get_device_success
(
faker
):
with
patch
(
"
gso.services.librenms_client.reques
ts.ge
t
"
)
as
mock_get_device
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_
request
"
)
as
mock_get_device
:
mock_get_device
().
status_code
=
HTTPStatus
.
OK
mock_get_device
().
status_code
=
HTTPStatus
.
OK
mock_get_device
().
json
.
return_value
=
{
mock_get_device
().
json
.
return_value
=
{
"
status
"
:
"
ok
"
,
"
status
"
:
"
ok
"
,
...
@@ -81,14 +81,14 @@ def mock_get_device_success(faker):
...
@@ -81,14 +81,14 @@ def mock_get_device_success(faker):
@pytest.fixture
()
@pytest.fixture
()
def
mock_get_device_not_found
():
def
mock_get_device_not_found
():
with
patch
(
"
gso.services.librenms_client.reques
ts.ge
t
"
)
as
mock_get_not_found
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_
request
"
)
as
mock_get_not_found
:
mock_get_not_found
().
status_code
=
HTTPStatus
.
NOT_FOUND
mock_get_not_found
().
status_code
=
HTTPStatus
.
NOT_FOUND
mock_get_not_found
().
json
.
return_value
=
{
mock_get_not_found
().
json
.
return_value
=
{
"
status
"
:
"
error
"
,
"
status
"
:
"
error
"
,
"
message
"
:
"
Device non-existent-url does not exist
"
,
"
message
"
:
"
Device non-existent-url does not exist
"
,
}
}
mock_get_not_found
().
raise_for_status
.
side_effect
=
HTTPError
(
mock_get_not_found
().
raise_for_status
.
side_effect
=
HTTPError
(
"
404 Client Error: Not Found for url: http://librenms/devices/non-existent-url
"
,
"
404 Client Error: Not Found for url: http
s
://librenms/devices/non-existent-url
"
,
response
=
mock_get_not_found
(),
response
=
mock_get_not_found
(),
)
)
...
@@ -97,7 +97,7 @@ def mock_get_device_not_found():
...
@@ -97,7 +97,7 @@ def mock_get_device_not_found():
@pytest.fixture
()
@pytest.fixture
()
def
mock_get_device_misconfigured
(
faker
):
def
mock_get_device_misconfigured
(
faker
):
with
patch
(
"
gso.services.librenms_client.reques
ts.ge
t
"
)
as
mock_get_device
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_
request
"
)
as
mock_get_device
:
mock_get_device
().
status_code
=
HTTPStatus
.
OK
mock_get_device
().
status_code
=
HTTPStatus
.
OK
mock_get_device
().
json
.
return_value
=
{
mock_get_device
().
json
.
return_value
=
{
"
status
"
:
"
ok
"
,
"
status
"
:
"
ok
"
,
...
@@ -169,7 +169,7 @@ def mock_get_device_misconfigured(faker):
...
@@ -169,7 +169,7 @@ def mock_get_device_misconfigured(faker):
@pytest.fixture
()
@pytest.fixture
()
def
mock_get_device_unauthenticated
():
def
mock_get_device_unauthenticated
():
with
(
with
(
patch
(
"
gso.services.librenms_client.reques
ts.ge
t
"
)
as
mock_get_unauthorized
,
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_
request
"
)
as
mock_get_unauthorized
,
patch
(
patch
(
"
gso.services.librenms_client.LibreNMSClient.get_device
"
,
"
gso.services.librenms_client.LibreNMSClient.get_device
"
,
)
as
mock_get_device
,
)
as
mock_get_device
,
...
@@ -177,7 +177,7 @@ def mock_get_device_unauthenticated():
...
@@ -177,7 +177,7 @@ def mock_get_device_unauthenticated():
mock_get_unauthorized
().
status_code
=
HTTPStatus
.
UNAUTHORIZED
mock_get_unauthorized
().
status_code
=
HTTPStatus
.
UNAUTHORIZED
mock_get_unauthorized
().
json
.
return_value
=
{
"
message
"
:
"
Unauthenticated.
"
}
mock_get_unauthorized
().
json
.
return_value
=
{
"
message
"
:
"
Unauthenticated.
"
}
mock_get_device
.
side_effect
=
HTTPError
(
mock_get_device
.
side_effect
=
HTTPError
(
"
401 Client Error: Unauthorized for url: http://librenms/devices/naughty-url
"
,
"
401 Client Error: Unauthorized for url: http
s
://librenms/devices/naughty-url
"
,
response
=
mock_get_unauthorized
(),
response
=
mock_get_unauthorized
(),
)
)
...
@@ -186,7 +186,7 @@ def mock_get_device_unauthenticated():
...
@@ -186,7 +186,7 @@ def mock_get_device_unauthenticated():
@pytest.fixture
()
@pytest.fixture
()
def
mock_add_device_success
():
def
mock_add_device_success
():
with
patch
(
"
gso.services.librenms_client.
requests.po
st
"
)
as
mock_post_device
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_reque
st
"
)
as
mock_post_device
:
mock_post_device
().
status_code
=
HTTPStatus
.
OK
mock_post_device
().
status_code
=
HTTPStatus
.
OK
mock_post_device
().
json
.
return_value
=
{
mock_post_device
().
json
.
return_value
=
{
"
status
"
:
"
ok
"
,
"
status
"
:
"
ok
"
,
...
@@ -222,14 +222,14 @@ def mock_add_device_success():
...
@@ -222,14 +222,14 @@ def mock_add_device_success():
@pytest.fixture
()
@pytest.fixture
()
def
mock_add_device_bad_url
():
def
mock_add_device_bad_url
():
with
patch
(
"
gso.services.librenms_client.
requests.po
st
"
)
as
mock_post_device
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_reque
st
"
)
as
mock_post_device
:
mock_post_device
().
status_code
=
HTTPStatus
.
INTERNAL_SERVER_ERROR
mock_post_device
().
status_code
=
HTTPStatus
.
INTERNAL_SERVER_ERROR
mock_post_device
().
json
.
return_value
=
{
mock_post_device
().
json
.
return_value
=
{
"
status
"
:
"
error
"
,
"
status
"
:
"
error
"
,
"
message
"
:
"
Could not ping non-existent-url (Hostname did not resolve to IP)
"
,
"
message
"
:
"
Could not ping non-existent-url (Hostname did not resolve to IP)
"
,
}
}
mock_post_device
().
raise_for_status
.
side_effect
=
HTTPError
(
mock_post_device
().
raise_for_status
.
side_effect
=
HTTPError
(
"
500 Server Error: Internal server error for url: http://librenms/devices
"
,
"
500 Server Error: Internal server error for url: http
s
://librenms/devices
"
,
response
=
mock_post_device
(),
response
=
mock_post_device
(),
)
)
...
@@ -238,14 +238,14 @@ def mock_add_device_bad_url():
...
@@ -238,14 +238,14 @@ def mock_add_device_bad_url():
@pytest.fixture
()
@pytest.fixture
()
def
mock_add_device_unreachable
():
def
mock_add_device_unreachable
():
with
patch
(
"
gso.services.librenms_client.
requests.po
st
"
)
as
mock_post_device
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_reque
st
"
)
as
mock_post_device
:
mock_post_device
().
status_code
=
HTTPStatus
.
INTERNAL_SERVER_ERROR
mock_post_device
().
status_code
=
HTTPStatus
.
INTERNAL_SERVER_ERROR
mock_post_device
().
json
.
return_value
=
{
mock_post_device
().
json
.
return_value
=
{
"
status
"
:
"
error
"
,
"
status
"
:
"
error
"
,
"
message
"
:
"
Could not connect to non-existent-url, please check the snmp details and snmp reachability
"
,
"
message
"
:
"
Could not connect to non-existent-url, please check the snmp details and snmp reachability
"
,
}
}
mock_post_device
().
raise_for_status
.
side_effect
=
HTTPError
(
mock_post_device
().
raise_for_status
.
side_effect
=
HTTPError
(
"
500 Server Error: Internal server error for url: http://librenms/devices
"
,
"
500 Server Error: Internal server error for url: http
s
://librenms/devices
"
,
response
=
mock_post_device
(),
response
=
mock_post_device
(),
)
)
...
@@ -254,7 +254,7 @@ def mock_add_device_unreachable():
...
@@ -254,7 +254,7 @@ def mock_add_device_unreachable():
@pytest.fixture
()
@pytest.fixture
()
def
mock_remove_device_success
(
faker
):
def
mock_remove_device_success
(
faker
):
with
patch
(
"
gso.services.librenms_client.
requests.delete
"
)
as
mock_remove_device
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_request
"
)
as
mock_remove_device
:
mock_remove_device
().
status_code
=
HTTPStatus
.
OK
mock_remove_device
().
status_code
=
HTTPStatus
.
OK
mock_remove_device
().
json
.
return_value
=
{
mock_remove_device
().
json
.
return_value
=
{
"
status
"
:
"
ok
"
,
"
status
"
:
"
ok
"
,
...
@@ -326,11 +326,11 @@ def mock_remove_device_success(faker):
...
@@ -326,11 +326,11 @@ def mock_remove_device_success(faker):
@pytest.fixture
()
@pytest.fixture
()
def
mock_remove_device_non_existent
(
faker
):
def
mock_remove_device_non_existent
(
faker
):
with
patch
(
"
gso.services.librenms_client.
requests.delete
"
)
as
mock_remove_device
:
with
patch
(
"
gso.services.librenms_client.
LibreNMSClient._send_request
"
)
as
mock_remove_device
:
mock_remove_device
().
status_code
=
HTTPStatus
.
NOT_FOUND
mock_remove_device
().
status_code
=
HTTPStatus
.
NOT_FOUND
mock_remove_device
().
json
.
return_value
=
{
"
status
"
:
"
error
"
,
"
message
"
:
"
Device non-existent-url not found
"
}
mock_remove_device
().
json
.
return_value
=
{
"
status
"
:
"
error
"
,
"
message
"
:
"
Device non-existent-url not found
"
}
mock_remove_device
().
raise_for_status
.
side_effect
=
HTTPError
(
mock_remove_device
().
raise_for_status
.
side_effect
=
HTTPError
(
"
404 Client Error: Not Found for url: http://librenms/devices/non-existent-url
"
,
"
404 Client Error: Not Found for url: http
s
://librenms/devices/non-existent-url
"
,
response
=
mock_remove_device
(),
response
=
mock_remove_device
(),
)
)
...
@@ -353,7 +353,7 @@ def test_get_device_not_found(mock_get_device_not_found):
...
@@ -353,7 +353,7 @@ def test_get_device_not_found(mock_get_device_not_found):
assert
e
.
value
.
response
.
status_code
==
HTTPStatus
.
NOT_FOUND
assert
e
.
value
.
response
.
status_code
==
HTTPStatus
.
NOT_FOUND
assert
e
.
value
.
response
.
json
()
==
{
"
status
"
:
"
error
"
,
"
message
"
:
"
Device non-existent-url does not exist
"
}
assert
e
.
value
.
response
.
json
()
==
{
"
status
"
:
"
error
"
,
"
message
"
:
"
Device non-existent-url does not exist
"
}
assert
e
.
value
.
args
[
0
]
==
"
404 Client Error: Not Found for url: http://librenms/devices/non-existent-url
"
assert
e
.
value
.
args
[
0
]
==
"
404 Client Error: Not Found for url: http
s
://librenms/devices/non-existent-url
"
def
test_device_exists_true
(
mock_get_device_success
):
def
test_device_exists_true
(
mock_get_device_success
):
...
@@ -376,7 +376,7 @@ def test_device_exists_bad_request(mock_get_device_unauthenticated):
...
@@ -376,7 +376,7 @@ def test_device_exists_bad_request(mock_get_device_unauthenticated):
assert
e
.
value
.
response
.
status_code
==
HTTPStatus
.
UNAUTHORIZED
assert
e
.
value
.
response
.
status_code
==
HTTPStatus
.
UNAUTHORIZED
assert
e
.
value
.
response
.
json
()
==
{
"
message
"
:
"
Unauthenticated.
"
}
assert
e
.
value
.
response
.
json
()
==
{
"
message
"
:
"
Unauthenticated.
"
}
assert
e
.
value
.
args
[
0
]
==
"
401 Client Error: Unauthorized for url: http://librenms/devices/naughty-url
"
assert
e
.
value
.
args
[
0
]
==
"
401 Client Error: Unauthorized for url: http
s
://librenms/devices/naughty-url
"
def
test_add_device_success
(
mock_add_device_success
):
def
test_add_device_success
(
mock_add_device_success
):
...
@@ -401,7 +401,7 @@ def test_add_device_bad_fqdn(mock_add_device_bad_url):
...
@@ -401,7 +401,7 @@ def test_add_device_bad_fqdn(mock_add_device_bad_url):
"
status
"
:
"
error
"
,
"
status
"
:
"
error
"
,
"
message
"
:
"
Could not ping non-existent-url (Hostname did not resolve to IP)
"
,
"
message
"
:
"
Could not ping non-existent-url (Hostname did not resolve to IP)
"
,
}
}
assert
e
.
value
.
args
[
0
]
==
"
500 Server Error: Internal server error for url: http://librenms/devices
"
assert
e
.
value
.
args
[
0
]
==
"
500 Server Error: Internal server error for url: http
s
://librenms/devices
"
def
test_add_device_no_ping
(
mock_add_device_unreachable
):
def
test_add_device_no_ping
(
mock_add_device_unreachable
):
...
@@ -416,7 +416,7 @@ def test_add_device_no_ping(mock_add_device_unreachable):
...
@@ -416,7 +416,7 @@ def test_add_device_no_ping(mock_add_device_unreachable):
"
status
"
:
"
error
"
,
"
status
"
:
"
error
"
,
"
message
"
:
"
Could not connect to non-existent-url, please check the snmp details and snmp reachability
"
,
"
message
"
:
"
Could not connect to non-existent-url, please check the snmp details and snmp reachability
"
,
}
}
assert
e
.
value
.
args
[
0
]
==
"
500 Server Error: Internal server error for url: http://librenms/devices
"
assert
e
.
value
.
args
[
0
]
==
"
500 Server Error: Internal server error for url: http
s
://librenms/devices
"
def
test_remove_device_success
(
mock_remove_device_success
):
def
test_remove_device_success
(
mock_remove_device_success
):
...
@@ -435,7 +435,7 @@ def test_remove_non_existent_device(mock_remove_device_non_existent):
...
@@ -435,7 +435,7 @@ def test_remove_non_existent_device(mock_remove_device_non_existent):
assert
e
.
value
.
response
.
status_code
==
HTTPStatus
.
NOT_FOUND
assert
e
.
value
.
response
.
status_code
==
HTTPStatus
.
NOT_FOUND
assert
e
.
value
.
response
.
json
()
==
{
"
status
"
:
"
error
"
,
"
message
"
:
"
Device non-existent-url not found
"
}
assert
e
.
value
.
response
.
json
()
==
{
"
status
"
:
"
error
"
,
"
message
"
:
"
Device non-existent-url not found
"
}
assert
e
.
value
.
args
[
0
]
==
"
404 Client Error: Not Found for url: http://librenms/devices/non-existent-url
"
assert
e
.
value
.
args
[
0
]
==
"
404 Client Error: Not Found for url: http
s
://librenms/devices/non-existent-url
"
def
test_validate_device_success
(
mock_get_device_success
):
def
test_validate_device_success
(
mock_get_device_success
):
...
...
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