def test_show_remote(self): """ should show remote url """ remote_connection = environ.RemoteConnection( url='http://my-fake.url', active=True ) support.run_remote_command( command='open @examples:hello_cauldron', remote_connection=remote_connection ) project = cauldron.project.internal_project url = project.make_remote_url(remote_connection.url) with patch('webbrowser.open') as func: r = support.run_remote_command( command='show', remote_connection=remote_connection ) self.assertFalse(r.failed, 'should not have failed') func.assert_called_once_with(url) support.run_command('close')
def run_remote_command(command: str, app=None, remote_connection: 'environ.RemoteConnection' = None, mock_send_request=None) -> 'environ.Response': """ """ name, args = parse.split_line(command) if not remote_connection: remote_connection = environ.RemoteConnection( url='fake-run-remote.command', active=True) app = app if app else server.create_test_app() def default_mock_send_request(endpoint: str, data: dict = None, method: str = None, **kwargs): http_method = method.lower() if method else None func = server.post if data or http_method == 'post' else server.get result = func(app=app, endpoint=endpoint, data=data) return result.response side_effect = (mock_send_request if mock_send_request else default_mock_send_request) with patch('cauldron.cli.sync.comm.send_request', side_effect=side_effect): response = commander.execute(name=name, raw_args=args, remote_connection=remote_connection) response.thread.join() return response
def test_assemble_url_specified_connection(self): """Should assemble url using the specified remote connection data""" url = 'some.url:5451' endpoint = '/some-endpoint' remote_connection = environ.RemoteConnection(url=url, active=True) url_assembled = comm.assemble_url(endpoint, remote_connection) self.assertEqual(url_assembled, 'http://{}{}'.format(url, endpoint))
def test_remote(self, sync_open: MagicMock): """ should successfully open project remotely """ sync_open.return_value = environ.Response() response = support.create_project( self, 'tester', confirm=False, remote_connection=environ.RemoteConnection(True, 'something.url')) self.assertTrue(response.success) self.assertGreater(sync_open.call_count, 0)
def execute(context: cli.CommandContext) -> Response: """ :return: """ environ.remote_connection = environ.RemoteConnection(active=False, url=None) return context.response.notify( kind='SUCCESS', code='DISCONNECTED', message='Disconnected from remote cauldron').console( whitespace=1).response