1818 ClientError as BotoClientError ,
1919 NoCredentialsError
2020)
21- from moto import mock_dynamodb2
21+ from moto import mock_aws
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- 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
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
4245
4346
4447def get_client ():
4548 from datalake_api import settings
4649 datalake_api .app .config .from_object (settings )
4750
4851 datalake_api .app .config ['TESTING' ] = True
52+ datalake_api .app .config ['AWS_REGION' ] = 'us-east-1'
4953 datalake_api .app .config ['AWS_ACCESS_KEY_ID' ] = 'abc'
5054 datalake_api .app .config ['AWS_SECRET_ACCESS_KEY' ] = '123'
5155
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' ):
56+ for a in ('archive_fetcher' , 's3_bucket' , 'dynamodb' ):
6057 try :
6158 delattr (datalake_api .app , a )
6259 except AttributeError :
@@ -71,15 +68,15 @@ def client():
7168
7269@pytest .fixture
7370def dynamodb (request ):
74- mock = mock_dynamodb2 ()
71+ mock = mock_aws ()
7572 mock .start ()
7673
7774 def tear_down ():
7875 mock .stop ()
7976 request .addfinalizer (tear_down )
8077
8178 return boto3 .resource ('dynamodb' ,
82- region_name = 'us-west-2 ' ,
79+ region_name = 'us-east-1 ' ,
8380 aws_secret_access_key = '123' ,
8481 aws_access_key_id = 'abc' )
8582
0 commit comments