Exemplo n.º 1
0
    def test_close(self):
        reader = Mock(channel=Mock())
        tag = 1234

        # test
        r = Receiver(reader)
        r.tag = tag
        r.close()

        # validation
        reader.channel.basic_cancel.assert_called_once_with(tag)
Exemplo n.º 2
0
    def test_fetch_empty(self):
        channel = Mock()
        reader = Mock(channel=channel)

        # test
        r = Receiver(reader)
        r.inbox = Mock()
        r.inbox.empty.return_value = False
        r.inbox.get.side_effect = Empty
        r._wait = Mock(side_effect=r.inbox.put)
        self.assertRaises(r.fetch)
Exemplo n.º 3
0
    def test_close(self):
        reader = Mock(channel=Mock())
        tag = 1234

        # test
        r = Receiver(reader)
        r.tag = tag
        r.close()

        # validation
        reader.channel.basic_cancel.assert_called_once_with(tag)
Exemplo n.º 4
0
    def test_open(self):
        node = Mock(address='test')
        reader = Mock(node=node, channel=Mock())

        # test
        r = Receiver(reader)
        r = r.open()

        # validation
        reader.channel.basic_consume.assert_called_once_with(node.address, callback=r.inbox.put)
        self.assertEqual(r.tag, reader.channel.basic_consume.return_value)
Exemplo n.º 5
0
    def test_fetch_empty(self):
        channel = Mock()
        reader = Mock(channel=channel)

        # test
        r = Receiver(reader)
        r.inbox = Mock()
        r.inbox.empty.return_value = False
        r.inbox.get.side_effect = Empty
        r._wait = Mock(side_effect=r.inbox.put)
        self.assertRaises(r.fetch)
Exemplo n.º 6
0
    def test_close_exception(self):
        reader = Mock()
        reader.channel.basic_cancel.side_effect = ValueError
        tag = 1234

        # test
        r = Receiver(reader)
        r.tag = tag
        r.close()

        # validation
        reader.channel.basic_cancel.assert_called_once_with(tag)
Exemplo n.º 7
0
    def test_open(self):
        node = Mock(address='test')
        reader = Mock(node=node, channel=Mock())

        # test
        r = Receiver(reader)
        r = r.open()

        # validation
        reader.channel.basic_consume.assert_called_once_with(
            node.address, callback=r.inbox.put)
        self.assertEqual(r.tag, reader.channel.basic_consume.return_value)
Exemplo n.º 8
0
    def test_close_exception(self):
        reader = Mock()
        reader.channel.basic_cancel.side_effect = ValueError
        tag = 1234

        # test
        r = Receiver(reader)
        r.tag = tag
        r.close()

        # validation
        reader.channel.basic_cancel.assert_called_once_with(tag)
Exemplo n.º 9
0
    def test_wait_with_queued(self, epoll):
        fd = 0
        channel = Mock(method_queue=[Mock()])
        timeout = 10

        epoll.return_value.poll.return_value = [fd]

        # test
        Receiver._wait(fd, channel, timeout)

        # validation
        self.assertFalse(epoll.called)
        channel.wait.assert_called_once_with()
Exemplo n.º 10
0
    def test_wait(self, epoll):
        fd = 0
        channel = Mock(method_queue=[Mock()])
        timeout = 10

        epoll.return_value.poll.return_value = [fd]

        # test
        Receiver._wait(fd, channel, timeout)

        # validation
        self.assertFalse(epoll.called)
        channel.wait.assert_called_once_with()
Exemplo n.º 11
0
    def test_wait_nothing(self, epoll):
        fd = 0
        channel = Mock(method_queue=[])
        timeout = 10

        epoll.return_value.poll.return_value = []

        # test
        Receiver._wait(fd, channel, timeout)

        # validation
        epoll.assert_called_once_with()
        epoll.return_value.register.assert_called_with(fd, select.EPOLLIN)
        epoll.return_value.poll.assert_called_with(timeout)
        self.assertFalse(channel.wait.called)
Exemplo n.º 12
0
    def test_wait_nothing(self, epoll):
        fd = 0
        channel = Mock(method_queue=[])
        timeout = 10

        epoll.return_value.poll.return_value = []

        # test
        Receiver._wait(fd, channel, timeout)

        # validation
        epoll.assert_called_once_with()
        epoll.return_value.register.assert_called_with(fd, select.EPOLLIN)
        epoll.return_value.poll.assert_called_with(timeout)
        self.assertFalse(channel.wait.called)
Exemplo n.º 13
0
    def test_wait(self, basic, epoll):
        fd = 0
        channel = Mock(method_queue=[])
        timeout = 10

        epoll.return_value.poll.return_value = [fd]
        basic.Deliver = (10, 70)

        # test
        Receiver._wait(fd, channel, timeout)

        # validation
        epoll.assert_called_once_with()
        epoll.return_value.register.assert_called_with(fd, select.EPOLLIN)
        epoll.return_value.poll.assert_called_with(timeout)
        channel.wait.assert_called_once_with(basic.Deliver)
Exemplo n.º 14
0
    def test_wait(self, basic, epoll):
        fd = 0
        channel = Mock(method_queue=[])
        timeout = 10

        epoll.return_value.poll.return_value = [fd]
        basic.Deliver = (10, 70)

        # test
        Receiver._wait(fd, channel, timeout)

        # validation
        epoll.assert_called_once_with()
        epoll.return_value.register.assert_called_with(fd, select.EPOLLIN)
        epoll.return_value.poll.assert_called_with(timeout)
        channel.wait.assert_called_once_with(basic.Deliver)
Exemplo n.º 15
0
    def test_fetch(self):
        timeout = 10
        channel = Mock()
        reader = Mock(channel=channel)
        received = 33

        # test
        r = Receiver(reader)
        r.inbox = Mock()
        r.inbox.empty.return_value = True
        r.inbox.get.return_value = received
        r._wait = Mock(side_effect=r.inbox.put)
        message = r.fetch(timeout)

        # validation
        fd = channel.connection.sock.fileno.return_value
        r._wait.assert_called_once_with(fd, channel, timeout)
        self.assertEqual(message, received)
Exemplo n.º 16
0
    def test_fetch(self):
        timeout = 10
        channel = Mock()
        reader = Mock(channel=channel)
        received = 33

        # test
        r = Receiver(reader)
        r.inbox = Mock()
        r.inbox.empty.return_value = True
        r.inbox.get.return_value = received
        r._wait = Mock(side_effect=r.inbox.put)
        message = r.fetch(timeout)

        # validation
        fd = channel.connection.sock.fileno.return_value
        r._wait.assert_called_once_with(fd, channel, timeout)
        self.assertEqual(message, received)
Exemplo n.º 17
0
 def test_channel(self):
     reader = Mock(channel=Mock())
     r = Receiver(reader)
     channel = r.channel()
     self.assertEqual(channel, reader.channel)
Exemplo n.º 18
0
 def test_init(self):
     reader = Mock()
     r = Receiver(reader)
     self.assertEqual(r.reader, reader)
     self.assertEqual(r.tag, None)
     self.assertTrue(isinstance(r.inbox, Inbox))
Exemplo n.º 19
0
 def test_channel(self):
     reader = Mock(channel=Mock())
     r = Receiver(reader)
     channel = r.channel()
     self.assertEqual(channel, reader.channel)