def test_with_overrides_value(self): """ Given values for the variables from user specified overrides """ expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", # This value is coming from user passed environment variable "AWS_DEFAULT_REGION": "user-specified-region", "variable2": "mystring", # Value coming from the overrides "variable1": "variable1 value from overrides", "list_var": "list value coming from overrides", "dict_var": "", "none_var": "", "true_var": "true", "false_var": "false", } environ = EnvironmentVariables( self.memory, self.timeout, self.handler, variables=self.variables, shell_env_values=self.shell_env, override_values=self.override, ) self.assertEqual(environ.resolve(), expected)
def test_with_no_additional_variables_extensions_preview( self, PreviewEnabledMock): """ Test assuming user has *not* passed any environment variables. Only AWS variables should be setup """ PreviewEnabledMock.return_value = True expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_REGION": "some region", "AWS_DEFAULT_REGION": "some region", "AWS_ACCESS_KEY_ID": "some key", "AWS_SECRET_ACCESS_KEY": "some other secret", "AWS_SESSION_TOKEN": "some other token", "AWS_LAMBDA_FUNCTION_NAME": "name", "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST", "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", } environ = EnvironmentVariables(self.name, self.memory, self.timeout, self.handler, aws_creds=self.aws_creds) result = environ.resolve() # With no additional environment variables, resolve() should just return all AWS variables self.assertEqual(result, expected)
def test_with_no_additional_variables(self): """ Test assuming user has *not* passed any environment variables. Only AWS variables should be setup """ expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_REGION": "some region", "AWS_DEFAULT_REGION": "some region", "AWS_ACCESS_KEY_ID": "some key", "AWS_SECRET_ACCESS_KEY": "some other secret", "AWS_SESSION_TOKEN": "some other token", } environ = EnvironmentVariables(self.memory, self.timeout, self.handler, aws_creds=self.aws_creds) result = environ.resolve() # With no additional environment variables, resolve() should just return all AWS variables self.assertEqual(result, expected)
def test_with_overrides_value(self): """ Given values for the variables from user specified overrides """ expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", # This value is coming from user passed environment variable "AWS_DEFAULT_REGION": "user-specified-region", "variable2": "mystring", # Value coming from the overrides "variable1": "variable1 value from overrides", "list_var": "list value coming from overrides", "dict_var": "", "none_var": "", "true_var": "true", "false_var": "false" } environ = EnvironmentVariables(self.memory, self.timeout, self.handler, variables=self.variables, shell_env_values=self.shell_env, override_values=self.override) self.assertEquals(environ.resolve(), expected)
def test_with_only_default_values_for_variables(self): """ Given only environment variable values, without any shell env values or overridden values """ expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", # This value is coming from user passed environment variable "AWS_DEFAULT_REGION": "user-specified-region", "variable1": "1", "variable2": "mystring", "list_var": "", "dict_var": "", "none_var": "", "true_var": "true", "false_var": "false" } environ = EnvironmentVariables(self.memory, self.timeout, self.handler, variables=self.variables) self.assertEquals(environ.resolve(), expected)
def test_with_shell_env_value(self): """ Given values for the variables from shell environment """ expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_LAMBDA_FUNCTION_NAME": self.name, "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST", "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", # This value is coming from user passed environment variable "AWS_DEFAULT_REGION": "user-specified-region", # Value coming from the shell "variable1": "variable1 value from shell_env", "variable2": "mystring", "list_var": "", "dict_var": "", "none_var": "", "true_var": "true", "false_var": "false", } environ = EnvironmentVariables( self.name, self.memory, self.timeout, self.handler, variables=self.variables, shell_env_values=self.shell_env, ) self.assertEqual(environ.resolve(), expected)
def test_with_only_default_values_for_variables_extensions_preview( self, PreviewEnabledMock): """ Given only environment variable values, without any shell env values or overridden values """ PreviewEnabledMock.return_value = True expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", "AWS_LAMBDA_FUNCTION_NAME": "name", "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST", "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", # This value is coming from user passed environment variable "AWS_DEFAULT_REGION": "user-specified-region", "variable1": "1", "variable2": "mystring", "list_var": "", "dict_var": "", "none_var": "", "true_var": "true", "false_var": "false", } environ = EnvironmentVariables(self.name, self.memory, self.timeout, self.handler, variables=self.variables) self.assertEqual(environ.resolve(), expected)
def test_with_no_additional_variables(self): """ Test assuming user has *not* passed any environment variables. Only AWS variables should be setup """ expected = { "AWS_SAM_LOCAL": "true", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024", "AWS_LAMBDA_FUNCTION_TIMEOUT": "123", "AWS_LAMBDA_FUNCTION_HANDLER": "handler", "AWS_REGION": "some region", "AWS_DEFAULT_REGION": "some region", "AWS_ACCESS_KEY_ID": "some key", "AWS_SECRET_ACCESS_KEY": "some other secret", "AWS_SESSION_TOKEN": "some other token" } environ = EnvironmentVariables(self.memory, self.timeout, self.handler, aws_creds=self.aws_creds) result = environ.resolve() # With no additional environment variables, resolve() should just return all AWS variables self.assertEquals(result, expected)