File: connect.py

package info (click to toggle)
python-stem 1.2.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,568 kB
  • ctags: 2,036
  • sloc: python: 20,108; makefile: 127; sh: 3
file content (83 lines) | stat: -rw-r--r-- 2,171 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Integration tests for the connect_* convenience functions.
"""

import StringIO
import sys
import unittest

import stem.connection
import test.runner


class TestConnect(unittest.TestCase):
  def setUp(self):
    # prevents the function from printing to the real stdout
    self.original_stdout = sys.stdout
    sys.stdout = StringIO.StringIO()

  def tearDown(self):
    sys.stdout = self.original_stdout

  def test_connect(self):
    """
    Basic sanity checks for the connect function.
    """

    if test.runner.require_control(self):
      return

    runner = test.runner.get_runner()

    control_socket = stem.connection.connect(
      control_port = ('127.0.0.1', test.runner.CONTROL_PORT),
      control_socket = test.runner.CONTROL_SOCKET_PATH,
      password = test.runner.CONTROL_PASSWORD,
      chroot_path = runner.get_chroot(),
      controller = None)

    test.runner.exercise_controller(self, control_socket)

  def test_connect_port(self):
    """
    Basic sanity checks for the connect_port function.
    """

    if test.runner.require_control(self):
      return

    runner = test.runner.get_runner()

    control_socket = stem.connection.connect_port(
      port = test.runner.CONTROL_PORT,
      password = test.runner.CONTROL_PASSWORD,
      chroot_path = runner.get_chroot(),
      controller = None)

    if test.runner.Torrc.PORT in runner.get_options():
      test.runner.exercise_controller(self, control_socket)
      control_socket.close()
    else:
      self.assertEquals(control_socket, None)

  def test_connect_socket_file(self):
    """
    Basic sanity checks for the connect_socket_file function.
    """

    if test.runner.require_control(self):
      return

    runner = test.runner.get_runner()

    control_socket = stem.connection.connect_socket_file(
      path = test.runner.CONTROL_SOCKET_PATH,
      password = test.runner.CONTROL_PASSWORD,
      chroot_path = runner.get_chroot(),
      controller = None)

    if test.runner.Torrc.SOCKET in runner.get_options():
      test.runner.exercise_controller(self, control_socket)
      control_socket.close()
    else:
      self.assertEquals(control_socket, None)