A base class that wraps the botocore Stubber and either uses the Stubber to intercept requests during tests or pass calls through to AWS. All stubbers used in Python unit tests must inherit from this base class.
| 10 | |
| 11 | |
| 12 | class ExampleStubber(Stubber): |
| 13 | """ |
| 14 | A base class that wraps the botocore Stubber and either uses the Stubber to |
| 15 | intercept requests during tests or pass calls through to AWS. |
| 16 | |
| 17 | All stubbers used in Python unit tests must inherit from this base class. |
| 18 | """ |
| 19 | |
| 20 | def __init__(self, client, use_stubs=True): |
| 21 | """ |
| 22 | Initializes the object with a specific client and configures it for |
| 23 | stubbing or AWS passthrough. |
| 24 | |
| 25 | :param client: A Boto 3 service client. |
| 26 | :param use_stubs: When True, use stubs to intercept requests. Otherwise, |
| 27 | pass requests through to AWS. |
| 28 | """ |
| 29 | self.use_stubs = use_stubs |
| 30 | self.region_name = client.meta.region_name |
| 31 | if self.use_stubs: |
| 32 | super().__init__(client) |
| 33 | else: |
| 34 | self.client = client |
| 35 | |
| 36 | def add_response(self, method, service_response, expected_params=None): |
| 37 | """When using stubs, add a stubbed response.""" |
| 38 | if self.use_stubs: |
| 39 | super().add_response(method, service_response, expected_params) |
| 40 | |
| 41 | def add_client_error( |
| 42 | self, |
| 43 | method, |
| 44 | service_error_code="", |
| 45 | service_message="", |
| 46 | http_status_code=400, |
| 47 | service_error_meta=None, |
| 48 | expected_params=None, |
| 49 | response_meta=None, |
| 50 | modeled_fields=None, |
| 51 | ): |
| 52 | """When using stubs, add a stubbed error response.""" |
| 53 | if self.use_stubs: |
| 54 | super().add_client_error( |
| 55 | method, |
| 56 | service_error_code, |
| 57 | service_message, |
| 58 | http_status_code, |
| 59 | service_error_meta, |
| 60 | expected_params, |
| 61 | response_meta, |
| 62 | ) |
| 63 | |
| 64 | def assert_no_pending_responses(self): |
| 65 | """When using stubs, verify no more responses are waiting in the queue.""" |
| 66 | if self.use_stubs: |
| 67 | super().assert_no_pending_responses() |
| 68 | |
| 69 | def _stub_bifurcator( |
nothing calls this directly
no outgoing calls
no test coverage detected