commit f7438a1b577a8bf3ec027edcd5a7c1456ce66067
Author: Damian Johnson <atagar(a)torproject.org>
Date: Thu Dec 4 18:00:41 2014 -0800
Unit test for DescriptorUnavailable
Quick test to exercise the new exception.
---
stem/__init__.py | 3 +++
test/unit/control/controller.py | 13 ++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/stem/__init__.py b/stem/__init__.py
index ffdfe72..c034f4f 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -546,6 +546,9 @@ class DescriptorUnavailable(OperationFailed):
Tor was unable to provide a descriptor for the given relay.
"""
+ def __init__(self, message):
+ super(DescriptorUnavailable, self).__init__(message = message)
+
class InvalidRequest(OperationFailed):
"""
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index 5e0058f..1974e50 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -13,7 +13,7 @@ import stem.socket
import stem.util.system
import stem.version
-from stem import ControllerError, InvalidArguments, InvalidRequest, ProtocolError, UnsatisfiableRequest
+from stem import ControllerError, DescriptorUnavailable, InvalidArguments, InvalidRequest, ProtocolError, UnsatisfiableRequest
from stem.control import _parse_circ_path, Listener, Controller, EventType
from stem.exit_policy import ExitPolicy
from test import mocking
@@ -428,6 +428,17 @@ class TestControl(unittest.TestCase):
except ControllerError as exc:
self.assertEqual('Unable to determine our own fingerprint: nope, too bad', str(exc))
+ get_info_mock.side_effect = [
+ '5AC9C5AA75BA1F18D8459B326B4B8111A856D290',
+ InvalidArguments(None, 'GETINFO request contained unrecognized keywords: ns/id/5AC9C5AA75BA1F18D8459B326B4B8111A856D290'),
+ ]
+
+ try:
+ self.controller.get_network_status()
+ self.fail("We should've raised an exception")
+ except DescriptorUnavailable as exc:
+ self.assertEqual("Tor was unable to provide the descriptor for '5AC9C5AA75BA1F18D8459B326B4B8111A856D290'", str(exc))
+
self.assertEqual('boom', self.controller.get_network_status(default = 'boom'))
# successful request