[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Test _draw_address_column()
commit 91e93050111be0c3f35b1dccd83db6d149dcb841
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Jul 10 12:26:25 2016 -0700
Test _draw_address_column()
---
nyx/panel/connection.py | 55 ++++++++++++++++++++++++------------------------
test/panel/connection.py | 11 ++++++++++
2 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index 33ef505..cda75a5 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -455,36 +455,10 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
else:
x += 1 # offset from edge
- self._draw_address_column(subwindow, x, y, line, attr)
+ _draw_address_column(subwindow, x, y, line, attr)
_draw_line_details(subwindow, 57, y, line, width - 57 - 20, attr)
_draw_right_column(subwindow, width - 18, y, line, current_time, attr)
- def _draw_address_column(self, subwindow, x, y, line, attr):
- src = tor_controller().get_info('address', line.connection.local_address)
- src += ':%s' % line.connection.local_port if line.line_type == LineType.CONNECTION else ''
-
- if line.line_type == LineType.CIRCUIT_HEADER and line.circuit.status != 'BUILT':
- dst = 'Building...'
- else:
- dst = '<scrubbed>' if line.entry.is_private() else line.connection.remote_address
- dst += ':%s' % line.connection.remote_port
-
- if line.entry.get_type() == Category.EXIT:
- purpose = connection.port_usage(line.connection.remote_port)
-
- if purpose:
- dst += ' (%s)' % str_tools.crop(purpose, 26 - len(dst) - 3)
- elif not tor_controller().is_geoip_unavailable() and not line.entry.is_private():
- dst += ' (%s)' % (line.locale if line.locale else '??')
-
- if line.entry.get_type() in (Category.INBOUND, Category.SOCKS, Category.CONTROL):
- dst, src = src, dst
-
- if line.line_type == LineType.CIRCUIT:
- subwindow.addstr(x, y, dst, *attr)
- else:
- subwindow.addstr(x, y, '%-21s --> %-26s' % (src, dst), *attr)
-
def _update(self):
"""
Fetches the newest resolved connections.
@@ -558,6 +532,33 @@ def _draw_title(subwindow, entries, showing_details):
subwindow.addstr(0, 0, 'Connections (%s):' % ', '.join(count_labels), HIGHLIGHT)
+def _draw_address_column(subwindow, x, y, line, attr):
+ src = tor_controller().get_info('address', line.connection.local_address)
+ src += ':%s' % line.connection.local_port if line.line_type == LineType.CONNECTION else ''
+
+ if line.line_type == LineType.CIRCUIT_HEADER and line.circuit.status != 'BUILT':
+ dst = 'Building...'
+ else:
+ dst = '<scrubbed>' if line.entry.is_private() else line.connection.remote_address
+ dst += ':%s' % line.connection.remote_port
+
+ if line.entry.get_type() == Category.EXIT:
+ purpose = connection.port_usage(line.connection.remote_port)
+
+ if purpose:
+ dst += ' (%s)' % str_tools.crop(purpose, 26 - len(dst) - 3)
+ elif not tor_controller().is_geoip_unavailable() and not line.entry.is_private():
+ dst += ' (%s)' % (line.locale if line.locale else '??')
+
+ if line.entry.get_type() in (Category.INBOUND, Category.SOCKS, Category.CONTROL):
+ dst, src = src, dst
+
+ if line.line_type == LineType.CIRCUIT:
+ subwindow.addstr(x, y, dst, *attr)
+ else:
+ subwindow.addstr(x, y, '%-21s --> %-26s' % (src, dst), *attr)
+
+
def _draw_details(subwindow, selected):
"""
Shows detailed information about the selected connection.
diff --git a/test/panel/connection.py b/test/panel/connection.py
index ac9d404..99c185b 100644
--- a/test/panel/connection.py
+++ b/test/panel/connection.py
@@ -182,6 +182,17 @@ class TestConnectionPanel(unittest.TestCase):
self.assertEqual(DETAILS_FOR_MULTIPLE_MATCHES, test.render(nyx.panel.connection._draw_details, line()).content)
@require_curses
+ @patch('nyx.panel.connection.tor_controller')
+ def test_draw_address_column(self, tor_controller_mock):
+ tor_controller_mock().get_info.return_value = '82.121.9.9'
+ tor_controller_mock().is_geoip_unavailable.return_value = False
+
+ self.assertEqual('75.119.206.243:22 (de) --> 82.121.9.9:3531', test.render(nyx.panel.connection._draw_address_column, 0, 0, line(), ()).content)
+ self.assertEqual('82.121.9.9:3531 --> 75.119.206.243:22 (SSH)', test.render(nyx.panel.connection._draw_address_column, 0, 0, line(entry = MockEntry(entry_type = Category.EXIT)), ()).content)
+ self.assertEqual('Building... --> 82.121.9.9', test.render(nyx.panel.connection._draw_address_column, 0, 0, line(line_type = LineType.CIRCUIT_HEADER, circ = MockCircuit(status = 'EXTENDING')), ()).content)
+ self.assertEqual('82.121.9.9', test.render(nyx.panel.connection._draw_address_column, 0, 0, line(line_type = LineType.CIRCUIT), ()).content)
+
+ @require_curses
@patch('nyx.tracker.get_port_usage_tracker')
def test_draw_line_details(self, port_usage_tracker_mock):
process = Mock()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits