commit 6159e01fdc1473fd25f3633b154a74cdac20ef8d Author: Damian Johnson atagar@torproject.org Date: Sat Apr 9 22:32:39 2016 -0700
Test _draw_ports_section() --- nyx/panel/header.py | 56 ++++++++++++++++++++++++++-------------------------- test/panel/header.py | 31 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 28 deletions(-)
diff --git a/nyx/panel/header.py b/nyx/panel/header.py index f49efe1..54046b2 100644 --- a/nyx/panel/header.py +++ b/nyx/panel/header.py @@ -184,7 +184,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread): _draw_platform_section(subwindow, 0, 0, left_width, vals)
if vals.is_connected: - self._draw_ports_section(subwindow, 0, 1, left_width, vals) + _draw_ports_section(subwindow, 0, 1, left_width, vals) else: self._draw_disconnected(subwindow, 0, 1, left_width, vals)
@@ -212,33 +212,6 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread): else: subwindow.addstr(0, subwindow.height - 1, 'Paused', HIGHLIGHT)
- def _draw_ports_section(self, subwindow, x, y, width, vals): - """ - Section providing our nickname, address, and port information... - - Unnamed - 0.0.0.0:7000, Control Port (cookie): 9051 - """ - - if not vals.is_relay: - x = subwindow.addstr(x, y, 'Relaying Disabled', CYAN) - else: - x = subwindow.addstr(x, y, vals.format('{nickname} - {address}:{or_port}')) - - if vals.dir_port != '0': - x = subwindow.addstr(x, y, vals.format(', Dir Port: {dir_port}')) - - if vals.control_port: - if width >= x + 19 + len(vals.control_port) + len(vals.auth_type): - auth_color = RED if vals.auth_type == 'open' else GREEN - - x = subwindow.addstr(x, y, ', Control Port (') - x = subwindow.addstr(x, y, vals.auth_type, auth_color) - subwindow.addstr(x, y, vals.format('): {control_port}')) - else: - subwindow.addstr(x, y, vals.format(', Control Port: {control_port}')) - elif vals.socket_path: - subwindow.addstr(x, y, vals.format(', Control Socket: {socket_path}')) - def _draw_disconnected(self, subwindow, x, y, width, vals): """ Message indicating that tor is disconnected... @@ -557,3 +530,30 @@ def _draw_platform_section(subwindow, x, y, width, vals): x = subwindow.addstr(x, y, ' (') x = subwindow.addstr(x, y, vals.version_status, version_color) subwindow.addstr(x, y, ')') + +def _draw_ports_section(subwindow, x, y, width, vals): + """ + Section providing our nickname, address, and port information... + + Unnamed - 0.0.0.0:7000, Control Port (cookie): 9051 + """ + + if not vals.is_relay: + x = subwindow.addstr(x, y, 'Relaying Disabled', CYAN) + else: + x = subwindow.addstr(x, y, vals.format('{nickname} - {address}:{or_port}')) + + if vals.dir_port != '0': + x = subwindow.addstr(x, y, vals.format(', Dir Port: {dir_port}')) + + if vals.control_port: + if width >= x + 19 + len(vals.control_port) + len(vals.auth_type): + auth_color = RED if vals.auth_type == 'open' else GREEN + + x = subwindow.addstr(x, y, ', Control Port (') + x = subwindow.addstr(x, y, vals.auth_type, auth_color) + subwindow.addstr(x, y, vals.format('): {control_port}')) + else: + subwindow.addstr(x, y, vals.format(', Control Port: {control_port}')) + elif vals.socket_path: + subwindow.addstr(x, y, vals.format(', Control Socket: {socket_path}')) diff --git a/test/panel/header.py b/test/panel/header.py index ee18eb6..c06fd39 100644 --- a/test/panel/header.py +++ b/test/panel/header.py @@ -45,3 +45,34 @@ class TestHeader(unittest.TestCase):
rendered = test.render(nyx.panel.header._draw_platform_section, 0, 0, 80, vals) self.assertEqual('nyx - odin (Linux 3.5.0-54-generic)', rendered.content) + + @require_curses + def test_draw_ports_section(self): + vals = nyx.panel.header._sampling( + nickname = 'Unnamed', + address = '174.21.17.28', + or_port = '7000', + dir_port = '7001', + control_port = '9051', + auth_type = 'cookie', + is_relay = True, + ) + + test_input = { + 80: 'Unnamed - 174.21.17.28:7000, Dir Port: 7001, Control Port (cookie): 9051', + 50: 'Unnamed - 174.21.17.28:7000, Dir Port: 7001, Control Port: 9051', + 0: 'Unnamed - 174.21.17.28:7000, Dir Port: 7001, Control Port: 9051', + } + + for width, expected in test_input.items(): + self.assertEqual(expected, test.render(nyx.panel.header._draw_ports_section, 0, 0, width, vals).content) + + @require_curses + def test_draw_ports_section_with_relaying(self): + vals = nyx.panel.header._sampling( + control_port = None, + socket_path = '/path/to/control/socket', + is_relay = False, + ) + + self.assertEqual('Relaying Disabled, Control Socket: /path/to/control/socket', test.render(nyx.panel.header._draw_ports_section, 0, 0, 80, vals).content)
tor-commits@lists.torproject.org