コード例 #1
0
 def test_handle_json_response(self):
     m = mock.MagicMock()
     m.raise_for_status.side_effect = Exception("Test")
     with self.assertRaises(DownstreamError) as ex:
         utils.handle_json_response(m)
     
     m = mock.MagicMock()
     m.json.side_effect = ValueError
     with self.assertRaises(DownstreamError) as ex:
         utils.handle_json_response(m)
     
     m = mock.MagicMock()
     result = utils.handle_json_response(m)
コード例 #2
0
ファイル: test_unit.py プロジェクト: wiggzz/downstream-farmer
    def test_handle_json_response(self):
        m = mock.MagicMock()
        m.status_code = 400
        m.json.return_value = dict(message='test error')
        with self.assertRaises(DownstreamError) as ex:
            utils.handle_json_response(m)
        self.assertEqual(str(ex.exception), 'test error')

        m.json.side_effect = Exception('json processing error')
        m.raise_for_status.side_effect = Exception('http error')
        with self.assertRaises(Exception) as ex:
            utils.handle_json_response(m)
        self.assertEqual(str(ex.exception), 'http error')

        m = mock.MagicMock()
        m.json.return_value = dict(key='value')
        result = utils.handle_json_response(m)
        self.assertEqual(m.json.return_value, result)
コード例 #3
0
ファイル: test_unit.py プロジェクト: mstg/downstream-farmer
    def test_handle_json_response(self):
        m = mock.MagicMock()
        m.status_code = 400
        m.json.return_value = dict(message='test error')
        with self.assertRaises(DownstreamError) as ex:
            utils.handle_json_response(m)
        self.assertEqual(str(ex.exception), 'test error')

        m.json.side_effect = Exception('json processing error')
        m.raise_for_status.side_effect = Exception('http error')
        with self.assertRaises(Exception) as ex:
            utils.handle_json_response(m)
        self.assertEqual(str(ex.exception), 'http error')

        m = mock.MagicMock()
        m.json.return_value = dict(key='value')
        result = utils.handle_json_response(m)
        self.assertEqual(m.json.return_value, result)