Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't allow use of subsequent basic_get calls. Closes #709
- Loading branch information
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
import unittest | ||
|
||
from mock import MagicMock | ||
from pika.frame import Method, Header | ||
from pika.exceptions import DuplicateGetOkCallback | ||
from pika.channel import Channel | ||
from pika.connection import Connection | ||
|
||
|
||
class OnlyOneBasicGetTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.channel = Channel(MagicMock(Connection)(), 0, None) | ||
self.channel._state = Channel.OPEN | ||
self.callback = MagicMock() | ||
|
||
def test_two_basic_get_with_callback(self): | ||
self.channel.basic_get(self.callback) | ||
self.channel._on_getok(MagicMock(Method)(), MagicMock(Header)(), '') | ||
self.channel.basic_get(self.callback) | ||
self.channel._on_getok(MagicMock(Method)(), MagicMock(Header)(), '') | ||
self.assertEqual(self.callback.call_count, 2) | ||
|
||
def test_two_basic_get_without_callback(self): | ||
self.channel.basic_get(self.callback) | ||
with self.assertRaises(DuplicateGetOkCallback): | ||
self.channel.basic_get(self.callback) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |