status_code=200) with patch("json.loads", return_value=({"hits": {"total": 0}})): output = search_elastic_server('test123') self.assertEqual(output, False) def test_key_error_parse_json(self): response = parse_json({}) self.assertEqual(response['error'], 'something wrong with JSON object.') def test_successful_parsing_of_json(self): dummyJson = { "instructors": [], "key": "testapp", "image": "", "title": "Intro to Deep Learning", "slug": "intro-to-deep-learning--ud101app?utm_medium=referral&utm_campaign=api", "short_summary": "", "level": "", "expected_duration_unit": "", "summary": "Learn how to learn.", "expected_duration": 0 } response = parse_json(dummyJson) self.assertEqual(response['CourseProvider'], 'udacity') if __name__ == '__main__': suite = TestCase.loadTestsFromTestCase(Testudacity) TestCase.TextTestRunner().run(suite)