def test_task_post_data(self, mock_requests): mock_requests.post.return_value.status_code = 200 d = DeliverHook() ret = d.post_data('http://www.example.com', {'junk': 'payload'}) self.assertEqual(ret.status_code, 200)
def test_task_delete_hook(self, mock_requests): # post_data deletes hooks when the status code is 410 mock_requests.post.return_value.status_code = 410 h = hook_models.Hook() h.url = 'http://example.com/project/delete/me/' h.project = self.project h.save() d = DeliverHook() # We're testing we don't have hook deleted, since we're not passing in the hook id ret = d.post_data('http://example.com/api/123', {'junk': 'payload'}) hook_models.Hook.objects.get(pk=h.pk)
def test_task_delete_hook_410(self, mock_requests): # post_data deletes hooks when the status code is 410 mock_requests.post.return_value.status_code = 410 h = hook_models.Hook() h.url = 'http://example.com/project/delete/me/' h.project = self.project h.save() hook_id = h.pk d = DeliverHook() ret = d.post_data('http://example.com/api/123', {'junk': 'payload'}, hook_id) def look_up_error(hook_id): hook_models.Hook.objects.get(pk=hook_id) self.assertRaises(hook_models.Hook.DoesNotExist, look_up_error, hook_id)
def test_task_post_data_run(self): d = DeliverHook() ret = d.run('http://www.example.com', {'junk': 'payload'})