Esempio n. 1
0
    def test_put(self):
        def put(url, data, **kwargs):
            pass

        with patch.object(requests, 'put', side_effects=put) as mock_put:
            test_path = 'test_path'
            test_data = {'test': 'test'}

            client = Client(TEST_API_URL)
            client.put(test_path, data=test_data)

        self.assertTrue(mock_put.called)
        expected_url_call = TEST_API_URL + '/' + test_path
        mock_put.assert_called_with(expected_url_call,
                                    data=test_data,
                                    headers=AUTH_HEADERS)
Esempio n. 2
0
    def test_put_invalid_response(self):
        test_data = {'test': 'test'}

        def put(url, data, **kwargs):
            return FakeResponse()

        response = FakeResponse()

        with patch.object(requests,
                          'put',
                          side_effects=put,
                          return_value=response) as mock_put:
            test_path = 'test_path'

            client = Client(TEST_API_URL)
            with self.assertRaises(InvalidJSONError):
                client.put(test_path, data=test_data)

        self.assertTrue(mock_put.called)
        expected_url_call = TEST_API_URL + '/' + test_path
        mock_put.assert_called_with(expected_url_call,
                                    data=test_data,
                                    headers=AUTH_HEADERS)