示例#1
0
def s3_mock():
    mock = mock_s3()
    mock.start()

    yield

    mock.stop()
示例#2
0
文件: conftest.py 项目: troylar/S4
def s3_client():
    mock = moto.mock_s3()
    mock.start()
    boto_client = boto3.client(
        "s3", aws_access_key_id="", aws_secret_access_key="", aws_session_token=""
    )
    bucket_name = fake.user_name()
    boto_client.create_bucket(Bucket=bucket_name)
    yield S3SyncClient(boto_client, bucket_name, fake.uri_path())
    mock.stop()
示例#3
0
def ec2_mock():
    mock = mock_ec2()
    mock_cw = mock_cloudwatch()

    mock.start()
    mock_cw.start()

    yield

    mock.stop()
    mock_cw.stop()
示例#4
0
def s3(inspire_app, enable_files):
    mock = mock_s3()
    mock.start()
    client = boto3.client("s3")
    resource = boto3.resource("s3")
    s3 = S3(client, resource)

    class MockedInspireS3:
        s3_instance = s3

    real_inspirehep_s3 = inspire_app.extensions["inspirehep-s3"]
    inspire_app.extensions["inspirehep-s3"] = MockedInspireS3

    yield s3
    mock.stop()
    inspire_app.extensions["inspirehep-s3"] = real_inspirehep_s3
示例#5
0
    def tearDown(self):
        for mock in self._mocks.values():
            mock.stop()

        return super(MockTestCaseMixin, self).tearDown()
示例#6
0
 def _stop_all_mocks(self):
     for mock in self._mocks.itervalues():
         mock.stop()
示例#7
0
 def _stop_zmq_mocks(self):
     for mock in self.mocks:
         mock.stop()
region = os.environ['REGION']
function_name = os.environ['FUNCTION_NAME']

from cfn_auto_update_broker import (get_lambda_arn,
                                    create_event,
                                    put_targets,
                                    delete_event,
                                    lambda_add_resource_policy,
                                    lambda_remove_resource_policy,
                                    lambda_handler)

mock = mock_sts()
mock.start()
account_id = boto3.client('sts').get_caller_identity().get('Account')
mock.stop()


# TestFunction plagarized from:
# https://github.com/spulec/moto/issues/1338
def _process_lambda(func_str):
    zip_output = io.BytesIO()
    zip_file = zipfile.ZipFile(zip_output, 'w', zipfile.ZIP_DEFLATED)
    zip_file.writestr('lambda_function.py', func_str)
    zip_file.close()
    zip_output.seek(0)
    return zip_output.read()


def get_test_zip_file1():
    """Return test zip file."""
    def tearDown(self):
        for mock in self._mocks.values():
            mock.stop()

        return super(MockTestCaseMixin, self).tearDown()