Skip to content
Snippets Groups Projects
Commit 9faf8327 authored by Robert Latta's avatar Robert Latta
Browse files

added handling for changed IMS response and updated test to cover it

parent 4c29640f
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@ from enum import Enum
# Navigation Properties
# http://149.210.162.190:81/ImsVersions/4.19.9/html/86d07a57-fa45-835e-d4a2-a789c4acbc96.htm # noqa
from requests import HTTPError
CIRCUIT_PROPERTIES = {
'Ports': 512,
'InternalPorts': 1024,
......@@ -75,6 +77,8 @@ VENDOR_RELATED_CONTACT_PROPERTIES = {
'Contact': 16
}
NO_FILTERED_RESULTS_MESSAGE = 'no records found for entity:'
class InventoryStatus(Enum):
PLANNED = 1
......@@ -166,7 +170,12 @@ class IMS(object):
if response_.status_code == requests.codes.unauthorized:
return True
if response_.status_code == requests.codes.ok:
if response_.status_code in (requests.codes.ok,
requests.codes.not_found):
if NO_FILTERED_RESULTS_MESSAGE in response_.text.lower():
return False
r = response_.json()
if r and 'HasErrors' in r and r['HasErrors']:
for e in r['Errors']:
......@@ -238,12 +247,20 @@ class IMS(object):
'paginatorNumberOfElements': step_count
}
url = f'{entity}/filtered/{filter_string}'
entities = self._get_entity(
url,
params,
navigation_properties,
use_cache)
more_to_come = False
try:
more_to_come = False
entities = self._get_entity(
url,
params,
navigation_properties,
use_cache)
except HTTPError as e:
r = e.response
if r.status_code == requests.codes.not_found \
and NO_FILTERED_RESULTS_MESSAGE in r.text.lower():
entities = None
else:
raise e
if entities:
more_to_come = \
len(entities) >= step_count
......
from requests import HTTPError
import inventory_provider
......@@ -5,6 +7,7 @@ class MockResponse:
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
self.text = '' if json_data else 'No records found for Entity:XXXXX'
def json(self):
return self.json_data
......@@ -96,6 +99,20 @@ def test_ims_class_filtered_entities(mocker):
assert mock_multi_get.call_count == 2
assert res == [1, 2, 3]
def side_effect_no_recs(*args, **kargs):
if kargs['params']['paginatorStartElement'] == 0:
return MockResponse([1, 2], 200)
e = HTTPError()
e.response = MockResponse('', 404)
raise e
mocker.patch('inventory_provider.db.ims.requests.get',
side_effect=side_effect_no_recs)
res = list(ds.get_filtered_entities(
'Node', 'dummy_param=dummy value', step_count=2))
assert res == [1, 2]
def test_ims_class_get_all_entities(mocker):
mock_get = mocker.patch('inventory_provider.db.ims.requests.get')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment