wg_utilities.testing
Pytest fixtures that can be used across projects.
MockBoto3Client
boto3.client for mock usage.
Class for adding custom mocks for boto3 when moto doesn't support the operation.
Usage
from unittest.mock import patch
def test_something(): mocked_operation_lookup = { "operation_name": "response", } mock_boto3_client = MockBoto3Client(mocked_operation_lookup)
with patch( MockBoto3Client.PATCH_METHOD, mock_boto3_client.build_api_call(), ):
Do something that calls the mocked operation
assert mock_boto3_client.boto3_calls == { "operation_name": [{"kwarg": "value"}], }
Source code in wg_utilities/testing/_custom_mocks.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
build_api_call(*, lookup_overrides=None, reset_boto3_calls=True)
Build an API call for use in stubs.
Wrapper function for the API call. Also resets the internal log of boto3 calls as this is a new API call
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lookup_overrides |
dict
|
any overrides to be applied for this specific API call |
None
|
reset_boto3_calls |
bool
|
option for resetting boto3 calls |
True
|
Returns:
Name | Type | Description |
---|---|---|
function |
Callable[[BaseClient, str, dict[str, Any]], object]
|
the mocked API call |
Source code in wg_utilities/testing/_custom_mocks.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
reset_boto3_calls()
Reset the boto3 calls to an empty dict.
Source code in wg_utilities/testing/_custom_mocks.py
54 55 56 |
|