File: config.py

package info (click to toggle)
nyx 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,732 kB
  • sloc: python: 7,055; makefile: 7; sh: 3
file content (53 lines) | stat: -rw-r--r-- 1,946 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Unit tests for nyx.panel.config.
"""

import unittest

import nyx.panel.config
import test

from test import require_curses

try:
  # added in python 3.3
  from unittest.mock import patch
except ImportError:
  from mock import patch

EXPECTED_LINE = 'ControlPort               9051       Port providing access to tor...'

EXPECTED_DETAIL_DIALOG = """
+------------------------------------------------------------------------------+
| ControlPort (General Option)                                                 |
| Value: 9051 (custom, LineList, usage: PORT|unix:path|auto [flags])           |
| Description: If set, Tor will accept connections on this port and allow those|
|   connections to control the Tor process using the Tor Control Protocol (des-|
|   cribed in control-spec.txt in torspec). Note: unless you also specify one  |
|   or more of HashedControlPassword or CookieAuthentication, setting this...  |
+------------------------------------------------------------------------------+
""".strip()


class TestConfigPanel(unittest.TestCase):
  @require_curses
  @patch('nyx.panel.config.tor_controller')
  def test_draw_line(self, tor_controller_mock):
    tor_controller_mock().get_info.return_value = True
    tor_controller_mock().get_conf.return_value = ['9051']

    entry = nyx.panel.config.ConfigEntry('ControlPort', 'LineList')

    rendered = test.render(nyx.panel.config._draw_line, 0, 0, entry, False, 10, 35)
    self.assertEqual(EXPECTED_LINE, rendered.content)

  @require_curses
  @patch('nyx.panel.config.tor_controller')
  def test_draw_selection_details(self, tor_controller_mock):
    tor_controller_mock().get_info.return_value = True
    tor_controller_mock().get_conf.return_value = ['9051']

    selected = nyx.panel.config.ConfigEntry('ControlPort', 'LineList')

    rendered = test.render(nyx.panel.config._draw_selection_details, selected)
    self.assertEqual(EXPECTED_DETAIL_DIALOG, rendered.content)