def test_get_ssm_parameter_missing_parameter_raises_client_error(self, mock_boto_client): mock_ssm = MagicMock() mock_ssm.get_parameters.side_effect = ClientError({}, "") mock_boto_client.return_value = mock_ssm @extract_from_ssm([SSMParameter("")]) def handler(key=None): return key with self.assertRaises(ClientError): handler()
def test_get_ssm_parameter_empty_key_container_raises_key_error(self, mock_boto_client): mock_ssm = MagicMock() mock_ssm.get_parameters.return_value = { } mock_boto_client.return_value = mock_ssm @extract_from_ssm([SSMParameter("")]) def handler(key=None): return key with self.assertRaises(KeyError): handler()
def test_get_valid_ssm_parameters(self, mock_boto_client): mock_ssm = MagicMock() mock_ssm.get_parameters.return_value = { "Parameters": [ { "Name": "key2", "Value": "test2" }, { "Name": "key1", "Value": "test1" } ] } mock_boto_client.return_value = mock_ssm @extract_from_ssm([SSMParameter("key1", "key1"), SSMParameter("key2", "key2")]) def handler(key1=None, key2=None): return [key1, key2] self.assertEqual(handler(), ["test1", "test2"])
def test_get_valid_ssm_parameter_custom_name(self, mock_boto_client): mock_ssm = MagicMock() mock_ssm.get_parameters.return_value = { "Parameters": [ { "Name": "key", "Value": "tests" } ] } mock_boto_client.return_value = mock_ssm @extract_from_ssm([SSMParameter("key", "custom")]) def handler(custom=None): return custom self.assertEqual(handler(), "tests")
def test_can_not_add_non_pythonic_var_name_to_ssm_parameter(self): param = SSMParameter("tests", "with space") with self.assertRaises(SyntaxError): param.get_var_name()