@mock.patch('tethys_apps.cli.install_commands.configure_services')
@mock.patch('tethys_apps.cli.cli_colors.pretty_output')
@mock.patch('tethys_apps.cli.install_commands.open_file')
@mock.patch('tethys_apps.cli.install_commands.os')
def test_run_portal_install(self, mock_os, mock_open_file, mock_pretty_output, mock_configure_services):
    app_name = 'foo'
    services = {'persistent': {'test_setting': 'test_service'}}
    portal_options_services = {'apps': {app_name: {'services': services}}}
    portal_options_empty_services = {'apps': {app_name: {'services': ''}}}
    portal_options_no_services = {'apps': {app_name: ''}}
    mock_open_file.side_effect = [portal_options_services, portal_options_empty_services, portal_options_no_services]
    mock_os.path.exists.return_value = True
    self.assertTrue(install_commands.run_portal_install(None, app_name))
    mock_configure_services.assert_called_with(services, app_name)
    self.assertFalse(install_commands.run_portal_install(None, app_name))
    self.assertFalse(install_commands.run_portal_install(None, app_name))
    po_call_args = mock_pretty_output().__enter__().write.call_args_list
    self.assertIn(f'No app configuration found for app: {app_name}', po_call_args[2][0][0])
    self.assertIn('No apps configuration found in portal config file.', po_call_args[4][0][0])
@mock.patch('tethys_apps.cli.install_commands.configure_services')
@mock.patch('tethys_apps.cli.cli_colors.pretty_output')
@mock.patch('tethys_apps.cli.install_commands.open_file')
@mock.patch('tethys_apps.cli.install_commands.os')
def test_run_portal_install(self, mock_os, mock_open_file, mock_pretty_output, mock_configure_services):
    app_name = 'foo'
    services = {'persistent': {'test_setting': 'test_service'}}
    portal_options_services = {'apps': {app_name: {'services': services}}}
    portal_options_empty_services = {'apps': {app_name: {'services': }}}
    portal_options_no_services = {'apps': {app_name: }}
    mock_open_file.side_effect = [portal_options_services, portal_options_empty_services, portal_options_no_services]
    mock_os.path.exists.return_value = True
    self.assertTrue(install_commands.run_portal_install(None, app_name))
    mock_configure_services.assert_called_with(services, app_name)
    self.assertFalse(install_commands.run_portal_install(None, app_name))
    self.assertFalse(install_commands.run_portal_install(None, app_name))
    po_call_args = mock_pretty_output().__enter__().write.call_args_list
    self.assertIn(f'No app configuration found for app: {app_name}', po_call_args[2][0][0])
    self.assertIn('No apps configuration found in portal config file.', po_call_args[4][0][0])