Пример #1
0
 def test_create_case(self, mock_dumps):
     client = sfdc.Client(self.auth)
     client._request = mock.Mock(return_value="response")
     self.assertEqual("response", client.create_case("case_data"))
     client._request.assert_called_once_with(
         "POST", "/services/data/v36.0/sobjects/Case", data="json_data")
     mock_dumps.assert_called_once_with("case_data")
Пример #2
0
    def test__request_raises(self, mock_log, mock_requests):
        mock_requests.request.side_effect = ValueError

        client = sfdc.Client(self.auth)
        result = client._request("POST", "/foo/bar",
                                 headers={"Spam": "Quiz"}, foo=42)
        self.assertEqual((None, None, None), result)
Пример #3
0
 def test_authenticate(self):
     client = sfdc.Client(self.auth)
     self.assertIsNone(client.access_token)
     self.assertIsNone(client.instance_url)
     self.assertIsNone(client.authenticate())
     self.assertEqual("foo_token", client.access_token)
     self.assertEqual("foo_url", client.instance_url)
Пример #4
0
    def test__request_json_raises(self, mock_log, mock_requests):
        mock_resp = mock.Mock(status_code=200, text="some response body")
        mock_resp.json.side_effect = ValueError
        mock_requests.request.return_value = mock_resp

        client = sfdc.Client(self.auth)
        result = client._request("POST", "/foo/bar",
                                 headers={"Spam": "Quiz"}, foo=42)
        self.assertEqual((200, {}, None), result)
Пример #5
0
    def test__request_with_empty_response(self, mock_log, mock_requests):
        mock_resp = mock.Mock(status_code=200, text="")
        mock_resp.json.return_value = {"json": 42}
        mock_requests.request.return_value = mock_resp

        client = sfdc.Client(self.auth)
        result = client._request("POST", "/foo/bar",
                                 headers={"Spam": "Quiz"}, foo=42)
        self.assertEqual((200, {}, None), result)
Пример #6
0
    def test__request_got_error(self, mock_log, mock_requests):
        mock_resp = mock.Mock(status_code=400, text="some data")
        mock_resp.json.return_value = [{"errorCode": "FOO",
                                        "message": "Foo!"}]
        mock_requests.request.return_value = mock_resp

        client = sfdc.Client(self.auth)
        result = client._request("POST", "/foo/bar",
                                 headers={"Spam": "Quiz"}, foo=42)
        expected = (
            400, [{"errorCode": "FOO", "message": "Foo!"}], ("FOO", "Foo!"))
        self.assertEqual(expected, result)
Пример #7
0
    def test__request_got_invalid_session_id(self, mock_log, mock_requests):
        mock_resp = mock.Mock(status_code=400, text="some data")
        mock_resp.json.return_value = [{"errorCode": "INVALID_SESSION_ID",
                                        "message": "Foo!"}]
        mock_requests.request.return_value = mock_resp

        client = sfdc.Client(self.auth)
        result = client._request("POST", "/foo/bar", foo=42)
        expected = (400,
                    [{"errorCode": "INVALID_SESSION_ID", "message": "Foo!"}],
                    ("INVALID_SESSION_ID", "Foo!"))
        self.assertEqual(expected, result)
        self.assertEqual(4, len(mock_requests.request.mock_calls))
Пример #8
0
    def test__request(self, mock_log, mock_requests):
        mock_resp = mock.Mock(status_code=200, text="some data")
        mock_resp.json.return_value = {"json": 42}
        mock_requests.request.return_value = mock_resp

        client = sfdc.Client(self.auth)
        result = client._request("POST", "/foo/bar",
                                 headers={"Spam": "Quiz"}, foo=42)
        headers = {"Content-Type": "application/json",
                   "Authorization": "Bearer foo_token", "Spam": "Quiz"}
        mock_requests.request.assert_called_once_with(
            "POST", "foo_url/foo/bar", headers=headers, verify=None, foo=42)
        self.assertEqual((200, {"json": 42}, None), result)
Пример #9
0
 def test_get_case(self):
     client = sfdc.Client(self.auth)
     client._request = mock.Mock(return_value="response")
     self.assertEqual("response", client.get_case(42))
     client._request.assert_called_once_with(
         "GET", "/services/data/v36.0/sobjects/Case/42")