summaryrefslogtreecommitdiff
path: root/scripts/emit_releases_file/test_write_bash_script.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/emit_releases_file/test_write_bash_script.py')
-rw-r--r--scripts/emit_releases_file/test_write_bash_script.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/scripts/emit_releases_file/test_write_bash_script.py b/scripts/emit_releases_file/test_write_bash_script.py
new file mode 100644
index 0000000..e074d5b
--- /dev/null
+++ b/scripts/emit_releases_file/test_write_bash_script.py
@@ -0,0 +1,68 @@
1from emit_releases_file import write_releases_dictionary_to_bash
2
3import os
4import mock
5from mock import mock_open
6from six import PY2
7
8import pytest
9
10if PY2:
11 BUILTINS_OPEN = "__builtin__.open"
12else:
13 BUILTINS_OPEN = "builtins.open"
14
15
16def test_empty_relases_dictionary_fails():
17 assert (not write_releases_dictionary_to_bash({}, ""))
18
19
20@pytest.fixture
21def releases_dictionary():
22 return {
23 'undercloud_install_release': 'queens',
24 'undercloud_install_hash': 'current-tripleo',
25 'undercloud_target_release': 'master',
26 'undercloud_target_hash': 'current-tripleo',
27 'overcloud_deploy_release': 'master',
28 'overcloud_deploy_hash': 'current-tripleo',
29 'overcloud_target_release': 'master',
30 'overcloud_target_hash': 'current-tripleo',
31 }
32
33
34@pytest.mark.parametrize('deleted_key', [
35 'undercloud_install_release',
36 'undercloud_install_hash',
37 'undercloud_target_release',
38 'undercloud_target_hash',
39 'overcloud_deploy_release',
40 'overcloud_deploy_hash',
41 'overcloud_target_release',
42 'overcloud_target_hash',
43])
44def test_missing_key_fails(releases_dictionary, deleted_key):
45 wrong_releases_dictionary = releases_dictionary.pop(deleted_key)
46 assert (not write_releases_dictionary_to_bash(wrong_releases_dictionary,
47 ""))
48
49
50@mock.patch(BUILTINS_OPEN, new_callable=mock_open)
51def test_open_exception_fails(mock, releases_dictionary):
52 bash_script = '/foo/bar.sh'
53 mock.side_effect = IOError
54 assert (not write_releases_dictionary_to_bash(releases_dictionary,
55 bash_script))
56
57
58@mock.patch(BUILTINS_OPEN, new_callable=mock_open)
59def test_output_is_sourceable(mock, releases_dictionary):
60 bash_script = '/foo/bar.sh'
61 assert (write_releases_dictionary_to_bash(releases_dictionary,
62 bash_script))
63 mock.assert_called_once_with(bash_script, 'w')
64 handle = mock()
65 args, _ = handle.write.call_args
66 written_content = args[0]
67 # TODO: check environment variables
68 assert (0 == os.system(written_content))