예제 #1
0
    def test_empty_mapping_json_err(self, mock_env):
        jsonD = '{"EventSourceMappings": []}'

        with patch('builtins.open', mock_open(read_data=jsonD), create=True):
            createEventMapping('development')

        mock_env.assert_not_called()
예제 #2
0
    def test_event_mapping_json_err(self):
        jsonD = ('{"EventSourceMappings": [{"EventSourceArn": "test",'
                 '"Enabled": "test", "BatchSize": "test",'
                 '"StartingPosition": "test"}}')

        with patch('builtins.open', mock_open(read_data=jsonD), create=True):
            try:
                createEventMapping('development')
            except json.decoder.JSONDecodeError:
                pass

        self.assertRaises(json.decoder.JSONDecodeError)
예제 #3
0
def deployFunc(runType):
    """Deploys the current Lambda function to the environment specificied
    in the current configuration file.

    Arguments:
        runType {string} -- The environment to deploy the function to. Should
        be one of [local|development|qa|production]
    """
    logger.info('Deploying lambda to {} environment'.format(runType))
    runProcess(runType, [
        'deploy', '--config-file', 'run_config.yaml', '--requirements',
        'requirements.txt'
    ])
    createEventMapping(runType)
예제 #4
0
def main():
    """Invoked by the makefile's arguments, controls the overall execution of
    the Lambda function. h/t to nonword for inspiration to use a makefile.

    Raises:
        InvalidExecutionType: If the args do not contain a valid execution type
        raise an error.
    """
    if len(sys.argv) != 2:
        logger.warning('This script takes one, and only one, argument!')
        sys.exit(1)
    runType = sys.argv[1]

    if re.match(r'^(?:local|development|qa|production)', runType):
        logger.info('Deploying lambda to {} environment'.format(runType))
        setEnvVars(runType)
        subprocess.run([
            'lambda', 'deploy', '--config-file', 'run_config.yaml',
            '--requirements', 'requirements.txt'
        ])
        os.remove('run_config.yaml')
        createEventMapping(runType)

    elif re.match(r'^run-local', runType):
        logger.info('Running test locally with development environment')
        env = 'local'
        setEnvVars(env)
        subprocess.run(
            ['lambda', 'invoke', '-v', '--config-file', 'run_config.yaml'])
        os.remove('run_config.yaml')

    elif re.match(r'^build-(?:development|qa|production)', runType):
        env = runType.replace('build-', '')
        logger.info(
            'Building package for {} environment, will be in dist/'.format(
                env))
        setEnvVars(env)
        subprocess.run([
            'lambda', 'build', '--requirements', 'requirements.txt',
            '--config-file', 'run_config.yaml'
        ])
        os.remove('run_config.yaml')

    else:
        logger.error('Execution type not recognized! {}'.format(runType))
        raise InvalidExecutionType('{} is not a valid command'.format(runType))
예제 #5
0
    def test_create_event_mapping(self, mock_env, mock_client):
        jsonD = ('{"EventSourceMappings": [{"EventSourceArn": "test",'
                 '"Enabled": "test", "BatchSize": "test",'
                 '"StartingPosition": "test"}]}')

        with patch('builtins.open', mock_open(read_data=jsonD), create=True):
            createEventMapping('development')

        mock_env.assert_called_once_with('development')
        mock_client.assert_called_once()
        mock_client().create_event_source_mapping.assert_has_calls([
            call(BatchSize='test',
                 Enabled='test',
                 EventSourceArn='test',
                 FunctionName='tester',
                 StartingPosition='test')
        ])
예제 #6
0
def main():

    if len(sys.argv) != 2:
        logger.warning('This script takes one, and only one, argument!')
        sys.exit(1)
    runType = sys.argv[1]

    if re.match(r'^(?:development|qa|production)', runType):
        logger.info('Deploying lambda to {} environment'.format(runType))
        setEnvVars(runType)
        subprocess.run([
            'lambda', 'deploy', '--config-file', 'run_config.yaml',
            '--requirements', 'requirements.txt'
        ])
        createEventMapping(runType)
        os.remove('run_config.yaml')

    elif re.match(r'^run-local', runType):
        logger.info('Running test locally with development environment')
        env = 'development'
        setEnvVars(env)
        subprocess.run(
            ['lambda', 'invoke', '-v', '--config-file', 'run_config.yaml'])
        os.remove('run_config.yaml')

    elif re.match(r'^build-(?:development|qa|production)', runType):
        env = runType.replace('build-', '')
        logger.info(
            'Building package for {} environment, will be in dist/'.format(
                env))  # noqa: E501
        setEnvVars(env)
        subprocess.run([
            'lambda', 'build', '--requirements', 'requirements.txt',
            '--config-file', 'run_config.yaml'
        ])
        os.remove('run_config.yaml')

    else:
        logger.error('Execution type not recognized! {}'.format(runType))
        raise InvalidExecutionType('{} is not a valid command'.format(runType))
예제 #7
0
 def test_event_permissions_err(self, mock_file):
     try:
         createEventMapping('development')
     except IOError:
         pass
     self.assertRaises(IOError)
예제 #8
0
 def test_event_missing_err(self, mock_file):
     try:
         createEventMapping('development')
     except FileNotFoundError:
         pass
     self.assertRaises(FileNotFoundError)