def setUp(self): AwsExceptionsFactory._EX_REGISTRY.clear() AwsExceptionsFactory.add_exception("TestEx", TestEx) self._http_cls = Mock() self._http_module = Mock(return_value=self._http_cls) self._http_client = AwsHttpClient(self._http_module)
def test_add_exception(self): '''Test case for add_exception method success scenario.''' AwsExceptionsFactory.add_exception("AccessDenied", TestEx) result = AwsExceptionsFactory._EX_REGISTRY.get("AccessDenied") self.assertIsNotNone(result) self.assertIs(TestEx, result)
def test_get_exception_concrete(self): '''Test case for get exception method when a concrete exception is found.''' AwsExceptionsFactory.add_exception("AccessDenied", TestEx) for code in ["AccessDenied", "Access.Denied"]: self._error_response["ErrorResponse"]["Error"]["Code"] = code ex = AwsExceptionsFactory.get_exception(self._error_response) self.assertIsInstance(ex, TestEx) self.assertEqual(400, ex.http_status) self.assertEqual("Sender", ex.error_type) self.assertEqual("AccessDenied", ex.error_code) self.assertEqual("Test message", ex.error_msg) self.assertEqual("123", ex.request_id)
def test_add_exception_exist(self): '''Test case for add_exception method when the code is already registered in the factory.''' AwsExceptionsFactory.add_exception("AccessDenied", TestEx) self.assertRaises(ValueError, AwsExceptionsFactory.add_exception, *["AccessDenied", TestEx])