Beispiel #1
0
 def test_envVar_parsing(self, mock_env):
     m = mock_open()
     with patch('builtins.open', m, create=True):
         setEnvVars('development')
         mock_env.assert_called_once()
         confHandle = m()
         confHandle.write.assert_called()
 def test_envVar_success(self, mock_file, mock_env):
     setEnvVars('development')
     envCalls = [
         call('development', 'config/{}.yaml'),
         call('development', None)
     ]
     mock_env.assert_has_calls(envCalls)
 def test_envVar_parsing(self, mock_env):
     m = mock_open()
     with patch('builtins.open', m, create=True):
         setEnvVars('development')
         confHandle = m()
         confHandle.write.assert_has_calls([
             call('environment_variables:\n  jerry: hello\n  test: world\n')
         ])
Beispiel #4
0
def runProcess(runType, argList):
    """Executes the requested command through a subprocess call to the CLI.

    Arguments:
        runType {string} -- The current environment to load settings for.
        argList {array} -- An array of command line arguments that dictate
        the specific type of invocation being made to `python-lambda`
    """
    setEnvVars(runType)  # Creates the run_config.yaml file
    processArgs = ['lambda']
    processArgs.extend(argList)
    subprocess.run(processArgs)  # Executes the actual command
Beispiel #5
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))
Beispiel #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))
Beispiel #7
0
 def test_envVar_permissions(self, mock_file, mock_env):
     try:
         setEnvVars('development')
     except IOError:
         pass
     self.assertRaises(IOError)
Beispiel #8
0
 def test_envVar_success(self, mock_file, mock_env):
     setEnvVars('development')
     mock_env.assert_has_calls([call('development')])
 def test_missing_block(self, mock_copy, mock_env):
     setEnvVars('development')
     mock_env.assert_called_once()
     mock_copy.assert_called_once_with('config.yaml', 'run_config.yaml')