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

    yield

    mock.stop()
Exemple #2
0
def responses(request):
    """Mock the requests library using responses.

    Return a RequestsMock instance rather than using the global default.
    """
    mock = responses_lib.RequestsMock()
    mock.start()
    request.addfinalizer(mock.stop)
    return mock
Exemple #3
0
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()
Exemple #4
0
def ec2_mock():
    mock = mock_ec2()
    mock_cw = mock_cloudwatch()

    mock.start()
    mock_cw.start()

    yield

    mock.stop()
    mock_cw.stop()
Exemple #5
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
Exemple #6
0
 def setUp(self):
     shotmgr = Mock()
     self.mgr = GoProManager.GoProManager(shotmgr)
     mock = patch('settings.writeSetting')
     self.addCleanup(mock.stop)
     self.mockWrite = mock.start()
     self.mgr.setGimbalEnabledParam = Mock()
 def setUp(self):
     self.maxDiff = None
     self.site_root = os.path.realpath(tempfile.mkdtemp(suffix='siteroot'))
     settings.SITE_ROOT = self.site_root
     settings.DOCROOT = os.path.join(settings.SITE_ROOT, 'user_builds')
     self.mocks = {
         'PublicSymlinkBase.CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PublicSymlinkBase.WEB_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PublicSymlinkBase.PROJECT_CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PrivateSymlinkBase.CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PrivateSymlinkBase.WEB_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PrivateSymlinkBase.PROJECT_CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
     }
     self.patches = dict((key, mock.start()) for (key, mock) in list(self.mocks.items()))
     self.patches['PublicSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_cname_root'
     )
     self.patches['PublicSymlinkBase.WEB_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_web_root'
     )
     self.patches['PublicSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_cname_project'
     )
     self.patches['PrivateSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_cname_root'
     )
     self.patches['PrivateSymlinkBase.WEB_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_web_root'
     )
     self.patches['PrivateSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_cname_project'
     )
 def setUp(self):
     self.maxDiff = None
     self.site_root = os.path.realpath(tempfile.mkdtemp(suffix='siteroot'))
     settings.SITE_ROOT = self.site_root
     settings.DOCROOT = os.path.join(settings.SITE_ROOT, 'user_builds')
     self.mocks = {
         'PublicSymlinkBase.CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PublicSymlinkBase.WEB_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PublicSymlinkBase.PROJECT_CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PrivateSymlinkBase.CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PrivateSymlinkBase.WEB_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock
         ),
         'PrivateSymlinkBase.PROJECT_CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock
         ),
     }
     self.patches = dict((key, mock.start()) for (key, mock) in list(self.mocks.items()))
     self.patches['PublicSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_cname_root'
     )
     self.patches['PublicSymlinkBase.WEB_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_web_root'
     )
     self.patches['PublicSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_cname_project'
     )
     self.patches['PrivateSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_cname_root'
     )
     self.patches['PrivateSymlinkBase.WEB_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_web_root'
     )
     self.patches['PrivateSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_cname_project'
     )
 def setUp(self):
     self.maxDiff = None
     self.mocks = {
         'PublicSymlinkBase.CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PublicSymlinkBase.WEB_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PublicSymlinkBase.PROJECT_CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PrivateSymlinkBase.CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PrivateSymlinkBase.WEB_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PrivateSymlinkBase.PROJECT_CNAME_ROOT': mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
     }
     self.patches = {key: mock.start() for (key, mock) in list(self.mocks.items())}
     self.patches['PublicSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_cname_root',
     )
     self.patches['PublicSymlinkBase.WEB_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_web_root',
     )
     self.patches['PublicSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'public_cname_project',
     )
     self.patches['PrivateSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_cname_root',
     )
     self.patches['PrivateSymlinkBase.WEB_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_web_root',
     )
     self.patches['PrivateSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT, 'private_cname_project',
     )
Exemple #10
0
 def _start_all_mocks(self):
     for mock in self._mocks.itervalues():
         mock.start()
Exemple #11
0
def sqs(request):
    mock = moto.mock_sqs()
    mock.start()
    sqs = boto3.resource('sqs', region_name='us-east-1')
    request.addfinalizer(mock.stop)
    return sqs
            )
mock_env.start()

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 setUp(self):
     self.maxDiff = None
     self.mocks = {
         'PublicSymlinkBase.CNAME_ROOT':
         mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PublicSymlinkBase.WEB_ROOT':
         mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PublicSymlinkBase.PROJECT_CNAME_ROOT':
         mock.patch(
             'readthedocs.core.symlink.PublicSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PrivateSymlinkBase.CNAME_ROOT':
         mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PrivateSymlinkBase.WEB_ROOT':
         mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.WEB_ROOT',
             new_callable=mock.PropertyMock,
         ),
         'PrivateSymlinkBase.PROJECT_CNAME_ROOT':
         mock.patch(
             'readthedocs.core.symlink.PrivateSymlinkBase.PROJECT_CNAME_ROOT',
             new_callable=mock.PropertyMock,
         ),
     }
     self.patches = {
         key: mock.start()
         for (key, mock) in list(self.mocks.items())
     }
     self.patches[
         'PublicSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
             settings.SITE_ROOT,
             'public_cname_root',
         )
     self.patches['PublicSymlinkBase.WEB_ROOT'].return_value = os.path.join(
         settings.SITE_ROOT,
         'public_web_root',
     )
     self.patches[
         'PublicSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
             settings.SITE_ROOT,
             'public_cname_project',
         )
     self.patches[
         'PrivateSymlinkBase.CNAME_ROOT'].return_value = os.path.join(
             settings.SITE_ROOT,
             'private_cname_root',
         )
     self.patches[
         'PrivateSymlinkBase.WEB_ROOT'].return_value = os.path.join(
             settings.SITE_ROOT,
             'private_web_root',
         )
     self.patches[
         'PrivateSymlinkBase.PROJECT_CNAME_ROOT'].return_value = os.path.join(
             settings.SITE_ROOT,
             'private_cname_project',
         )