from django.test import Client, TestCase from django.core.urlresolvers import reverse from unittest import mock from ..ingestion import Ingestion import json client = Client() class TestViews(TestCase): def test_add_build_receives_json(self): test_json_dict = {'name': 'feature name', 'elements': 'results'} test_json = json.dumps(test_json_dict) with mock.patch.object(Ingestion, 'run') as mock_run: response = client.post(reverse('add_build'), content_type='application/json', data=test_json) self.assertEqual(response.status_code, 200) mock_run.assert_called_once_with(test_json.encode("utf-8"))