def test_process_results_success(self): test_object = MagicMock() test_object.status_code = 200 test_object.json.return_value = {'message': 'This is just a tribute!'} result = process_results(test_object) self.assertDictEqual({'message': 'This is just a tribute!'}, result) expected_calls = [call.json()] self.assertListEqual(expected_calls, test_object.mock_calls)
def test_process_results_bad_json_call(self): test_object = MagicMock() test_object.status_code = 200 test_object.json.side_effect = ValueError('Nickleback') with self.assertRaises(ValueError) as exc_info: process_results(test_object) self.assertTrue('Nickleback' in exc_info.exception) expected_calls = [call.json()] self.assertListEqual(expected_calls, test_object.mock_calls)
def test_dict_and_string(self, mock_json, mock_markdown): """Test st.write with dict.""" manager = Mock() manager.attach_mock(mock_json, 'json') manager.attach_mock(mock_markdown, 'markdown') st.write('here is a dict', {'a': 1, 'b': 2}, ' and that is all') expected_calls = [ call.markdown('here is a dict'), call.json({'a': 1, 'b': 2}), call.markdown(' and that is all'), ] self.assertEqual(manager.mock_calls, expected_calls)
def test_dict_and_string(self, mock_json, mock_markdown): """Test st.write with dict.""" manager = Mock() manager.attach_mock(mock_json, "json") manager.attach_mock(mock_markdown, "markdown") st.write("here is a dict", {"a": 1, "b": 2}, " and that is all") expected_calls = [ call.markdown("here is a dict", unsafe_allow_html=False), call.json({"a": 1, "b": 2}), call.markdown(" and that is all", unsafe_allow_html=False), ] self.assertEqual(manager.mock_calls, expected_calls)