Ejemplo 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())
Ejemplo 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())
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)