Skip to content

Commit

Permalink
fix: pass in proper hosts to CrateShell
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pilosus committed Feb 10, 2024
1 parent 8f8850d commit 7dba3fc
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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"))
Expand All @@ -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))
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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',
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -716,15 +716,15 @@ 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()
crash.process(slow_query)
crash.logger.warn.assert_any_call("Use \\connect <server> 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()
Expand All @@ -740,7 +740,7 @@ def test_command_timeout(self):
crash.logger.warn.assert_any_call("Use \\connect <server> 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")
Expand All @@ -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,
Expand Down Expand Up @@ -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())

Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7dba3fc

Please sign in to comment.