Beispiel #1
0
 def test_is_open(self):
     url = 'test-url'
     node = Mock(address='test')
     reader = Reader(node, url=url)
     # closed
     self.assertFalse(reader.is_open())
     # open
     reader.receiver = Mock()
     self.assertTrue(reader.is_open())
Beispiel #2
0
 def test_is_open(self):
     url = 'test-url'
     node = Mock(address='test')
     reader = Reader(node, url=url)
     # closed
     self.assertFalse(reader.is_open())
     # open
     reader.receiver = Mock()
     self.assertTrue(reader.is_open())
Beispiel #3
0
    def test_reject_queued(self):
        node = Mock(address='test')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.reject(None, requeue=True)

        # validation
        reader.receiver.release.assert_called_once_with()
Beispiel #4
0
    def test_ack(self):
        node = Mock(address='test')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.ack(None)

        # validation
        reader.receiver.accept.assert_called_once_with()
Beispiel #5
0
    def test_reject_queued(self):
        node = Mock(address='test')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.reject(None, requeue=True)

        # validation
        reader.receiver.release.assert_called_once_with()
Beispiel #6
0
    def test_ack(self):
        node = Mock(address='test')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.ack(None)

        # validation
        reader.receiver.accept.assert_called_once_with()
Beispiel #7
0
    def test_get_empty(self):
        node = Mock(address='test')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.receiver.receive.side_effect = Timeout
        message = reader.get(10)

        # validation
        reader.receiver.receive.assert_called_once_with(10)
        self.assertEqual(message, None)
Beispiel #8
0
    def test_get_empty(self):
        node = Mock(address='test')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.receiver.receive.side_effect = Timeout
        message = reader.get(10)

        # validation
        reader.receiver.receive.assert_called_once_with(10)
        self.assertEqual(message, None)
Beispiel #9
0
    def test_close(self):
        connection = Mock()
        receiver = Mock()
        receiver.close.side_effect = KeyError
        node = Mock(address='test')

        # test
        reader = Reader(node, '')
        reader.connection = connection
        reader.receiver = receiver
        reader.is_open = Mock(return_value=True)
        reader.close()

        # validation
        receiver.close.assert_called_once_with()
        self.assertFalse(connection.close.called)
Beispiel #10
0
    def test_close(self):
        connection = Mock()
        receiver = Mock()
        receiver.close.side_effect = KeyError
        node = Mock(address='test')

        # test
        reader = Reader(node, '')
        reader.connection = connection
        reader.receiver = receiver
        reader.is_open = Mock(return_value=True)
        reader.close()

        # validation
        receiver.close.assert_called_once_with()
        self.assertFalse(connection.close.called)
Beispiel #11
0
    def test_get(self):
        node = Mock(address='test')
        received = Mock(body='<body/>')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.receiver.receive.return_value = received
        message = reader.get(10)

        # validation
        reader.receiver.receive.assert_called_once_with(10)
        self.assertTrue(isinstance(message, Message))
        self.assertEqual(message._reader, reader)
        self.assertEqual(message._impl, received)
        self.assertEqual(message._body, received.body)
Beispiel #12
0
    def test_get(self):
        node = Mock(address='test')
        received = Mock(body='<body/>')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)
        reader.receiver = Mock()
        reader.receiver.receive.return_value = received
        message = reader.get(10)

        # validation
        reader.receiver.receive.assert_called_once_with(10)
        self.assertTrue(isinstance(message, Message))
        self.assertEqual(message._reader, reader)
        self.assertEqual(message._impl, received)
        self.assertEqual(message._body, received.body)