예제 #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(result_queue_ttl=0)
     func = MagicMock(_send_result=True)
     call = _TaskCaller(func, 'testname', app, 'testexchange', 'testqueue')
     ret = call.apply_async(('one', 'two'), {'three': 'four'},
                            send_result=True)
     self.assertTrue(isinstance(ret, AsyncResult))
     body_matcher = JsonMatcher(
         self, {
             'task': 'testname',
             'args': ['one', 'two'],
             'kwargs': {
                 'three': 'four'
             }
         })
     msg_mock.assert_called_with(body_matcher,
                                 content_type='application/json',
                                 reply_to=ANY,
                                 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
파일: test_app.py 프로젝트: RSEmail/provoke
 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(result_queue_ttl=0)
     func = MagicMock(_send_result=True)
     call = _TaskCaller(func, 'testname', app, 'testexchange', 'testqueue')
     ret = call.apply_async(('one', 'two'), {'three': 'four'},
                            send_result=True)
     self.assertTrue(isinstance(ret, AsyncResult))
     body_matcher = JsonMatcher(self, {'task': 'testname',
                                       'args': ['one', 'two'],
                                       'kwargs': {'three': 'four'}})
     msg_mock.assert_called_with(body_matcher,
                                 content_type='application/json',
                                 reply_to=ANY,
                                 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)
예제 #3
0
파일: test_app.py 프로젝트: RSEmail/provoke
 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')
예제 #4
0
파일: test_app.py 프로젝트: RSEmail/provoke
 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'})
예제 #5
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')
예제 #6
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'})