From 7dba3fc6e946f04219e50a36c425f33624f9a3f4 Mon Sep 17 00:00:00 2001 From: Vitaly Samigullin Date: Sat, 10 Feb 2024 22:19:51 +0100 Subject: [PATCH] fix: pass in proper hosts to CrateShell CrateShell invocation in integration tests relied on the default localhost:4200 instead of the custom host urls used in Docker containers. That resulted in a flood of urllib3 warning logs coming from the crate client. This change fix the hosts urls. --- tests/test_integration.py | 52 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index c6c6ab9e..877d1186 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -223,7 +223,7 @@ def test_pprint_duplicate_keys(self): "| name | name |", "+------+------+", "+------+------+\n"]) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint([], ['name', 'name']) self.assertEqual(expected, output.getvalue()) @@ -235,7 +235,7 @@ def test_pprint_dont_guess_type(self): "+---------+", "| 0.50 |", "+---------+\n"]) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint([["0.50"]], ['version']) self.assertEqual(expected, output.getvalue()) @@ -384,7 +384,7 @@ def test_tabulate_null_int_column(self): '| 1 |', '| NULL |', '+------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['x']) self.assertEqual(expected, output.getvalue()) @@ -400,7 +400,7 @@ def test_tabulate_boolean_int_column(self): '| FALSE |', '| 1 |', '+-------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['x']) self.assertEqual(expected, output.getvalue()) @@ -417,7 +417,7 @@ def test_multiline_header(self): '| FALSE |', '| 1 |', '+-------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['x\ny']) self.assertEqual(expected, output.getvalue()) @@ -436,7 +436,7 @@ def test_multiline_row(self): '| name string | | |', '| ) | | |', '+-----------------------+-----+---+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['show create table foo', 'a', 'b']) self.assertEqual(expected, output.getvalue()) @@ -458,7 +458,7 @@ def test_tabulate_empty_line(self): '| | Planet |', '+------------------------------------+-------------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['min(name)', 'kind']) # assert 0 @@ -481,7 +481,7 @@ def test_empty_line_first_row_first_column(self): '| Galactic Sector QQ7 Active J Gamma | Galaxy |', '+------------------------------------+-------------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['min(name)', 'kind']) self.assertEqual(expected, output.getvalue()) @@ -505,7 +505,7 @@ def test_empty_first_row(self): '| Alpha Centauri | Alpha - Centauri |', '+---------------------+-----------------------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['name', 'replaced']) self.assertEqual(expected, output.getvalue()) @@ -527,7 +527,7 @@ def test_any_empty(self): '| Features and conformance views | FALSE | 3 | SQL_LANGUAGES view |', '+--------------------------------+--------------+----------------+--------------------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['feature_name', 'is_supported', 'sub_feature_id', 'sub_feature_name']) self.assertEqual(expected, output.getvalue()) @@ -563,7 +563,7 @@ def test_first_column_first_row_empty(self): '| NULL | 1.0 |', '+------------------------------------+--------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint(rows, cols=['name', '_score']) self.assertEqual(expected, output.getvalue()) @@ -582,7 +582,7 @@ def test_error_exit_code(self): self.assertEqual(e.code, 1) def test_verbose_with_error_trace(self): - with CrateShell(error_trace=True) as cmd: + with CrateShell(crate_hosts=[node.http_url], error_trace=True) as cmd: cmd.logger = Mock() cmd.cursor.execute = Mock(side_effect=ProgrammingError(msg="the error message", error_trace="error trace")) @@ -591,7 +591,7 @@ def test_verbose_with_error_trace(self): cmd.logger.critical.assert_called_with("\nerror trace") def test_verbose_no_error_trace(self): - with CrateShell(error_trace=True) as cmd: + with CrateShell(crate_hosts=[node.http_url], error_trace=True) as cmd: cmd.logger = Mock() cmd.cursor.execute = Mock(side_effect=ProgrammingError(msg="the error message", error_trace=None)) @@ -607,7 +607,7 @@ def test_rendering_object(self): '+-------------------------------+', '| {"age": 42, "name": "Arthur"} |', '+-------------------------------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint([[user]], ['user']) self.assertEqual(expected, output.getvalue()) @@ -620,7 +620,7 @@ def test_rendering_array(self): '+--------------------+', '| ["Arthur", "Ford"] |', '+--------------------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint([[names]], ['names']) self.assertEqual(expected, output.getvalue()) @@ -633,14 +633,14 @@ def test_rendering_float(self): '| 3.1415926535 |', '| 42.0 |', '+---------------+\n']) - with CrateShell() as cmd: + with CrateShell(crate_hosts=[node.http_url]) as cmd: with patch('sys.stdout', new_callable=StringIO) as output: cmd.pprint([[3.1415926535], [42.0]], ['number']) self.assertEqual(expected, output.getvalue()) def test_help_command(self): """Test output of help command""" - command = CrateShell(is_tty=False) + command = CrateShell(crate_hosts=[node.http_url], is_tty=False) expected = "\n".join([ '\\? print this help', '\\autocapitalize toggle automatic capitalization of SQL keywords', @@ -660,7 +660,7 @@ def test_help_command(self): help_ = command.commands['?'] self.assertTrue(isinstance(help_, Command)) self.assertEqual(expected, help_(command)) - with CrateShell(is_tty=False) as cmd: + with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: output = StringIO() cmd.logger = ColorPrinter(False, stream=output) text = help_(cmd, 'arg1', 'arg2') @@ -701,7 +701,7 @@ def test_wrong_host_format(self): _create_shell(crate_hosts, False, None, False, args) def test_command_timeout(self): - with CrateShell(node.http_url) as crash: + with CrateShell(crate_hosts=[node.http_url]) as crash: crash.process(""" CREATE FUNCTION fib(long) RETURNS LONG @@ -716,7 +716,7 @@ def test_command_timeout(self): slow_query = "SELECT fib(35)" # without verbose - with CrateShell(node.http_url, + with CrateShell(crate_hosts=[node.http_url], error_trace=False, timeout=timeout) as crash: crash.logger = Mock() @@ -724,7 +724,7 @@ def test_command_timeout(self): crash.logger.warn.assert_any_call("Use \\connect to connect to one or more servers first.") # with verbose - with CrateShell(node.http_url, + with CrateShell(crate_hosts=[node.http_url], error_trace=True, timeout=timeout) as crash: crash.logger = Mock() @@ -740,7 +740,7 @@ def test_command_timeout(self): crash.logger.warn.assert_any_call("Use \\connect to connect to one or more servers first.") def test_username_param(self): - with CrateShell(node.http_url, + with CrateShell(crate_hosts=[node.http_url], username='crate') as crash: self.assertEqual(crash.username, "crate") self.assertEqual(crash.connection.client.username, "crate") @@ -755,7 +755,7 @@ def test_ssl_params(self): ftouch(key_filename) ftouch(ca_cert_filename) - with CrateShell(node.http_url, + with CrateShell(crate_hosts=[node.http_url], verify_ssl=False, cert_file=cert_filename, key_file=key_filename, @@ -799,7 +799,7 @@ def test_ssl_params_wrong_permision_file(self): parser.parse_args(argv) def test_close_shell(self): - crash = CrateShell(node.http_url) + crash = CrateShell(crate_hosts=[node.http_url]) self.assertFalse(crash.is_closed()) self.assertTrue(crash.is_conn_available()) @@ -814,7 +814,7 @@ def test_close_shell(self): ctx.exception.message) def test_connect_info(self): - with CrateShell(node.http_url, + with CrateShell(crate_hosts=[node.http_url], username='crate', schema='test') as crash: self.assertEqual(crash.connect_info.user, "crate") @@ -863,7 +863,7 @@ def test_connect_info(self): @patch.object(CrateShell, "is_conn_available") def test_connect_info_not_available(self, is_conn_available): is_conn_available.return_value = False - with CrateShell(node.http_url, + with CrateShell(crate_hosts=[node.http_url], username='crate', schema='test') as crash: self.assertEqual(crash.connect_info.user, None)