Skip to content

Commit a70ec80

Browse files
authored
Added not-found error message for hostname search (#47)
* Added not-found error message for address search * Add test for PHPyPAMEntityNotFoundException Refactor exception.py to make `_NOT_FOUND_MESSAGES` available outside exception definition. Add test method for testing not found exceptions. Iterate over a list of dicts with test data. Add fixture for the new test case for not found exception. * add changelog entry Co-authored-by: cmeissner
1 parent 6d80f66 commit a70ec80

File tree

4 files changed

+457
-11
lines changed

4 files changed

+457
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Changes
1010

1111
### Fixes
12+
* fix #48 - raise PHPyPAMEntityNotFoundException if searching for non existing host
1213

1314
### Breaks
1415

phpypam/core/exceptions.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ class PHPyPAMException(Exception):
77
This exception is raised if anythings in :class:`phpypam.api` doesn't work out.
88
"""
99

10+
_NOT_FOUND_MESSAGES = {
11+
'No subnets found',
12+
'Address not found',
13+
'Vlan not found',
14+
'No vrfs configured',
15+
'No devices configured',
16+
'No results (filter applied)',
17+
'No objects found',
18+
'Hostname not found'
19+
}
20+
1021
def __init__(self, *args, code=None, message=None):
1122
"""Generate PHPyPAMException.
1223
@@ -24,17 +35,7 @@ def __init__(self, *args, code=None, message=None):
2435
self._code = code
2536
self._message = message
2637

27-
_NOT_FOUND_MESSAGES = {
28-
'No subnets found',
29-
'Address not found',
30-
'Vlan not found',
31-
'No vrfs configured',
32-
'No devices configured',
33-
'No results (filter applied)',
34-
'No objects found',
35-
}
36-
37-
if (self._code == 200 and self._message in _NOT_FOUND_MESSAGES) or self._code == 404:
38+
if (self._code == 200 and self._message in self._NOT_FOUND_MESSAGES) or self._code == 404:
3839
raise PHPyPAMEntityNotFoundException(self._message)
3940
elif self._code == 500:
4041
if self._message == 'Invalid username or password':

0 commit comments

Comments
 (0)