OLD | NEW |
1 # This file is part of the Juju GUI, which lets users view and manage Juju | 1 # This file is part of the Juju GUI, which lets users view and manage Juju |
2 # environments within a graphical interface (https://launchpad.net/juju-gui). | 2 # environments within a graphical interface (https://launchpad.net/juju-gui). |
3 # Copyright (C) 2012-2013 Canonical Ltd. | 3 # Copyright (C) 2012-2013 Canonical Ltd. |
4 # | 4 # |
5 # This program is free software: you can redistribute it and/or modify it under | 5 # This program is free software: you can redistribute it and/or modify it under |
6 # the terms of the GNU Affero General Public License version 3, as published by | 6 # the terms of the GNU Affero General Public License version 3, as published by |
7 # the Free Software Foundation. | 7 # the Free Software Foundation. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, but WITHOUT | 9 # This program is distributed in the hope that it will be useful, but WITHOUT |
10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | 10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
(...skipping 16 matching lines...) Expand all Loading... |
27 import charmhelpers | 27 import charmhelpers |
28 import mock | 28 import mock |
29 from shelltoolbox import environ | 29 from shelltoolbox import environ |
30 import tempita | 30 import tempita |
31 import yaml | 31 import yaml |
32 | 32 |
33 from utils import ( | 33 from utils import ( |
34 API_PORT, | 34 API_PORT, |
35 JUJU_GUI_DIR, | 35 JUJU_GUI_DIR, |
36 JUJU_PEM, | 36 JUJU_PEM, |
37 SERVER_DEPENDENCIES, | |
38 WEB_PORT, | 37 WEB_PORT, |
39 _get_by_attr, | 38 _get_by_attr, |
40 cmd_log, | 39 cmd_log, |
41 compute_build_dir, | 40 compute_build_dir, |
42 download_release, | 41 download_release, |
43 fetch_gui_release, | 42 fetch_gui_release, |
44 first_path_in_dir, | 43 first_path_in_dir, |
45 get_api_address, | 44 get_api_address, |
46 get_launchpad_release, | 45 get_launchpad_release, |
47 get_npm_cache_archive_url, | 46 get_npm_cache_archive_url, |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 self.actions, [charmhelpers.RESTART, charmhelpers.RESTART]) | 970 self.actions, [charmhelpers.RESTART, charmhelpers.RESTART]) |
972 | 971 |
973 def test_stop_haproxy_apache(self): | 972 def test_stop_haproxy_apache(self): |
974 stop_haproxy_apache() | 973 stop_haproxy_apache() |
975 self.assertEqual(self.svc_ctl_call_count, 2) | 974 self.assertEqual(self.svc_ctl_call_count, 2) |
976 self.assertEqual(self.service_names, ['haproxy', 'apache2']) | 975 self.assertEqual(self.service_names, ['haproxy', 'apache2']) |
977 self.assertEqual(self.actions, [charmhelpers.STOP, charmhelpers.STOP]) | 976 self.assertEqual(self.actions, [charmhelpers.STOP, charmhelpers.STOP]) |
978 | 977 |
979 def test_install_builtin_server(self): | 978 def test_install_builtin_server(self): |
980 install_builtin_server() | 979 install_builtin_server() |
981 # The function executes one "pip install" call for each dependency, and | 980 # Two run calls are executed: one for the dependencies, one for the |
982 # a final "python setup.py" call for the GUI server itself. | 981 # server itself. |
983 self.assertEqual(self.run_call_count, len(SERVER_DEPENDENCIES) + 1) | 982 self.assertEqual(2, self.run_call_count) |
984 | 983 |
985 def test_write_builtin_server_startup(self): | 984 def test_write_builtin_server_startup(self): |
986 write_builtin_server_startup( | 985 write_builtin_server_startup( |
987 JUJU_GUI_DIR, self.ssl_cert_path, serve_tests=True, insecure=True) | 986 JUJU_GUI_DIR, self.ssl_cert_path, serve_tests=True, insecure=True) |
988 guiserver_conf = self.files['guiserver.conf'] | 987 guiserver_conf = self.files['guiserver.conf'] |
989 self.assertIn('description "GUIServer"', guiserver_conf) | 988 self.assertIn('description "GUIServer"', guiserver_conf) |
990 self.assertIn('--logging="info"', guiserver_conf) | 989 self.assertIn('--logging="info"', guiserver_conf) |
991 self.assertIn('--apiurl="wss://127.0.0.1:8080/ws"', guiserver_conf) | 990 self.assertIn('--apiurl="wss://127.0.0.1:8080/ws"', guiserver_conf) |
992 self.assertIn('--apiversion="python"', guiserver_conf) | 991 self.assertIn('--apiversion="python"', guiserver_conf) |
993 self.assertIn( | 992 self.assertIn( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 | 1092 |
1094 def test_write_gui_config_with_button(self): | 1093 def test_write_gui_config_with_button(self): |
1095 write_gui_config( | 1094 write_gui_config( |
1096 False, 'This is login help.', False, False, self.charmworld_url, | 1095 False, 'This is login help.', False, False, self.charmworld_url, |
1097 self.build_dir, sandbox=True, show_get_juju_button=True, | 1096 self.build_dir, sandbox=True, show_get_juju_button=True, |
1098 config_js_path='config') | 1097 config_js_path='config') |
1099 self.assertIn('showGetJujuButton: true', self.files['config']) | 1098 self.assertIn('showGetJujuButton: true', self.files['config']) |
1100 | 1099 |
1101 | 1100 |
1102 @mock.patch('utils.run') | 1101 @mock.patch('utils.run') |
| 1102 @mock.patch('utils.log') |
| 1103 @mock.patch('utils.cmd_log', mock.Mock()) |
| 1104 @mock.patch('utils.su', mock.MagicMock()) |
| 1105 class TestInstallBuiltinServer(unittest.TestCase): |
| 1106 |
| 1107 def test_call(self, mock_log, mock_run): |
| 1108 # The builtin server its correctly installed. |
| 1109 install_builtin_server() |
| 1110 charm_dir = os.path.abspath( |
| 1111 os.path.join(os.path.dirname(__file__), '..')) |
| 1112 mock_log.assert_has_calls([ |
| 1113 mock.call('Installing the builtin server dependencies.'), |
| 1114 mock.call('Installing the builtin server.'), |
| 1115 ]) |
| 1116 mock_run.assert_has_calls([ |
| 1117 mock.call( |
| 1118 'pip', 'install', '--no-index', '--no-dependencies', |
| 1119 '--find-links', 'file:///{}/deps'.format(charm_dir), |
| 1120 '-r', os.path.join(charm_dir, 'server-requirements.pip')), |
| 1121 mock.call( |
| 1122 '/usr/bin/python', |
| 1123 os.path.join(charm_dir, 'server', 'setup.py'), 'install') |
| 1124 ]) |
| 1125 |
| 1126 |
| 1127 @mock.patch('utils.run') |
1103 @mock.patch('utils.cmd_log', mock.Mock()) | 1128 @mock.patch('utils.cmd_log', mock.Mock()) |
1104 @mock.patch('utils.log', mock.Mock()) | 1129 @mock.patch('utils.log', mock.Mock()) |
1105 @mock.patch('utils.su', mock.MagicMock()) | 1130 @mock.patch('utils.su', mock.MagicMock()) |
1106 class TestRemoveApacheSetup(unittest.TestCase): | 1131 class TestRemoveApacheSetup(unittest.TestCase): |
1107 | 1132 |
1108 def test_existing_configuration(self, mock_run): | 1133 def test_existing_configuration(self, mock_run): |
1109 # The Apache configuration is cleaned up if previously set up. | 1134 # The Apache configuration is cleaned up if previously set up. |
1110 apache_site = tempfile.mkdtemp() | 1135 apache_site = tempfile.mkdtemp() |
1111 apache_ports = os.path.join(apache_site, 'ports.conf') | 1136 apache_ports = os.path.join(apache_site, 'ports.conf') |
1112 self.addCleanup(shutil.rmtree, apache_site) | 1137 self.addCleanup(shutil.rmtree, apache_site) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 | 1232 |
1208 class FauxLaunchpad(object): | 1233 class FauxLaunchpad(object): |
1209 projects = {'juju-gui': FauxProject()} | 1234 projects = {'juju-gui': FauxProject()} |
1210 | 1235 |
1211 url = get_npm_cache_archive_url(Launchpad=FauxLaunchpadFactory()) | 1236 url = get_npm_cache_archive_url(Launchpad=FauxLaunchpadFactory()) |
1212 self.assertEqual(url, 'http://launchpad.example/path/to/cache/file') | 1237 self.assertEqual(url, 'http://launchpad.example/path/to/cache/file') |
1213 | 1238 |
1214 | 1239 |
1215 if __name__ == '__main__': | 1240 if __name__ == '__main__': |
1216 unittest.main(verbosity=2) | 1241 unittest.main(verbosity=2) |
OLD | NEW |