-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into missing-allowable-types
- Loading branch information
Showing
5 changed files
with
325 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
import sys | ||
import os | ||
from test.testlib.testcase import BaseTestCase | ||
from mock import patch, MagicMock, mock_open | ||
import cfnlint.helpers | ||
import json | ||
|
||
|
||
class TestDownloadsMetadata(BaseTestCase): | ||
"""Test Downloads Metadata""" | ||
|
||
@patch('cfnlint.helpers.os.path.exists') | ||
def test_no_file(self, mock_path_exists): | ||
"""Test success run""" | ||
|
||
mock_path_exists.return_value = False | ||
|
||
filename = 'foo.bar' | ||
|
||
result = cfnlint.helpers.load_metadata(filename) | ||
|
||
self.assertEqual(result, {}) | ||
|
||
@patch('cfnlint.helpers.os.path.exists') | ||
def test_load_metadata(self, mock_path_exists): | ||
"""Test success run""" | ||
|
||
mock_path_exists.return_value = True | ||
|
||
filename = 'foo.bar' | ||
file_contents = { | ||
'etag': 'foo' | ||
} | ||
|
||
if sys.version_info.major == 3: | ||
builtin_module_name = 'builtins' | ||
else: | ||
builtin_module_name = '__builtin__' | ||
|
||
mo = mock_open(read_data=json.dumps(file_contents)) | ||
with patch('{}.open'.format(builtin_module_name), mo) as mock_builtin_open: | ||
result = cfnlint.helpers.load_metadata(filename) | ||
|
||
self.assertEqual(result, file_contents) | ||
|
||
@patch('cfnlint.helpers.os.path.exists') | ||
@patch('cfnlint.helpers.os.path.dirname') | ||
@patch('cfnlint.helpers.os.mkdir') | ||
@patch('cfnlint.helpers.json.dump') | ||
def test_save_download_metadata(self, mock_json_dump, mock_mkdir, mock_dirname, mock_path_exists): | ||
"""Test success run""" | ||
|
||
filename = 'foo.bar' | ||
filedir = 'foobardir' | ||
file_contents = { | ||
'etag': 'foo' | ||
} | ||
|
||
mock_path_exists.return_value = False | ||
mock_dirname.return_value = filedir | ||
|
||
if sys.version_info.major == 3: | ||
builtin_module_name = 'builtins' | ||
else: | ||
builtin_module_name = '__builtin__' | ||
|
||
mo = mock_open() | ||
with patch('{}.open'.format(builtin_module_name), mo) as mock_builtin_open: | ||
cfnlint.helpers.save_metadata(file_contents, filename) | ||
mock_mkdir.assert_called_with(filedir) | ||
mock_json_dump.assert_called_once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.