Esempio n. 1
0
 def test_is_open(self):
     url = 'test-url'
     reader = Reader(Mock(), url=url)
     # closed
     self.assertFalse(reader.is_open())
     # open
     reader.receiver = Mock()
     self.assertTrue(reader.is_open())
Esempio n. 2
0
 def test_is_open(self):
     url = 'test-url'
     reader = Reader(Mock(), url=url)
     # closed
     self.assertFalse(reader.is_open())
     # open
     reader.receiver = Mock()
     self.assertTrue(reader.is_open())
Esempio n. 3
0
    def test_open_already(self, receiver):
        url = 'test-url'
        queue = Mock(name='test-queue')

        # test
        reader = Reader(queue, url)
        reader.is_open = Mock(return_value=True)
        reader.open()

        # validation
        self.assertFalse(reader.connection.open.called)
        self.assertFalse(receiver.called)
Esempio n. 4
0
    def test_open_already(self, receiver):
        url = 'test-url'
        queue = Mock(name='test-queue')

        # test
        reader = Reader(queue, url)
        reader.is_open = Mock(return_value=True)
        reader.open()

        # validation
        self.assertFalse(reader.connection.open.called)
        self.assertFalse(receiver.called)
Esempio n. 5
0
    def test_reject_exception(self):
        url = 'test-url'
        tag = '1234'
        queue = Mock()
        message = Mock(delivery_info={DELIVERY_TAG: tag})

        # test
        reader = Reader(queue, url=url)
        reader.channel = Mock()
        reader.channel.basic_reject.side_effect = ValueError

        # validation
        self.assertRaises(ValueError, reader.reject, message)
Esempio n. 6
0
    def test_reject_discarded(self):
        url = 'test-url'
        tag = '1234'
        queue = Mock()
        message = Mock(delivery_info={DELIVERY_TAG: tag})

        # test
        reader = Reader(queue, url=url)
        reader.channel = Mock()
        reader.reject(message, False)

        # validation
        reader.channel.basic_reject.assert_called_once_with(tag, False)
Esempio n. 7
0
    def test_get_empty(self):
        queue = Mock(name='test-queue')
        url = 'test-url'

        # test
        reader = Reader(queue, url=url)
        reader.receiver = Mock()
        reader.receiver.fetch.side_effect = Empty
        message = reader.get(10)

        # validation
        reader.receiver.fetch.assert_called_once_with(10)
        self.assertEqual(message, None)
Esempio n. 8
0
    def test_reject_discarded(self):
        url = 'test-url'
        tag = '1234'
        queue = Mock()
        message = Mock(delivery_info={DELIVERY_TAG: tag})

        # test
        reader = Reader(queue, url=url)
        reader.channel = Mock()
        reader.reject(message, False)

        # validation
        reader.channel.basic_reject.assert_called_once_with(tag, False)
Esempio n. 9
0
    def test_reject_exception(self):
        url = 'test-url'
        tag = '1234'
        queue = Mock()
        message = Mock(delivery_info={DELIVERY_TAG: tag})

        # test
        reader = Reader(queue, url=url)
        reader.channel = Mock()
        reader.channel.basic_reject.side_effect = ValueError

        # validation
        self.assertRaises(ValueError, reader.reject, message)
Esempio n. 10
0
    def test_ack(self):
        url = 'test-url'
        tag = '1234'
        queue = Mock()
        message = Mock(delivery_info={DELIVERY_TAG: tag})

        # test
        reader = Reader(queue, url=url)
        reader.channel = Mock()
        reader.ack(message)

        # validation
        reader.channel.basic_ack.assert_called_once_with(tag)
Esempio n. 11
0
    def test_get_empty(self):
        queue = Mock(name='test-queue')
        url = 'test-url'

        # test
        reader = Reader(queue, url=url)
        reader.receiver = Mock()
        reader.receiver.fetch.side_effect = Empty
        message = reader.get(10)

        # validation
        reader.receiver.fetch.assert_called_once_with(10)
        self.assertEqual(message, None)
Esempio n. 12
0
    def test_ack(self):
        url = 'test-url'
        tag = '1234'
        queue = Mock()
        message = Mock(delivery_info={DELIVERY_TAG: tag})

        # test
        reader = Reader(queue, url=url)
        reader.channel = Mock()
        reader.ack(message)

        # validation
        reader.channel.basic_ack.assert_called_once_with(tag)
Esempio n. 13
0
    def test_open(self, receiver, connection):
        url = 'test-url'
        queue = Queue('test-queue')
        receiver.return_value.open.return_value = receiver.return_value

        # test
        reader = Reader(queue, url)
        reader.is_open = Mock(return_value=False)
        reader.open()

        # validation
        connection.return_value.open.assert_called_once_with()
        connection.return_value.channel.assert_called_once_with()
        receiver.assert_called_once_with(reader)
        self.assertEqual(reader.channel, connection.return_value.channel.return_value)
        self.assertEqual(reader.receiver, receiver.return_value)
Esempio n. 14
0
    def test_get(self):
        queue = Mock(name='test-queue')
        received = Mock(content='<body/>')
        url = 'test-url'

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

        # validation
        reader.receiver.fetch.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)
Esempio n. 15
0
    def test_open(self, receiver, connection):
        url = 'test-url'
        queue = Queue('test-queue')
        receiver.return_value.open.return_value = receiver.return_value

        # test
        reader = Reader(queue, url)
        reader.is_open = Mock(return_value=False)
        reader.open()

        # validation
        connection.return_value.open.assert_called_once_with()
        connection.return_value.channel.assert_called_once_with()
        receiver.assert_called_once_with(reader)
        self.assertEqual(reader.channel,
                         connection.return_value.channel.return_value)
        self.assertEqual(reader.receiver, receiver.return_value)
Esempio n. 16
0
    def test_get(self):
        queue = Mock(name='test-queue')
        received = Mock(content='<body/>')
        url = 'test-url'

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

        # validation
        reader.receiver.fetch.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)
Esempio n. 17
0
    def test_close(self):
        connection = Mock()
        channel = Mock()
        receiver = Mock()

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

        # validation
        receiver.close.assert_called_once_with()
        channel.close.assert_called_once_with()
        self.assertFalse(connection.close.called)
Esempio n. 18
0
    def test_init(self, connection):
        node = Mock(address='test')
        url = 'test-url'

        # test
        reader = Reader(node, url=url)

        # validation
        connection.assert_called_once_with(url)
        self.assertTrue(isinstance(reader, BaseReader))
        self.assertEqual(reader.url, url)
        self.assertEqual(reader.connection, connection.return_value)
        self.assertEqual(reader.node, node)
        self.assertEqual(reader.channel, None)
        self.assertEqual(reader.receiver, None)
Esempio n. 19
0
    def test_close(self):
        connection = Mock()
        channel = Mock()
        receiver = Mock()

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

        # validation
        receiver.close.assert_called_once_with()
        channel.close.assert_called_once_with()
        self.assertFalse(connection.close.called)