Example #1
0
    def test__get_response_Should_CallResponseRaiseForStatus_When_ResponseNotOk(
            self, *patches):
        mock_response = Mock(ok=False)
        mock_response.json.return_value = {
            'message': 'error message',
            'details': 'error details'
        }
        mock_response.raise_for_status.side_effect = [
            Exception('exception occurred')
        ]

        client = RESTclient('hostname1.company.com')
        with self.assertRaises(Exception):
            client.get_response(mock_response)
Example #2
0
 def test__get_response_Should_ReturnResponseText_When_ResponseJsonRaisesValueError(
         self, *patches):
     mock_response = Mock(ok=True, text='response text')
     mock_response.json.side_effect = [ValueError('No JSON')]
     client = RESTclient('hostname1.company.com')
     result = client.get_response(mock_response)
     self.assertEqual(result, 'response text')
Example #3
0
 def test__get_response_Should_ReturnResponseJson_When_ResponseOk(
         self, *patches):
     mock_response = Mock(ok=True)
     mock_response.json.return_value = {'result': 'result'}
     client = RESTclient('hostname1.company.com')
     result = client.get_response(mock_response)
     self.assertEqual(result, mock_response.json.return_value)
Example #4
0
 def test__get_response_Should_ReturnRawResponse_When_RawResponse(
         self, *patches):
     mock_response = Mock()
     client = RESTclient('hostname1.company.com')
     result = client.get_response(mock_response, raw_response=True)
     self.assertEqual(result, mock_response)