|
3 | 3 | from __future__ import division |
4 | 4 | from __future__ import absolute_import |
5 | 5 | import json |
6 | | -import os |
7 | | -import sys |
8 | 6 | import unittest |
9 | 7 |
|
10 | 8 | from mock import MagicMock |
|
15 | 13 | from stacker.variables import Variable |
16 | 14 | from ..factories import mock_context |
17 | 15 |
|
| 16 | + |
18 | 17 | RAW_JSON_TEMPLATE_PATH = 'stacker/tests/fixtures/cfn_template.json' |
19 | 18 | RAW_YAML_TEMPLATE_PATH = 'stacker/tests/fixtures/cfn_template.yaml' |
20 | 19 | RAW_J2_TEMPLATE_PATH = 'stacker/tests/fixtures/cfn_template.json.j2' |
21 | 20 |
|
22 | 21 |
|
23 | | -class TestRawBluePrintHelpers(unittest.TestCase): |
24 | | - """Test class for functions in module.""" |
25 | | - |
26 | | - def test_get_template_path_local_file(self): # noqa pylint: disable=invalid-name |
27 | | - """Verify get_template_path finding a file relative to CWD.""" |
28 | | - self.assertEqual(get_template_path(RAW_YAML_TEMPLATE_PATH), |
29 | | - RAW_YAML_TEMPLATE_PATH) |
30 | | - |
31 | | - def test_get_template_path_invalid_file(self): # noqa pylint: disable=invalid-name |
32 | | - """Verify get_template_path with an invalid filename.""" |
33 | | - self.assertEqual(get_template_path('afilenamethatdoesnotexist.txt'), |
34 | | - None) |
35 | | - |
36 | | - def test_get_template_path_file_in_syspath(self): # noqa pylint: disable=invalid-name |
37 | | - """Verify get_template_path with a file in sys.path. |
38 | | -
|
39 | | - This ensures templates are able to be retreived from remote packages. |
40 | | -
|
41 | | - """ |
42 | | - stacker_tests_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # noqa |
43 | | - old_sys_path = list(sys.path) |
44 | | - sys.path.append(stacker_tests_dir) |
45 | | - try: |
46 | | - self.assertEqual(get_template_path('fixtures/cfn_template.yaml'), |
47 | | - os.path.join(stacker_tests_dir, |
48 | | - 'fixtures/cfn_template.yaml')) |
49 | | - finally: |
50 | | - sys.path = old_sys_path |
51 | | - |
52 | | - def test_get_template_params(self): |
53 | | - """Verify get_template_params function operation.""" |
54 | | - template_dict = { |
55 | | - "AWSTemplateFormatVersion": "2010-09-09", |
56 | | - "Description": "TestTemplate", |
57 | | - "Parameters": { |
58 | | - "Param1": { |
59 | | - "Type": "String" |
60 | | - }, |
61 | | - "Param2": { |
62 | | - "Default": "default", |
63 | | - "Type": "CommaDelimitedList" |
64 | | - } |
65 | | - }, |
66 | | - "Resources": {} |
67 | | - } |
68 | | - template_params = { |
| 22 | +def test_get_template_path_local_file(tmpdir): |
| 23 | + """Verify get_template_path finding a file relative to CWD.""" |
| 24 | + |
| 25 | + template_path = tmpdir.join('cfn_template.json') |
| 26 | + template_path.ensure() |
| 27 | + |
| 28 | + with tmpdir.as_cwd(): |
| 29 | + result = get_template_path('cfn_template.json') |
| 30 | + assert template_path.samefile(result) |
| 31 | + |
| 32 | + |
| 33 | +def test_get_template_path_invalid_file(tmpdir): |
| 34 | + """Verify get_template_path with an invalid filename.""" |
| 35 | + |
| 36 | + with tmpdir.as_cwd(): |
| 37 | + assert get_template_path('cfn_template.json') is None |
| 38 | + |
| 39 | + |
| 40 | +def test_get_template_path_file_in_syspath(tmpdir, monkeypatch): |
| 41 | + """Verify get_template_path with a file in sys.path. |
| 42 | +
|
| 43 | + This ensures templates are able to be retrieved from remote packages. |
| 44 | +
|
| 45 | + """ |
| 46 | + |
| 47 | + template_path = tmpdir.join('cfn_template.json') |
| 48 | + template_path.ensure() |
| 49 | + |
| 50 | + monkeypatch.syspath_prepend(tmpdir) |
| 51 | + result = get_template_path(template_path.basename) |
| 52 | + assert template_path.samefile(result) |
| 53 | + |
| 54 | + |
| 55 | +def test_get_template_params(): |
| 56 | + """Verify get_template_params function operation.""" |
| 57 | + template_dict = { |
| 58 | + "AWSTemplateFormatVersion": "2010-09-09", |
| 59 | + "Description": "TestTemplate", |
| 60 | + "Parameters": { |
69 | 61 | "Param1": { |
70 | 62 | "Type": "String" |
71 | 63 | }, |
72 | 64 | "Param2": { |
73 | 65 | "Default": "default", |
74 | 66 | "Type": "CommaDelimitedList" |
75 | 67 | } |
| 68 | + }, |
| 69 | + "Resources": {} |
| 70 | + } |
| 71 | + template_params = { |
| 72 | + "Param1": { |
| 73 | + "Type": "String" |
| 74 | + }, |
| 75 | + "Param2": { |
| 76 | + "Default": "default", |
| 77 | + "Type": "CommaDelimitedList" |
76 | 78 | } |
77 | | - self.assertEqual(get_template_params(template_dict), template_params) |
| 79 | + } |
| 80 | + |
| 81 | + assert get_template_params(template_dict) == template_params |
78 | 82 |
|
79 | 83 |
|
80 | 84 | class TestBlueprintRendering(unittest.TestCase): |
|
0 commit comments