def test_fetch_too_many_systems(self): systems_to_fetch = list(string.ascii_lowercase) with self.assertRaises(SystemNotReturned) as cm: inventory_service_interface.fetch_systems(systems_to_fetch, "my-auth-key", self.mock_logger) self.assertEqual(cm.exception.message, "Too many systems requested, limit is 20")
def test_fetch_systems_backend_service_error(self): systems_to_fetch = [ '243926fa-262f-11e9-a632-c85b761454fa', '264fb5b2-262f-11e9-9b12-c85b761454fa', '269a3da8-262f-11e9-8ee5-c85b761454fa' ] self._create_500_response_for_systems('inventory_svc_url_is_not_set', ','.join(systems_to_fetch)) with self.assertRaises(InventoryServiceError) as cm: inventory_service_interface.fetch_systems(systems_to_fetch, "my-auth-key", self.mock_logger) self.assertEqual(cm.exception.message, "Error received from backend service")
def test_fetch_systems_missing_system(self): systems_to_fetch = [ '243926fa-262f-11e9-a632-c85b761454fa', '264fb5b2-262f-11e9-9b12-c85b761454fa', '269a3da8-262f-11e9-8ee5-c85b761454fa' ] self._create_response_for_systems('inventory_svc_url_is_not_set', ','.join(systems_to_fetch)) with self.assertRaises(SystemNotReturned) as cm: inventory_service_interface.fetch_systems(systems_to_fetch, "my-auth-key", self.mock_logger) self.assertEqual( cm.exception.message, "System(s) 269a3da8-262f-11e9-8ee5-c85b761454fa not available to display" )
def test_fetch_systems(self): systems_to_fetch = [ '243926fa-262f-11e9-a632-c85b761454fa', '264fb5b2-262f-11e9-9b12-c85b761454fa' ] self._create_response_for_systems('inventory_svc_url_is_not_set', ','.join(systems_to_fetch)) systems = inventory_service_interface.fetch_systems( systems_to_fetch, "my-auth-key", self.mock_logger) found_system_ids = {system['id'] for system in systems} self.assertSetEqual(found_system_ids, set(systems_to_fetch))
def comparison_report(): system_ids = request.args.getlist('system_ids[]') auth_key = get_key_from_headers(request.headers) fact_namespace = FACT_NAMESPACE if config.return_mock_data: fact_namespace = MOCK_FACT_NAMESPACE try: comparisons = info_parser.build_comparisons(fetch_systems(system_ids, auth_key, current_app.logger), fact_namespace) return jsonify(comparisons) except SystemNotReturned as error: raise HTTPError(HTTPStatus.BAD_REQUEST, message=error.message)
def test_fetch_systems_mock_facts(self, mock_config): mock_config.inventory_svc_hostname = "http://inventory_svc_url_is_not_set" mock_config.return_mock_data = True systems_to_fetch = [ '243926fa-262f-11e9-a632-c85b761454fa', '264fb5b2-262f-11e9-9b12-c85b761454fa' ] self._create_response_for_systems('inventory_svc_url_is_not_set', ','.join(systems_to_fetch)) systems = inventory_service_interface.fetch_systems( systems_to_fetch, "my-auth-key", self.mock_logger) found_system_ids = {system['id'] for system in systems} self.assertSetEqual(found_system_ids, set(systems_to_fetch))