Пример #1
0
 def test_apply_async(self, msg_mock, amqp_exit_mock, amqp_enter_mock):
     channel = MagicMock()
     amqp_enter_mock.return_value = channel
     msg_mock.return_value = 52
     app = MagicMock()
     call = _TaskCaller('testfunc', 'testname', app, 'testexchange',
                       'testqueue')
     ret = call.apply_async(('one', 'two'), {'three': 'four'})
     self.assertTrue(isinstance(ret, _AsyncResult))
     body_matcher = JsonMatcher(self, {'task_name': 'testname',
                                       'args': ['one', 'two'],
                                       'kwargs': {'three': 'four'}})
     msg_mock.assert_called_with(body_matcher,
                                 content_type='application/json',
                                 correlation_id=ANY)
     amqp_enter_mock.assert_called_with()
     channel.basic_publish.assert_called_with(52, exchange='testexchange',
                                              routing_key='testqueue')
     amqp_exit_mock.assert_called_with(None, None, None)
Пример #2
0
 def test_call(self):
     func = MagicMock(return_value=13)
     call = _TaskCaller(func, 'a', 'b', 'c', 'd')
     ret = call('one', 'two', three='four')
     self.assertEqual(13, ret)
     func.assert_called_with('one', 'two', three='four')
Пример #3
0
 def test_delay(self):
     call = _TaskCaller('a', 'b', 'c', 'd', 'e')
     call.apply_async = MagicMock()
     call.delay('stuff', 13, test='what')
     call.apply_async.assert_called_with(('stuff', 13), {'test': 'what'})