def test_simplivity_resource_not_found_inheritance(self): exception = exceptions.HPESimpliVityResourceNotFound( "The resource was not found!") self.assertIsInstance(exception, exceptions.HPESimpliVityException) self.assertEqual(exception.msg, "The resource was not found!") self.assertEqual(exception.response, None) self.assertEqual(exception.args[0], "The resource was not found!")
def get_by_id(self, resource_id): """Gets resource by id. Args: id: ID of the resource Returns: object: Resource object Raises: HPESimpliVityResourceNotFound: if resource doesn't exist with the id passed. """ resources = self.get_all(filters={'id': resource_id}) if not len(resources): raise exceptions.HPESimpliVityResourceNotFound("Resource not found with the id {}".format(resource_id)) return resources[0]
def get_by_name(self, name): """Gets resource by name. Args: name: Name of the resource Returns: object: object of the resource Raises: HPESimpliVityResourceNotFound: if resource doesn't exist with the name passed. """ resources = self.get_all(filters={'name': name}) if not len(resources): raise exceptions.HPESimpliVityResourceNotFound("Resource not found with the name {}".format(name)) return resources[0]