|
7 | 7 | import pytest
|
8 | 8 |
|
9 | 9 | import config.main as config
|
| 10 | +import consutil.main as consutil |
10 | 11 | import tests.mock_tables.dbconnector
|
11 | 12 |
|
12 | 13 | from click.testing import CliRunner
|
@@ -463,3 +464,34 @@ def test_sys_info_provider_get_active_console_process_info_nonexists(self):
|
463 | 464 | SysInfoProvider.DEVICE_PREFIX == "/dev/ttyUSB"
|
464 | 465 | proc = SysInfoProvider.get_active_console_process_info("2")
|
465 | 466 | assert proc is None
|
| 467 | + |
| 468 | +class TestConsutilShow(object): |
| 469 | + @classmethod |
| 470 | + def setup_class(cls): |
| 471 | + print("SETUP") |
| 472 | + |
| 473 | + expect_show_output = ''+ \ |
| 474 | + """ Line Baud PID Start Time Device |
| 475 | +------ ------ ----- ------------------------ -------- |
| 476 | + 1 9600 - - switch1 |
| 477 | + *2 9600 223 Wed Mar 6 08:31:35 2019 switch2 |
| 478 | + 3 9600 - - |
| 479 | +""" |
| 480 | + @mock.patch('consutil.lib.SysInfoProvider.init_device_prefix', mock.MagicMock(return_value=None)) |
| 481 | + def test_show(self): |
| 482 | + runner = CliRunner() |
| 483 | + db = Db() |
| 484 | + db.cfgdb.set_entry("CONSOLE_PORT", 1, { "remote_device" : "switch1", "baud_rate" : "9600" }) |
| 485 | + db.cfgdb.set_entry("CONSOLE_PORT", 2, { "remote_device" : "switch2", "baud_rate" : "9600" }) |
| 486 | + db.cfgdb.set_entry("CONSOLE_PORT", 3, { "baud_rate" : "9600" }) |
| 487 | + |
| 488 | + db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "state", "busy") |
| 489 | + db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "pid", "223") |
| 490 | + db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "start_time", "Wed Mar 6 08:31:35 2019") |
| 491 | + |
| 492 | + # use '--brief' option to avoid access system |
| 493 | + result = runner.invoke(consutil.consutil.commands["show"], ['--brief'], obj=db) |
| 494 | + print(result.exit_code) |
| 495 | + print(sys.stderr, result.output) |
| 496 | + assert result.exit_code == 0 |
| 497 | + assert result.output == TestConsutilShow.expect_show_output |
0 commit comments