Exemple #1
0
    def test_must_raise_if_docker_not_found(self, test_name, error_docker_throws):
        client = Mock()

        client.ping.side_effect = error_docker_throws

        with self.assertRaises(InvokeContextException) as ex_ctx:
            InvokeContext._check_docker_connectivity(client)

        msg = str(ex_ctx.exception)
        self.assertEquals(msg, "Running AWS SAM projects locally requires Docker. Have you got it installed?")
    def test_must_read_from_necessary_files(self, SamFunctionProviderMock):
        function_provider = Mock()

        SamFunctionProviderMock.return_value = function_provider

        template_file = "template_file"
        env_vars_file = "env_vars_file"
        log_file = "log_file"

        invoke_context = InvokeContext(template_file=template_file,
                                       function_identifier="id",
                                       env_vars_file=env_vars_file,
                                       docker_volume_basedir="volumedir",
                                       docker_network="network",
                                       log_file=log_file,
                                       skip_pull_image=True,
                                       aws_profile="profile",
                                       debug_port=1111,
                                       debugger_path="path-to-debugger",
                                       debug_args='args',
                                       aws_region="region",
                                       parameter_overrides={})

        template_dict = "template_dict"
        invoke_context._get_template_data = Mock()
        invoke_context._get_template_data.return_value = template_dict

        env_vars_value = "env_vars_value"
        invoke_context._get_env_vars_value = Mock()
        invoke_context._get_env_vars_value.return_value = env_vars_value

        log_file_handle = "handle"
        invoke_context._setup_log_file = Mock()
        invoke_context._setup_log_file.return_value = log_file_handle

        debug_context_mock = Mock()
        invoke_context._get_debug_context = Mock()
        invoke_context._get_debug_context.return_value = debug_context_mock

        invoke_context._check_docker_connectivity = Mock()

        # Call Enter method manually for testing purposes
        result = invoke_context.__enter__()
        self.assertTrue(result is invoke_context,
                        "__enter__() must return self")

        self.assertEquals(invoke_context._template_dict, template_dict)
        self.assertEquals(invoke_context._function_provider, function_provider)
        self.assertEquals(invoke_context._env_vars_value, env_vars_value)
        self.assertEquals(invoke_context._log_file_handle, log_file_handle)
        self.assertEquals(invoke_context._debug_context, debug_context_mock)

        invoke_context._get_template_data.assert_called_with(template_file)
        SamFunctionProviderMock.assert_called_with(template_dict,
                                                   {"AWS::Region": "region"})
        invoke_context._get_env_vars_value.assert_called_with(env_vars_file)
        invoke_context._setup_log_file.assert_called_with(log_file)
        invoke_context._get_debug_context.assert_called_once_with(
            1111, "args", "path-to-debugger")
        invoke_context._check_docker_connectivity.assert_called_with()
    def test_must_read_from_necessary_files(self, SamFunctionProviderMock):
        function_provider = Mock()

        SamFunctionProviderMock.return_value = function_provider

        template_file = "template_file"
        env_vars_file = "env_vars_file"
        log_file = "log_file"

        invoke_context = InvokeContext(template_file=template_file,
                                       function_identifier="id",
                                       env_vars_file=env_vars_file,
                                       debug_port=123,
                                       debug_args="args",
                                       docker_volume_basedir="volumedir",
                                       docker_network="network",
                                       log_file=log_file,
                                       skip_pull_image=True,
                                       aws_profile="profile")

        template_dict = "template_dict"
        invoke_context._get_template_data = Mock()
        invoke_context._get_template_data.return_value = template_dict

        env_vars_value = "env_vars_value"
        invoke_context._get_env_vars_value = Mock()
        invoke_context._get_env_vars_value.return_value = env_vars_value

        log_file_handle = "handle"
        invoke_context._setup_log_file = Mock()
        invoke_context._setup_log_file.return_value = log_file_handle

        invoke_context._check_docker_connectivity = Mock()

        # Call Enter method manually for testing purposes
        result = invoke_context.__enter__()
        self.assertTrue(result is invoke_context,
                        "__enter__() must return self")

        self.assertEquals(invoke_context._template_dict, template_dict)
        self.assertEquals(invoke_context._function_provider, function_provider)
        self.assertEquals(invoke_context._env_vars_value, env_vars_value)
        self.assertEquals(invoke_context._log_file_handle, log_file_handle)

        invoke_context._get_template_data.assert_called_with(template_file)
        SamFunctionProviderMock.assert_called_with(template_dict)
        invoke_context._get_env_vars_value.assert_called_with(env_vars_file)
        invoke_context._setup_log_file.assert_called_with(log_file)
        invoke_context._check_docker_connectivity.assert_called_with()
    def test_must_call_ping_with_docker_client_from_env(self, docker_mock):
        client = Mock()
        docker_mock.from_env.return_value = client

        InvokeContext._check_docker_connectivity()
        client.ping.assert_called_with()
 def test_must_call_ping(self):
     client = Mock()
     InvokeContext._check_docker_connectivity(client)
     client.ping.assert_called_with()