Skip to content

Commit 4d1a640

Browse files
committed
Updated requirements, added to unit tests.
1 parent 6c884ec commit 4d1a640

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

requirements-testing.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
nose
2-
coverage
2+
coveralls
3+
mock

tests/testclient.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import unittest
22
from mockserver import MockServer
3+
import telnetlib
4+
try:
5+
from mock import Mock
6+
except ImportError:
7+
from unittest.mock import Mock
8+
39
from nut2 import PyNUTClient, PyNUTError
410

511
class TestClient(unittest.TestCase):
@@ -15,11 +21,42 @@ def setUp(self):
1521
self.invalid = "does_not_exist"
1622
self.valid_ups_name = "Test UPS 1"
1723
self.valid_command_desc = "Test description"
24+
telnetlib.Telnet = Mock()
1825

1926
def test_init_with_args(self):
2027
PyNUTClient(connect=False, login='test', password='test',
2128
host='test', port=1)
2229

30+
def test_supports_context_manager(self):
31+
try:
32+
with PyNUTClient(connect=False) as client:
33+
pass
34+
except AttributeError:
35+
assert(False)
36+
37+
def test_connect(self):
38+
try:
39+
PyNUTClient()
40+
except Exception:
41+
assert(False)
42+
43+
def test_connect_debug(self):
44+
try:
45+
PyNUTClient(debug=True)
46+
except Exception:
47+
assert(False)
48+
49+
def test_connect_credentials(self):
50+
# FIXME: Mock the __gettem__ call, so this can be fully tested.
51+
try:
52+
PyNUTClient(login=self.valid, password=self.valid)
53+
except TypeError:
54+
pass
55+
except PyNUTError:
56+
pass
57+
except Exception:
58+
assert(False)
59+
2360
def test_get_ups_list(self):
2461
ups_list = self.client.list_ups()
2562
self.assertEquals(type(ups_list), dict)

0 commit comments

Comments
 (0)