def test_failed_request(self): EventTracker.endpoint = 'brokenurl' with eager_tasks(): result = EventTracker.delay('event_foo') self.assertNotEqual(result.traceback, None)
def test_delay_or_eager_runs(self, mock_calculate_result): with eager_tasks(): async_task = self.task.delay_or_eager(result=1) self.assertEqual(async_task.status, states.SUCCESS) self.assertEqual(async_task.result, 1) self.assertEqual(mock_calculate_result.call_count, 1)
def test_instantiated_event_tracker_delay(self): with eager_tasks(): result = event_tracker.delay('event_foo') self.assertTrue(result) self.assertParams({ 'event': 'event_foo', 'properties': {'token': 'testtesttest'} })
def test_instantiated_event_tracker_delay(self): with eager_tasks(): result = event_tracker.delay('event_foo') self.assertTrue(result) self.assertParams({ 'event': 'event_foo', 'properties': { 'token': 'testtesttest' } })
def test_URL_post_async(self): def with_eager_tasks(_val): def with_mock_urlopen(_val): d = http.URL("http://example.com/mul").post_async(x=10, y=10) self.assertEqual(d.get(), 100) context = mock_urlopen(success_response(100)) execute_context(context, with_mock_urlopen) execute_context(eager_tasks(), with_eager_tasks)
def test_instantiated_people_tracker_delay(self): with eager_tasks(): result = people_tracker.delay('set', { 'distinct_id': 'x', 'foo': 'bar', }) self.assertTrue(result) self.assertParams({ '$distinct_id': 'x', '$token': 'testtesttest', '$set': {'foo': 'bar'}, })
def test_starts_with_progress_state(self): # The state has already been set to PROGRESS before `calculate_result` # starts with eager_tasks(): with mock.patch.object( self.task, 'calculate_result', autospec=True, side_effect=task_status_is_progress, ): async_task = self.task.delay(count_to=2) # And the state should still be set to SUCCESS in the end self.assertEqual(async_task.status, SUCCESS)
def test_instantiated_people_tracker_delay(self): with eager_tasks(): result = people_tracker.delay('set', { 'distinct_id': 'x', 'foo': 'bar', }) self.assertTrue(result) self.assertParams({ '$distinct_id': 'x', '$token': 'testtesttest', '$set': { 'foo': 'bar' }, })
def test_instantiated_funnel_tracker_delay(self): with eager_tasks(): result = funnel_tracker.delay('test_funnel', 'test_step', 'test_goal', {'distinct_id': 'test_user'}) self.assertTrue(result) self.assertParams({ 'event': 'mp_funnel', 'properties': { 'distinct_id': 'test_user', 'funnel': 'test_funnel', 'goal': 'test_goal', 'step': 'test_step', 'token': 'testtesttest'} })
def test_instantiated_funnel_tracker_delay(self): with eager_tasks(): result = funnel_tracker.delay('test_funnel', 'test_step', 'test_goal', {'distinct_id': 'test_user'}) self.assertTrue(result) self.assertParams({ 'event': 'mp_funnel', 'properties': { 'distinct_id': 'test_user', 'funnel': 'test_funnel', 'goal': 'test_goal', 'step': 'test_step', 'token': 'testtesttest' } })
def test_failed_socket_request(self): mp_settings.MIXPANEL_API_SERVER = '127.0.0.1:60000' with eager_tasks(): result = EventTracker.delay('event_foo') self.assertNotEqual(result.traceback, None)
def test_failed_socket_request(self): self.response.read = Mock(side_effect=socket.error('BOOM')) with eager_tasks(): result = EventTracker.delay('event_foo') self.assertNotEqual(result.traceback, None)
def test_failed_request(self): self.response.status = 400 with eager_tasks(): result = EventTracker.delay('event_foo') self.assertNotEqual(result.traceback, None)
def test_sanity(self): # The task actually runs with eager_tasks(): async_task = self.task.delay(result=1) self.assertEqual(async_task.status, states.SUCCESS) self.assertEqual(async_task.result, 1)
def test_URL_post_async(self): with eager_tasks(): with mock_urlopen(success_response(100)): d = http.URL("http://example.com/mul").post_async(x=10, y=10) self.assertEqual(d.get(), 100)
def test_URL_post_async(self): with eager_tasks(): with mock_urlopen(success_response(100)): d = http.URL('http://example.com/mul').post_async(x=10, y=10) self.assertEqual(d.get(), 100)
def test_sanity(self): # The task actually runs with eager_tasks(): async_task = self.task.delay(count_to=2) self.assertEqual(async_task.status, SUCCESS) self.assertEqual(async_task.result, 2)