-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock connection error #197
Changes from 1 commit
bb70bcd
6aea29c
5359bdf
f940176
17a98dd
ffb6205
4263daa
2164cb6
cbaba98
ef97612
269fc1c
49db0a3
5dccd2a
c1a80b3
fa63151
0fa4e3c
ed56f4a
dc3e59e
bfe919b
03615de
71e89ba
8412e25
6f301b3
75dced3
28cae30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4403,5 +4403,42 @@ def test_hscan_iter(self): | |
self.redis.hscan_iter('name') | ||
|
||
|
||
class TestPubSubConnected(unittest.TestCase): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with other classes, remove this blank line. |
||
def setUp(self): | ||
self.redis = fakeredis.FakePubSub(connected=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather call this variable |
||
|
||
def tearDown(self): | ||
del self.redis | ||
|
||
def test_basic_subscript(self): | ||
with self.assertRaises(redis.ConnectionError): | ||
self.redis.subscribe('logs') | ||
|
||
def test_subscript_conn_lost(self): | ||
self.redis.connected = True | ||
self.redis.subscribe('logs') | ||
self.redis.connected = False | ||
with self.assertRaises(redis.ConnectionError): | ||
self.redis.get_message() | ||
|
||
def test_put_listen(self): | ||
self.redis.connected = True | ||
count = self.redis.put('logs', 'mymessage', 'subscribe') | ||
self.assertEqual(count, 1, 'Message could should be 1') | ||
self.redis.connected = False | ||
with self.assertRaises(redis.ConnectionError): | ||
self.redis.get_message() | ||
self.redis.connected = True | ||
msg = self.redis.get_message() | ||
check = { | ||
'type': 'subscribe', | ||
'pattern': None, | ||
'channel': b'logs', | ||
'data': 'mymessage' | ||
} | ||
self.assertEqual(msg, check, 'Message was not published to channel') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather put
connected
afterdecode_responses
, so that it doesn't break existing code that passes decode_responses as a positional parameter.