Пример #1
0
    def test_verify_ctx_template_file_param(self):

        ctx_mock = Mock()
        ctx_mock.default_map = {"template": "bar.txt"}
        expected_result_from_ctx = os.path.abspath("bar.txt")

        result = get_or_default_template_file_name(ctx_mock, None, _TEMPLATE_OPTION_DEFAULT_VALUE, include_build=True)
        self.assertEqual(result, expected_result_from_ctx)
Пример #2
0
    def test_must_return_abspath_of_user_provided_value(self):
        filename = "foo.txt"
        expected = os.path.abspath(filename)

        result = get_or_default_template_file_name(None,
                                                   None,
                                                   filename,
                                                   include_build=False)
        self.assertEqual(result, expected)
Пример #3
0
    def test_must_return_yaml_extension(self, os_mock):
        expected = "template.yaml"

        os_mock.path.exists.return_value = True
        os_mock.path.abspath.return_value = "absPath"

        result = get_or_default_template_file_name(None, None, _TEMPLATE_OPTION_DEFAULT_VALUE, include_build=False)
        self.assertEqual(result, "absPath")
        os_mock.path.abspath.assert_called_with(expected)
Пример #4
0
    def test_must_return_built_template(self, os_mock):
        expected = os.path.join(".aws-sam", "build", "template.yaml")

        os_mock.path.exists.return_value = True
        os_mock.path.join = os.path.join  # Use the real method
        os_mock.path.abspath.return_value = "absPath"

        result = get_or_default_template_file_name(None, None, _TEMPLATE_OPTION_DEFAULT_VALUE, include_build=True)
        self.assertEqual(result, "absPath")
        os_mock.path.abspath.assert_called_with(expected)
Пример #5
0
    def test_verify_ctx(self, os_mock):

        ctx = Mock()

        expected = os.path.join(".aws-sam", "build", "template.yaml")

        os_mock.path.exists.return_value = True
        os_mock.path.join = os.path.join  # Use the real method
        os_mock.path.abspath.return_value = "a/b/c/absPath"
        os_mock.path.dirname.return_value = "a/b/c"

        result = get_or_default_template_file_name(
            ctx, None, _TEMPLATE_OPTION_DEFAULT_VALUE, include_build=True)
        self.assertEqual(result, "a/b/c/absPath")
        self.assertEqual(ctx.samconfig_dir, "a/b/c")
        os_mock.path.abspath.assert_called_with(expected)