Moto Fixtures
aws_credentials(aws_region, monkeypatch)
Mocked AWS Credentials for moto.
Source code in pytest_aiomoto/aws_credentials.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
aws_profile_credentials(monkeypatch)
This returns a context manager that applies awscli credentials for a named profile - it assumes the named profile is available - and it will use monkeypatch to set awscli environment variables with those credentials. It cleans up the environment variables.
The context manager returned is used like so
with mock_aws_credentials(profile_name, aws_region) as profile_session: assert isinstance(profile_session, boto3.session.Session)
Source code in pytest_aiomoto/aws_credentials.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
clean_aws_credentials(monkeypatch)
This uses monkeypatch to clear awscli environment variables and applies
boto3.DEFAULT_SESSION = None S3FileSystem.clear_instance_cache()
Source code in pytest_aiomoto/aws_credentials.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
ctx_aws_default_credentials(monkeypatch)
This returns a context manager that applies awscli credentials for a named profile - it assumes the named profile is available - and it will use monkeypatch to set awscli environment variables with those credentials. It cleans up the environment variables.
Source code in pytest_aiomoto/aws_credentials.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
ctx_aws_default_credentials_file(monkeypatch)
This returns a context manager that mocks [default] profile credentials in a temporary credentials file.
... seealso:: - https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#shared-credentials-file - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list
Source code in pytest_aiomoto/aws_credentials.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
default_profile()
a default profile key:value pairs
Source code in pytest_aiomoto/aws_credentials.py
232 233 234 235 236 237 |
|
default_profile_credentials_content(default_profile)
A string for the [default] entry in ~/.aws/credentials file
Source code in pytest_aiomoto/aws_credentials.py
240 241 242 243 244 245 |
|
get_default_profile()
a default profile key:value pairs
Source code in pytest_aiomoto/aws_credentials.py
35 36 37 38 39 40 41 42 43 |
|
mock_default_credentials_file(monkeypatch)
A context manager to mock a default profile in a mocked temporary file like ~/.aws/credentials
Source code in pytest_aiomoto/aws_credentials.py
277 278 279 280 281 282 283 284 |
|
mock_default_profile(default_profile, mocker, monkeypatch)
mock a default profile by patching botocore.session.Session.get_scoped_config
Source code in pytest_aiomoto/aws_credentials.py
265 266 267 268 269 270 271 272 273 274 |
|
mock_default_session(monkeypatch)
A context manager to mock a session with a default profile by creating a mocked temporary file like ~/.aws/credentials
Source code in pytest_aiomoto/aws_credentials.py
287 288 289 290 291 292 293 294 |
|
patch_aws_profile_credentials(profile_name, aws_region=None, profile_file=None, monkeypatch=None)
This returns a context manager that applies awscli credentials for a named profile - it assumes the named profile is available - and it will use monkeypatch to set awscli environment variables with those credentials. It cleans up the environment variables.
Source code in pytest_aiomoto/aws_credentials.py
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 141 |
|
setup_aws_credentials(profile_name, aws_region=None, profile_file=None, monkeypatch=None)
Any clients created from this session will use credentials from the [profile_name] section of ~/.aws/credentials.
This assumes the profile_name is available in user credentials, it does not mock the credentials.
It yields a boto3.Session
for the named profile, and it uses
monkeypatch to set awscli environment variables with the profile credentials.
Source code in pytest_aiomoto/aws_credentials.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
batch_infrastructure(aws_clients, compute_env_name, job_queue_name, job_definition_name, iam_role_name)
Create AWS Batch infrastructure, including: - VPC with subnet - Security group and IAM role - Batch compute environment and job queue - Batch job job_definition
This function is not a fixture so that tests can pass the AWS clients to it and then continue to use the infrastructure created by it while the client fixtures are in-tact for the duration of a test.
Source code in pytest_aiomoto/aws_batch.py
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
compute_env_name(moto_uuid)
A unique batch compute environment name
Source code in pytest_aiomoto/aws_batch.py
60 61 62 63 |
|
iam_role_name(moto_uuid)
A unique IAM role name
Source code in pytest_aiomoto/aws_batch.py
66 67 68 69 |
|
job_definition_name(moto_uuid)
A unique batch job definition name
Source code in pytest_aiomoto/aws_batch.py
54 55 56 57 |
|
job_queue_name(moto_uuid)
A unique batch queue name
Source code in pytest_aiomoto/aws_batch.py
48 49 50 51 |
|
moto_uuid()
A uuid.uuid4() for unique moto mock artifacts
Source code in pytest_aiomoto/aws_batch.py
42 43 44 45 |
|
AWS Lambda Utilities for Testing
lambda_handler(event, context)
A lambda handler for test purposes. This function must be self-contained, including imports required.
Source code in pytest_aiomoto/aws_lambda.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
MotoService
Will Create MotoService.
Service is ref-counted so there will only be one per process. Real Service will
be returned by __enter__
.
Source code in pytest_aiomoto/moto_services.py
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
moto_service_reset(service_name)
Reset a moto service backend, for all regions. Each service can have multiple regional backends.
Source code in pytest_aiomoto/moto_services.py
33 34 35 36 37 38 39 40 41 |
|
AWS test fixtures
This test suite uses a large suite of moto mocks for the AWS batch infrastructure. These infrastructure mocks are derived from the moto test suite for testing the batch client. The test infrastructure should be used according to the moto license.
.. seealso::
- https://github.com/spulec/moto/pull/1197/files
- https://github.com/spulec/moto/blob/master/tests/test_batch/test_batch.py
s3_bucket(s3_bucket_name, aws_s3_client, aws_region)
The s3_bucket fixture provides a moto-bucket for the s3_bucket_name fixture, where the moto-bucket is cleaned up on exit. :return: the s3_bucket_name
Source code in pytest_aiomoto/aws_s3.py
218 219 220 221 222 223 224 225 226 227 228 |
|
s3_bucket_name(s3_uuid)
A valid S3 bucket name with a UUID suffix.
This bucket may not exist yet; for a bucket that exists, use
the s3_bucket
fixture instead. It creates a moto-bucket
for this bucket name.
:return: str for the bucket component of 's3://{bucket}/{key}'
Source code in pytest_aiomoto/aws_s3.py
204 205 206 207 208 209 210 211 212 213 214 215 |
|
s3_bucket_resource(s3_bucket_name, aws_s3_resource, aws_region)
The s3_bucket fixture provides a moto-bucket for the s3_bucket_name fixture, where the moto-bucket is cleaned up on exit. :return: the s3.Bucket resource
Source code in pytest_aiomoto/aws_s3.py
231 232 233 234 235 236 237 238 239 240 241 |
|
s3_buckets(s3_bucket_name, aws_s3_client, aws_region)
The s3_buckets fixture creates moto-buckets for the s3_bucket_name fixture, with a numeric suffix for each bucket, where the moto-buckets are cleaned up on exit. :return: a list of bucket names
Source code in pytest_aiomoto/aws_s3.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
s3_key(s3_key_path, s3_key_file)
A valid S3 key composed of a key_path and a key_file The key component of 's3://{bucket}/{key}' that is composed of '{key_path}/{key_file}'; the key does not begin or end with any delimiters (e.g. '/') :return: str for the key component of 's3://{bucket}/{key}'
Source code in pytest_aiomoto/aws_s3.py
285 286 287 288 289 290 291 292 |
|
s3_key_file()
A valid S3 key name that is also a file name The key component of 's3://{bucket}/{key}' that is composed of '{key_file}'; the key does not begin or end with any delimiters (e.g. '/') :return: str for the key component of 's3://{bucket}/{key}'
Source code in pytest_aiomoto/aws_s3.py
275 276 277 278 279 280 281 282 |
|
s3_key_path()
A valid S3 key name that is not a file name, it's like a directory The key component of 's3://{bucket}/{key}' that is composed of '{key_path}'; the key does not begin or end with any delimiters (e.g. '/') :return: str for the key component of 's3://{bucket}/{key}'
Source code in pytest_aiomoto/aws_s3.py
265 266 267 268 269 270 271 272 |
|
s3_object_text()
s3 object data: 's3 test object text '
Source code in pytest_aiomoto/aws_s3.py
295 296 297 298 |
|
s3_protocol()
An s3:// protocol prefix
Source code in pytest_aiomoto/aws_s3.py
192 193 194 195 |
|
s3_temp_1000s_objects(aws_s3_client, aws_s3_resource, s3_bucket, s3_temp_dir, s3_uuid)
This creates 1010 files, half with .txt and others with .tif file extensions, below the s3://s3_bucket/s3_temp_dir path; the default page limit for s3 object listings is usually 1000, so this should exceed 1 page.
Source code in pytest_aiomoto/aws_s3.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
s3_temp_objects(aws_s3_client, aws_s3_resource, s3_bucket, s3_temp_dir, s3_uuid)
This creates 10 files, 5 with .txt and 5 with .tif file extensions, below the s3://s3_bucket/s3_temp_dir path
Source code in pytest_aiomoto/aws_s3.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
s3_uri_object(aws_s3_client, aws_s3_resource, aws_region, s3_bucket_name, s3_key, s3_object_text)
The s3_uri_object fixture creates a moto-bucket and moto-object for the s3_uri_str fixture, where the moto-bucket is cleaned up on exit. :return: an S3Object(bucket=s3_bucket_name, key=s3_key)
Source code in pytest_aiomoto/aws_s3.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
s3_uri_str(s3_protocol, s3_bucket_name, s3_key)
A valid S3 URI comprised of 's3://{bucket}/{key}'
This s3_uri_str may not exist yet; for an object that exists, use
the s3_uri_object
fixture instead.
:return: str
Source code in pytest_aiomoto/aws_s3.py
301 302 303 304 305 306 307 308 309 310 |
|
s3_uuid()
A UUID for S3 artifacts
Source code in pytest_aiomoto/aws_s3.py
198 199 200 201 |
|
S3Object
Bases: NamedTuple
Just the bucket_name and key for an :code:s3.ObjectSummary
.
This simple named tuple should work around problems with :code:Pickle
for an :code:s3.ObjectSummary
Source code in pytest_aiomoto/s3_object.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
response_success(response)
Parse a response from a request issued by any botocore.client.BaseClient to determine whether the request was successful or not. :param response: :return: boolean :raises: KeyError if the response is not an AWS response
Source code in pytest_aiomoto/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|