commit a976f7699c9ed63ca65c16da7110f68b65e67e7c Author: Sambuddha Basu sambuddhabasu1@gmail.com Date: Sat May 28 19:35:22 2016 -0700
Added test for new event selection dialog --- test/popups.py | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+)
diff --git a/test/popups.py b/test/popups.py index d782b96..19ff0e1 100644 --- a/test/popups.py +++ b/test/popups.py @@ -111,6 +111,60 @@ Event Types:-------------------------------------------------------------------+ +------------------------------------------------------------------------------+ """.strip()
+EXPECTED_NEW_EVENT_SELECTOR = """ +Event Types:-------------------------------------------------------------------+ +|Tor Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | +|Nyx Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | ++------------------------------------------------------------------------------+ +|[ ] CIRC [ ] CIRC_MINOR | +| [Ok] [Cancel]| ++------------------------------------------------------------------------------+ +""".strip() + +EXPECTED_NEW_EVENT_SELECTOR_UP_DOWN = """ +Event Types:-------------------------------------------------------------------+ +|Tor Runlevel: [X] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | +|Nyx Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | ++------------------------------------------------------------------------------+ +|[ ] CIRC [ ] CIRC_MINOR [ ] STREAM | +|[ ] ORCONN [ ] BW | +| [Ok] [Cancel]| ++------------------------------------------------------------------------------+ +""".strip() + +EXPECTED_NEW_EVENT_SELECTOR_LEFT_RIGHT = """ +Event Types:-------------------------------------------------------------------+ +|Tor Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | +|Nyx Runlevel: [X] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | ++------------------------------------------------------------------------------+ +|[ ] CIRC [ ] CIRC_MINOR [ ] STREAM | +|[ ] ORCONN [ ] BW | +| [Ok] [Cancel]| ++------------------------------------------------------------------------------+ +""".strip() + +EXPECTED_NEW_EVENT_SELECTOR_CANCEL = """ +Event Types:-------------------------------------------------------------------+ +|Tor Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | +|Nyx Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | ++------------------------------------------------------------------------------+ +|[ ] CIRC [ ] CIRC_MINOR [ ] STREAM | +|[ ] ORCONN [ ] BW | +| [Ok] [Cancel]| ++------------------------------------------------------------------------------+ +""".strip() + +EXPECTED_NEW_EVENT_SELECTOR_INITIAL_SELECTION = """ +Event Types:-------------------------------------------------------------------+ +|Tor Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | +|Nyx Runlevel: [ ] DEBUG [ ] INFO [ ] NOTICE [ ] WARN [ ] ERR | ++------------------------------------------------------------------------------+ +|[ ] CIRC [X] CIRC_MINOR [ ] STREAM | +|[ ] ORCONN [ ] BW | +| [Ok] [Cancel]| ++------------------------------------------------------------------------------+ +""".strip() + TORRC = """ ControlPort 9051 CookieAuthentication 1 @@ -317,6 +371,133 @@ class TestPopups(unittest.TestCase):
@require_curses @patch('nyx.popups._top', Mock(return_value = 0)) + @patch('nyx.tor_controller') + def test_new_select_event_types(self, controller_mock): + controller = Mock() + controller.get_info.return_value = 'DEBUG INFO NOTICE WARN ERR CIRC CIRC_MINOR' + controller_mock.return_value = controller + + keypresses = [ + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_ENTER), + ] + + def draw_func(): + with patch('nyx.curses.key_input', side_effect = keypresses): + return nyx.popups.new_select_event_types([]) + + rendered = test.render(draw_func) + self.assertEqual(EXPECTED_NEW_EVENT_SELECTOR, rendered.content) + self.assertEqual(set([]), rendered.return_value) + + @require_curses + @patch('nyx.popups._top', Mock(return_value = 0)) + @patch('nyx.tor_controller') + def test_new_select_event_types_up_down(self, controller_mock): + controller = Mock() + controller.get_info.return_value = 'DEBUG INFO NOTICE WARN ERR CIRC CIRC_MINOR STREAM ORCONN BW' + controller_mock.return_value = controller + + keypresses = [ + nyx.curses.KeyInput(curses.KEY_UP), + nyx.curses.KeyInput(curses.KEY_ENTER), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_ENTER), + ] + + def draw_func(): + with patch('nyx.curses.key_input', side_effect = keypresses): + return nyx.popups.new_select_event_types([]) + + rendered = test.render(draw_func) + self.assertEqual(EXPECTED_NEW_EVENT_SELECTOR_UP_DOWN, rendered.content) + self.assertEqual(set(['DEBUG']), rendered.return_value) + + @require_curses + @patch('nyx.popups._top', Mock(return_value = 0)) + @patch('nyx.tor_controller') + def test_new_select_event_types_left_right(self, controller_mock): + controller = Mock() + controller.get_info.return_value = 'DEBUG INFO NOTICE WARN ERR CIRC CIRC_MINOR STREAM ORCONN BW' + controller_mock.return_value = controller + + keypresses = [ + nyx.curses.KeyInput(curses.KEY_LEFT), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_ENTER), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_RIGHT), + nyx.curses.KeyInput(curses.KEY_RIGHT), + nyx.curses.KeyInput(curses.KEY_LEFT), + nyx.curses.KeyInput(curses.KEY_ENTER), + ] + + def draw_func(): + with patch('nyx.curses.key_input', side_effect = keypresses): + return nyx.popups.new_select_event_types([]) + + rendered = test.render(draw_func) + self.assertEqual(EXPECTED_NEW_EVENT_SELECTOR_LEFT_RIGHT, rendered.content) + self.assertEqual(set(['NYX_DEBUG']), rendered.return_value) + + @require_curses + @patch('nyx.popups._top', Mock(return_value = 0)) + @patch('nyx.tor_controller') + def test_new_select_event_types_cancel(self, controller_mock): + controller = Mock() + controller.get_info.return_value = 'DEBUG INFO NOTICE WARN ERR CIRC CIRC_MINOR STREAM ORCONN BW' + controller_mock.return_value = controller + + keypresses = [ + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_RIGHT), + nyx.curses.KeyInput(curses.KEY_ENTER), + ] + + def draw_func(): + with patch('nyx.curses.key_input', side_effect = keypresses): + return nyx.popups.new_select_event_types([]) + + rendered = test.render(draw_func) + self.assertEqual(EXPECTED_NEW_EVENT_SELECTOR_CANCEL, rendered.content) + self.assertEqual(None, rendered.return_value) + + @require_curses + @patch('nyx.popups._top', Mock(return_value = 0)) + @patch('nyx.tor_controller') + def test_new_select_event_types_initial_selection(self, controller_mock): + controller = Mock() + controller.get_info.return_value = 'DEBUG INFO NOTICE WARN ERR CIRC CIRC_MINOR STREAM ORCONN BW' + controller_mock.return_value = controller + + keypresses = [ + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_DOWN), + nyx.curses.KeyInput(curses.KEY_ENTER), + ] + + def draw_func(): + with patch('nyx.curses.key_input', side_effect = keypresses): + return nyx.popups.new_select_event_types(['CIRC_MINOR']) + + rendered = test.render(draw_func) + self.assertEqual(EXPECTED_NEW_EVENT_SELECTOR_INITIAL_SELECTION, rendered.content) + self.assertEqual(set(['CIRC_MINOR']), rendered.return_value) + + @require_curses + @patch('nyx.popups._top', Mock(return_value = 0)) def test_confirm_save_torrc(self): rendered = test.render(nyx.popups.confirm_save_torrc, TORRC) self.assertEqual(EXPECTED_SAVE_TORRC_CONFIRMATION, rendered.content)
tor-commits@lists.torproject.org