LEFT | RIGHT |
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 charmworld_url=self.charmworld_url) | 987 charmworld_url=self.charmworld_url) |
989 guiserver_conf = self.files['guiserver.conf'] | 988 guiserver_conf = self.files['guiserver.conf'] |
990 self.assertIn('description "GUIServer"', guiserver_conf) | 989 self.assertIn('description "GUIServer"', guiserver_conf) |
991 self.assertIn('--logging="info"', guiserver_conf) | 990 self.assertIn('--logging="info"', guiserver_conf) |
992 self.assertIn('--apiurl="wss://127.0.0.1:8080/ws"', guiserver_conf) | 991 self.assertIn('--apiurl="wss://127.0.0.1:8080/ws"', guiserver_conf) |
993 self.assertIn('--apiversion="python"', guiserver_conf) | 992 self.assertIn('--apiversion="python"', guiserver_conf) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 mock_legacy_juju.return_value = True | 1057 mock_legacy_juju.return_value = True |
1059 write_gui_config( | 1058 write_gui_config( |
1060 False, 'This is login help.', True, True, self.charmworld_url, | 1059 False, 'This is login help.', True, True, self.charmworld_url, |
1061 self.build_dir, config_js_path='config', | 1060 self.build_dir, config_js_path='config', |
1062 password='kumquat') | 1061 password='kumquat') |
1063 js_conf = self.files['config'] | 1062 js_conf = self.files['config'] |
1064 self.assertIn('user: "admin"', js_conf) | 1063 self.assertIn('user: "admin"', js_conf) |
1065 self.assertIn('password: "kumquat"', js_conf) | 1064 self.assertIn('password: "kumquat"', js_conf) |
1066 | 1065 |
1067 @mock.patch('utils.legacy_juju') | 1066 @mock.patch('utils.legacy_juju') |
| 1067 def test_write_gui_config_default_sandbox_backend(self, mock_legacy_juju): |
| 1068 mock_legacy_juju.return_value = True |
| 1069 write_gui_config( |
| 1070 False, 'This is login help.', True, True, self.charmworld_url, |
| 1071 self.build_dir, config_js_path='config', |
| 1072 password='kumquat', sandbox=True) |
| 1073 js_conf = self.files['config'] |
| 1074 # Because this is sandbox, the apiBackend is always go, even though it |
| 1075 # is legacy_juju. |
| 1076 self.assertIn('apiBackend: "go"', js_conf) |
| 1077 |
| 1078 @mock.patch('utils.legacy_juju') |
1068 def test_write_gui_config_default_go_password(self, mock_legacy_juju): | 1079 def test_write_gui_config_default_go_password(self, mock_legacy_juju): |
1069 mock_legacy_juju.return_value = False | 1080 mock_legacy_juju.return_value = False |
1070 write_gui_config( | 1081 write_gui_config( |
1071 False, 'This is login help.', True, True, self.charmworld_url, | 1082 False, 'This is login help.', True, True, self.charmworld_url, |
1072 self.build_dir, config_js_path='config', | 1083 self.build_dir, config_js_path='config', |
1073 password='kumquat') | 1084 password='kumquat') |
1074 js_conf = self.files['config'] | 1085 js_conf = self.files['config'] |
1075 self.assertIn('user: "user-admin"', js_conf) | 1086 self.assertIn('user: "user-admin"', js_conf) |
1076 self.assertIn('password: "kumquat"', js_conf) | 1087 self.assertIn('password: "kumquat"', js_conf) |
1077 | 1088 |
(...skipping 17 matching lines...) Expand all Loading... |
1095 self.build_dir, sandbox=True, default_viewmode='fullscreen', | 1106 self.build_dir, sandbox=True, default_viewmode='fullscreen', |
1096 config_js_path='config') | 1107 config_js_path='config') |
1097 self.assertIn('defaultViewmode: "fullscreen"', self.files['config']) | 1108 self.assertIn('defaultViewmode: "fullscreen"', self.files['config']) |
1098 | 1109 |
1099 def test_write_gui_config_with_button(self): | 1110 def test_write_gui_config_with_button(self): |
1100 write_gui_config( | 1111 write_gui_config( |
1101 False, 'This is login help.', False, False, self.charmworld_url, | 1112 False, 'This is login help.', False, False, self.charmworld_url, |
1102 self.build_dir, sandbox=True, show_get_juju_button=True, | 1113 self.build_dir, sandbox=True, show_get_juju_button=True, |
1103 config_js_path='config') | 1114 config_js_path='config') |
1104 self.assertIn('showGetJujuButton: true', self.files['config']) | 1115 self.assertIn('showGetJujuButton: true', self.files['config']) |
| 1116 |
| 1117 |
| 1118 @mock.patch('utils.run') |
| 1119 @mock.patch('utils.log') |
| 1120 @mock.patch('utils.cmd_log', mock.Mock()) |
| 1121 @mock.patch('utils.su', mock.MagicMock()) |
| 1122 class TestInstallBuiltinServer(unittest.TestCase): |
| 1123 |
| 1124 def test_call(self, mock_log, mock_run): |
| 1125 # The builtin server its correctly installed. |
| 1126 install_builtin_server() |
| 1127 charm_dir = os.path.abspath( |
| 1128 os.path.join(os.path.dirname(__file__), '..')) |
| 1129 mock_log.assert_has_calls([ |
| 1130 mock.call('Installing the builtin server dependencies.'), |
| 1131 mock.call('Installing the builtin server.'), |
| 1132 ]) |
| 1133 mock_run.assert_has_calls([ |
| 1134 mock.call( |
| 1135 'pip', 'install', '--no-index', '--no-dependencies', |
| 1136 '--find-links', 'file:///{}/deps'.format(charm_dir), |
| 1137 '-r', os.path.join(charm_dir, 'server-requirements.pip')), |
| 1138 mock.call( |
| 1139 '/usr/bin/python', |
| 1140 os.path.join(charm_dir, 'server', 'setup.py'), 'install') |
| 1141 ]) |
1105 | 1142 |
1106 | 1143 |
1107 @mock.patch('utils.run') | 1144 @mock.patch('utils.run') |
1108 @mock.patch('utils.cmd_log', mock.Mock()) | 1145 @mock.patch('utils.cmd_log', mock.Mock()) |
1109 @mock.patch('utils.log', mock.Mock()) | 1146 @mock.patch('utils.log', mock.Mock()) |
1110 @mock.patch('utils.su', mock.MagicMock()) | 1147 @mock.patch('utils.su', mock.MagicMock()) |
1111 class TestRemoveApacheSetup(unittest.TestCase): | 1148 class TestRemoveApacheSetup(unittest.TestCase): |
1112 | 1149 |
1113 def test_existing_configuration(self, mock_run): | 1150 def test_existing_configuration(self, mock_run): |
1114 # The Apache configuration is cleaned up if previously set up. | 1151 # The Apache configuration is cleaned up if previously set up. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 | 1249 |
1213 class FauxLaunchpad(object): | 1250 class FauxLaunchpad(object): |
1214 projects = {'juju-gui': FauxProject()} | 1251 projects = {'juju-gui': FauxProject()} |
1215 | 1252 |
1216 url = get_npm_cache_archive_url(Launchpad=FauxLaunchpadFactory()) | 1253 url = get_npm_cache_archive_url(Launchpad=FauxLaunchpadFactory()) |
1217 self.assertEqual(url, 'http://launchpad.example/path/to/cache/file') | 1254 self.assertEqual(url, 'http://launchpad.example/path/to/cache/file') |
1218 | 1255 |
1219 | 1256 |
1220 if __name__ == '__main__': | 1257 if __name__ == '__main__': |
1221 unittest.main(verbosity=2) | 1258 unittest.main(verbosity=2) |
LEFT | RIGHT |