def test_get_cached(self): res = AsyncResult(None) res._result = True res._return = 123 self.assertEqual(123, res.get()) del res._return res._exc = ValueError self.assertRaises(ValueError, res.get)
def test_get_nonblock(self, exit_mock, enter_mock): enter_mock.return_value = channel = MagicMock() exit_mock.return_value = None msg = MagicMock(correlation_id='abc123', body='{"return": 123}') channel.basic_get.return_value = msg res = AsyncResult('test_results') self.assertEqual(123, res.get(0.0)) exit_mock.assert_called_with(None, None, None) channel.basic_get.assert_called_with(queue='test_results', no_ack=True)
def test_get(self, exit_mock, enter_mock): enter_mock.return_value = channel = MagicMock() exit_mock.return_value = None msg = MagicMock(correlation_id='abc123', body='{"return": 123}') def add_msg(queue, callback): callback(msg) channel.basic_consume.side_effect = add_msg res = AsyncResult('test_results') self.assertEqual(123, res.get()) exit_mock.assert_called_with(GeneratorExit, ANY, ANY) channel.basic_consume.assert_called_with(queue='test_results', callback=ANY) channel.connection.drain_events.assert_called_with(timeout=10.0) self.assertFalse(channel.connection.send_heartbeat.called)