@@ -126,7 +126,7 @@ def alternative_region():
126
126
127
127
@pytest .fixture
128
128
def signature_version ():
129
- return 's3 '
129
+ return 'v4 '
130
130
131
131
132
132
@pytest .fixture
@@ -160,23 +160,18 @@ def config(request, region, signature_version):
160
160
)
161
161
162
162
163
+ @pytest .fixture
164
+ def aws_auth ():
165
+ return {'aws_secret_access_key' : 'xxx' , 'aws_access_key_id' : 'xxx' }
166
+
167
+
163
168
@pytest .fixture
164
169
def mocking_test ():
165
170
# change this flag for test with real aws
166
171
# TODO: this should be merged with pytest.mark.moto
167
172
return True
168
173
169
174
170
- def moto_config (endpoint_url ):
171
- kw = dict (
172
- endpoint_url = endpoint_url ,
173
- aws_secret_access_key = "xxx" ,
174
- aws_access_key_id = "xxx" ,
175
- )
176
-
177
- return kw
178
-
179
-
180
175
@pytest .fixture
181
176
def patch_attributes (request ):
182
177
"""Call unittest.mock.patch on arguments passed through a pytest mark.
@@ -227,14 +222,15 @@ async def s3_client(
227
222
session ,
228
223
region ,
229
224
config ,
230
- s3_server ,
225
+ moto_server ,
231
226
mocking_test ,
232
227
s3_verify ,
233
228
patch_attributes ,
229
+ aws_auth ,
234
230
):
235
231
# This depends on mock_attributes because we may want to test event listeners.
236
232
# See the documentation of `mock_attributes` for details.
237
- kw = moto_config ( s3_server ) if mocking_test else {}
233
+ kw = { 'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
238
234
239
235
async with session .create_client (
240
236
's3' , region_name = region , config = config , verify = s3_verify , ** kw
@@ -244,9 +240,14 @@ async def s3_client(
244
240
245
241
@pytest .fixture
246
242
async def alternative_s3_client (
247
- session , alternative_region , signature_version , s3_server , mocking_test
243
+ session ,
244
+ alternative_region ,
245
+ signature_version ,
246
+ moto_server ,
247
+ mocking_test ,
248
+ aws_auth ,
248
249
):
249
- kw = moto_config ( s3_server ) if mocking_test else {}
250
+ kw = { 'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
250
251
251
252
config = AioConfig (
252
253
region_name = alternative_region ,
@@ -263,9 +264,9 @@ async def alternative_s3_client(
263
264
264
265
@pytest .fixture
265
266
async def dynamodb_client (
266
- session , region , config , dynamodb2_server , mocking_test
267
+ session , region , config , moto_server , mocking_test , aws_auth
267
268
):
268
- kw = moto_config ( dynamodb2_server ) if mocking_test else {}
269
+ kw = { 'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
269
270
async with session .create_client (
270
271
'dynamodb' , region_name = region , config = config , ** kw
271
272
) as client :
@@ -274,72 +275,86 @@ async def dynamodb_client(
274
275
275
276
@pytest .fixture
276
277
async def cloudformation_client (
277
- session , region , config , cloudformation_server , mocking_test
278
+ session , region , config , moto_server , mocking_test , aws_auth
278
279
):
279
- kw = moto_config ( cloudformation_server ) if mocking_test else {}
280
+ kw = { 'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
280
281
async with session .create_client (
281
282
'cloudformation' , region_name = region , config = config , ** kw
282
283
) as client :
283
284
yield client
284
285
285
286
286
287
@pytest .fixture
287
- async def sns_client (session , region , config , sns_server , mocking_test ):
288
- kw = moto_config (sns_server ) if mocking_test else {}
288
+ async def sns_client (
289
+ session , region , config , moto_server , mocking_test , aws_auth
290
+ ):
291
+ kw = {'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
289
292
async with session .create_client (
290
293
'sns' , region_name = region , config = config , ** kw
291
294
) as client :
292
295
yield client
293
296
294
297
295
298
@pytest .fixture
296
- async def sqs_client (session , region , config , sqs_server , mocking_test ):
297
- kw = moto_config (sqs_server ) if mocking_test else {}
299
+ async def sqs_client (
300
+ session , region , config , moto_server , mocking_test , aws_auth
301
+ ):
302
+ kw = {'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
298
303
async with session .create_client (
299
304
'sqs' , region_name = region , config = config , ** kw
300
305
) as client :
301
306
yield client
302
307
303
308
304
309
@pytest .fixture
305
- async def batch_client (session , region , config , batch_server , mocking_test ):
306
- kw = moto_config (batch_server ) if mocking_test else {}
310
+ async def batch_client (
311
+ session , region , config , moto_server , mocking_test , aws_auth
312
+ ):
313
+ kw = {'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
307
314
async with session .create_client (
308
315
'batch' , region_name = region , config = config , ** kw
309
316
) as client :
310
317
yield client
311
318
312
319
313
320
@pytest .fixture
314
- async def lambda_client (session , region , config , lambda_server , mocking_test ):
315
- kw = moto_config (lambda_server ) if mocking_test else {}
321
+ async def lambda_client (
322
+ session , region , config , moto_server , mocking_test , aws_auth
323
+ ):
324
+ kw = {'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
316
325
async with session .create_client (
317
326
'lambda' , region_name = region , config = config , ** kw
318
327
) as client :
319
328
yield client
320
329
321
330
322
331
@pytest .fixture
323
- async def iam_client (session , region , config , iam_server , mocking_test ):
324
- kw = moto_config (iam_server ) if mocking_test else {}
332
+ async def iam_client (
333
+ session , region , config , moto_server , mocking_test , aws_auth
334
+ ):
335
+ kw = {'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
325
336
async with session .create_client (
326
337
'iam' , region_name = region , config = config , ** kw
327
338
) as client :
328
339
yield client
329
340
330
341
331
342
@pytest .fixture
332
- async def rds_client (session , region , config , rds_server , mocking_test ):
333
- kw = moto_config (rds_server ) if mocking_test else {}
343
+ async def rds_client (
344
+ session , region , config , moto_server , mocking_test , aws_auth
345
+ ):
346
+ kw = {'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
334
347
async with session .create_client (
335
348
'rds' , region_name = region , config = config , ** kw
336
349
) as client :
337
350
yield client
338
351
339
352
340
353
@pytest .fixture
341
- async def ec2_client (session , region , config , ec2_server , mocking_test ):
342
- kw = moto_config (ec2_server ) if mocking_test else {}
354
+ async def ec2_client (
355
+ session , region , config , moto_server , mocking_test , aws_auth
356
+ ):
357
+ kw = {'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
343
358
async with session .create_client (
344
359
'ec2' , region_name = region , config = config , ** kw
345
360
) as client :
@@ -348,9 +363,9 @@ async def ec2_client(session, region, config, ec2_server, mocking_test):
348
363
349
364
@pytest .fixture
350
365
async def kinesis_client (
351
- session , region , config , kinesis_server , mocking_test
366
+ session , region , config , moto_server , mocking_test , aws_auth
352
367
):
353
- kw = moto_config ( kinesis_server ) if mocking_test else {}
368
+ kw = { 'endpoint_url' : moto_server , ** aws_auth } if mocking_test else {}
354
369
async with session .create_client (
355
370
'kinesis' , region_name = region , config = config , ** kw
356
371
) as client :
@@ -468,8 +483,8 @@ def tempdir():
468
483
469
484
470
485
@pytest .fixture
471
- def create_object (s3_client , bucket_name ):
472
- async def _f (key_name , body = 'foo' ):
486
+ def create_object (s3_client , bucket_name : str ):
487
+ async def _f (key_name : str , body = 'foo' , ** kwargs ):
473
488
r = await s3_client .put_object (
474
489
Bucket = bucket_name , Key = key_name , Body = body
475
490
)
0 commit comments