Пример #1
0
    def test_reject_exception(self, disposition):
        message = Mock()
        session = Mock()
        session.acknowledge.side_effect = ValueError

        # test
        reader = Reader(None, '')
        reader.session = session
        self.assertRaises(ValueError, reader.reject, message)
Пример #2
0
    def test_ack_exception(self):
        message = Mock()
        session = Mock()
        session.acknowledge.side_effect = ValueError

        # test
        reader = Reader(None, '')
        reader.session = session
        self.assertRaises(ValueError, reader.ack, message)
Пример #3
0
    def test_reject_exception(self, disposition):
        message = Mock()
        session = Mock()
        session.acknowledge.side_effect = ValueError

        # test
        reader = Reader(None, '')
        reader.session = session
        self.assertRaises(ValueError, reader.reject, message)
Пример #4
0
    def test_ack_exception(self):
        message = Mock()
        session = Mock()
        session.acknowledge.side_effect = ValueError

        # test
        reader = Reader(None, '')
        reader.session = session
        self.assertRaises(ValueError, reader.ack, message)
Пример #5
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())
Пример #6
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())
Пример #7
0
    def test_ack(self):
        message = Mock()

        # test
        reader = Reader(None, '')
        reader.session = Mock()
        reader.ack(message)

        # validation
        reader.session.acknowledge.assert_called_once_with(message=message)
Пример #8
0
    def test_ack(self):
        message = Mock()

        # test
        reader = Reader(None, '')
        reader.session = Mock()
        reader.ack(message)

        # validation
        reader.session.acknowledge.assert_called_once_with(message=message)
Пример #9
0
    def test_open_already(self):
        url = 'test-url'
        node = Mock(address='test')

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

        # validation
        self.assertFalse(reader.connection.open.called)
Пример #10
0
    def test_open_already(self):
        url = 'test-url'
        node = Mock(address='test')

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

        # validation
        self.assertFalse(reader.connection.open.called)
Пример #11
0
    def test_reject_rejected(self, disposition, rejected):
        message = Mock()

        # test
        reader = Reader(None, '')
        reader.session = Mock()
        reader.reject(message, False)

        # validation
        disposition.assert_called_once_with(rejected)
        reader.session.acknowledge.assert_called_once_with(
            message=message, disposition=disposition.return_value)
Пример #12
0
    def test_reject_rejected(self, disposition, rejected):
        message = Mock()

        # test
        reader = Reader(None, '')
        reader.session = Mock()
        reader.reject(message, False)

        # validation
        disposition.assert_called_once_with(rejected)
        reader.session.acknowledge.assert_called_once_with(
            message=message, disposition=disposition.return_value)
Пример #13
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)
Пример #14
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)
Пример #15
0
    def test_open(self, connection):
        url = 'test-url'
        node = Mock(address='test')

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

        # validation
        connection.return_value.open.assert_called_once_with()
        connection.return_value.session.assert_called_once_with()
        connection.return_value.session.return_value.receiver.assert_called_once_with(node.address)
        self.assertEqual(reader.session, connection.return_value.session.return_value)
        self.assertEqual(reader.receiver, reader.session.receiver.return_value)
Пример #16
0
    def test_get(self):
        queue = Queue('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.content)
Пример #17
0
    def test_get(self):
        queue = Queue('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.content)
Пример #18
0
    def test_open(self, connection):
        url = 'test-url'
        node = Mock(address='test')

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

        # validation
        connection.return_value.open.assert_called_once_with()
        connection.return_value.session.assert_called_once_with()
        connection.return_value.session.return_value.receiver.assert_called_once_with(
            node.address)
        self.assertEqual(reader.session,
                         connection.return_value.session.return_value)
        self.assertEqual(reader.receiver, reader.session.receiver.return_value)
Пример #19
0
    def test_close(self):
        connection = Mock()
        session = Mock(connection=connection)
        receiver = Mock()

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

        # validation
        receiver.close.assert_called_once_with()
        session.close.assert_called_once_with()
        self.assertFalse(connection.close.called)
Пример #20
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.session, None)
        self.assertEqual(reader.receiver, None)
Пример #21
0
    def test_close(self):
        connection = Mock()
        session = Mock(connection=connection)
        receiver = Mock()

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

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