1818 ClientError as BotoClientError ,
1919 NoCredentialsError
2020)
21- from moto import mock_aws
21+ from moto import mock_dynamodb2
2222
2323from datalake_api import app as datalake_api
2424from datalake .tests import * # noqa
3333# This will cause moto to fail
3434# But more critically, may impact production systems
3535# So we test for real credentials and fail hard if they exist
36- # Session fixture runs in pytest setup rather than at import time
37- @pytest .fixture (scope = 'session' , autouse = True )
38- def verify_no_aws_credentials ():
39- sts = boto3 .client ('sts' )
40- try :
41- sts .get_caller_identity ()
42- pytest .exit ("Real AWS credentials detected, aborting" , 3 )
43- except NoCredentialsError :
44- pass
36+ sts = boto3 .client ('sts' )
37+ try :
38+ sts .get_caller_identity ()
39+ pytest .exit ("Real AWS credentials detected, aborting" , 3 )
40+ except NoCredentialsError :
41+ pass # no credentials are good
4542
4643
4744def get_client ():
4845 from datalake_api import settings
4946 datalake_api .app .config .from_object (settings )
5047
5148 datalake_api .app .config ['TESTING' ] = True
52- datalake_api .app .config ['AWS_REGION' ] = 'us-east-1'
5349 datalake_api .app .config ['AWS_ACCESS_KEY_ID' ] = 'abc'
5450 datalake_api .app .config ['AWS_SECRET_ACCESS_KEY' ] = '123'
5551
56- for a in ('archive_fetcher' , 's3_bucket' , 'dynamodb' ):
52+ # TODO: Sigh. The api caches the archive_fetcher and s3_bucket, which is
53+ # the right thing. However, because moto<3 still uses httpretty, and
54+ # because httpretty wreaks havoc on the python socket code, these cached
55+ # parts end up in a bad state after their first use. The right thing to do
56+ # here is to upgrade moto. But for that we will also have to move
57+ # everything from boto to boto3. This is a near-term goal. But first lets
58+ # get everything off of python2.
59+ for a in ('archive_fetcher' , 's3_bucket' ):
5760 try :
5861 delattr (datalake_api .app , a )
5962 except AttributeError :
@@ -68,15 +71,15 @@ def client():
6871
6972@pytest .fixture
7073def dynamodb (request ):
71- mock = mock_aws ()
74+ mock = mock_dynamodb2 ()
7275 mock .start ()
7376
7477 def tear_down ():
7578 mock .stop ()
7679 request .addfinalizer (tear_down )
7780
7881 return boto3 .resource ('dynamodb' ,
79- region_name = 'us-east-1 ' ,
82+ region_name = 'us-west-2 ' ,
8083 aws_secret_access_key = '123' ,
8184 aws_access_key_id = 'abc' )
8285
0 commit comments