Exemplo 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())
Exemplo 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())
Exemplo 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)
Exemplo 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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo 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)
Exemplo 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)