[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Test _draw_exit_policy()
commit 09c23a7433d4710c8c88962c7b4acc3f21dcc5d0
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Apr 10 13:00:53 2016 -0700
Test _draw_exit_policy()
---
nyx/panel/header.py | 57 ++++++++++++++++++++++++++--------------------------
test/panel/header.py | 6 ++++++
2 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 00d4794..96b8383 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -195,7 +195,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
if vals.is_relay:
_draw_fingerprint_and_fd_usage(subwindow, left_width, 1, right_width, vals)
_draw_flags(subwindow, 0, 2, vals.flags)
- self._draw_exit_policy(subwindow, left_width, 2, right_width, vals)
+ _draw_exit_policy(subwindow, left_width, 2, vals.exit_policy)
elif vals.is_connected:
self._draw_newnym_option(subwindow, left_width, 1, right_width, vals)
else:
@@ -213,33 +213,6 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
else:
subwindow.addstr(0, subwindow.height - 1, 'Paused', HIGHLIGHT)
- def _draw_exit_policy(self, subwindow, x, y, width, vals):
- """
- Presents our exit policy...
-
- exit policy: reject *:*
- """
-
- x = subwindow.addstr(x, y, 'exit policy: ')
-
- if not vals.exit_policy:
- return
-
- rules = list(vals.exit_policy.strip_private().strip_default())
-
- for i, rule in enumerate(rules):
- policy_color = GREEN if rule.is_accept else RED
- x = subwindow.addstr(x, y, str(rule), policy_color, BOLD)
-
- if i < len(rules) - 1:
- x = subwindow.addstr(x, y, ', ')
-
- if vals.exit_policy.has_default():
- if rules:
- x = subwindow.addstr(x, y, ', ')
-
- subwindow.addstr(x, y, '<default>', CYAN, BOLD)
-
def _draw_newnym_option(self, subwindow, x, y, width, vals):
"""
Provide a notice for requiesting a new identity, and time until it's next
@@ -563,3 +536,31 @@ def _draw_flags(subwindow, x, y, flags):
x = subwindow.addstr(x, y, ', ')
else:
subwindow.addstr(x, y, 'none', CYAN, BOLD)
+
+
+def _draw_exit_policy(subwindow, x, y, exit_policy):
+ """
+ Presents our exit policy...
+
+ exit policy: reject *:*
+ """
+
+ x = subwindow.addstr(x, y, 'exit policy: ')
+
+ if not exit_policy:
+ return
+
+ rules = list(exit_policy.strip_private().strip_default())
+
+ for i, rule in enumerate(rules):
+ policy_color = GREEN if rule.is_accept else RED
+ x = subwindow.addstr(x, y, str(rule), policy_color, BOLD)
+
+ if i < len(rules) - 1:
+ x = subwindow.addstr(x, y, ', ')
+
+ if exit_policy.has_default():
+ if rules:
+ x = subwindow.addstr(x, y, ', ')
+
+ subwindow.addstr(x, y, '<default>', CYAN, BOLD)
diff --git a/test/panel/header.py b/test/panel/header.py
index 39982e0..9794644 100644
--- a/test/panel/header.py
+++ b/test/panel/header.py
@@ -6,6 +6,7 @@ import time
import unittest
import nyx.panel.header
+import stem.exit_policy
import test
from test import require_curses
@@ -162,3 +163,8 @@ class TestHeader(unittest.TestCase):
self.assertEqual('flags: none', test.render(nyx.panel.header._draw_flags, 0, 0, []).content)
self.assertEqual('flags: Guard', test.render(nyx.panel.header._draw_flags, 0, 0, ['Guard']).content)
self.assertEqual('flags: Running, Exit', test.render(nyx.panel.header._draw_flags, 0, 0, ['Running', 'Exit']).content)
+
+ @require_curses
+ def test_draw_exit_policy(self):
+ self.assertEqual('exit policy: reject *:*', test.render(nyx.panel.header._draw_exit_policy, 0, 0, stem.exit_policy.ExitPolicy('reject *:*')).content)
+ self.assertEqual('exit policy: accept *:80, accept *:443, reject *:*', test.render(nyx.panel.header._draw_exit_policy, 0, 0, stem.exit_policy.ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')).content)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits