-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f1479f
commit df656da
Showing
7 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,3 +135,6 @@ cython_debug/ | |
|
||
# Ignore config.yaml | ||
config/config.yaml | ||
|
||
# Ignore .vscode | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/unit/datacosmos/client/test_client_delete_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from unittest.mock import patch, MagicMock | ||
from datacosmos.client import DatacosmosClient | ||
from config.config import Config | ||
|
||
|
||
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client") | ||
def test_delete_request(mock_auth_client): | ||
""" | ||
Test that the client performs a DELETE request correctly. | ||
""" | ||
# Mock the HTTP client | ||
mock_http_client = MagicMock() | ||
mock_response = MagicMock() | ||
mock_response.status_code = 204 | ||
mock_http_client.request.return_value = mock_response | ||
mock_auth_client.return_value = mock_http_client | ||
|
||
config = Config( | ||
client_id="test-client-id", | ||
client_secret="test-client-secret", | ||
token_url="https://mock.token.url/oauth/token", | ||
audience="https://mock.audience", | ||
) | ||
client = DatacosmosClient(config=config) | ||
response = client.delete("https://mock.api/some-endpoint") | ||
|
||
# Assertions | ||
assert response.status_code == 204 | ||
mock_http_client.request.assert_called_once_with( | ||
"DELETE", | ||
"https://mock.api/some-endpoint" | ||
) | ||
mock_auth_client.call_count == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from unittest.mock import patch, MagicMock | ||
from datacosmos.client import DatacosmosClient | ||
from config.config import Config | ||
|
||
|
||
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client") | ||
def test_client_get_request(mock_auth_client): | ||
""" | ||
Test that the client performs a GET request correctly. | ||
""" | ||
# Mock the HTTP client | ||
mock_http_client = MagicMock() | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_response.json.return_value = {"message": "success"} | ||
mock_http_client.request.return_value = mock_response | ||
mock_auth_client.return_value = mock_http_client | ||
|
||
config = Config( | ||
client_id="test-client-id", | ||
client_secret="test-client-secret", | ||
token_url="https://mock.token.url/oauth/token", | ||
audience="https://mock.audience", | ||
) | ||
client = DatacosmosClient(config=config) | ||
response = client.get("https://mock.api/some-endpoint") | ||
|
||
# Assertions | ||
assert response.status_code == 200 | ||
assert response.json() == {"message": "success"} | ||
mock_http_client.request.assert_called_once_with( | ||
"GET", | ||
"https://mock.api/some-endpoint" | ||
) | ||
mock_auth_client.call_count == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest.mock import patch, MagicMock | ||
from datacosmos.client import DatacosmosClient | ||
from config.config import Config | ||
|
||
|
||
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client") | ||
def test_post_request(mock_auth_client): | ||
""" | ||
Test that the client performs a POST request correctly. | ||
""" | ||
# Mock the HTTP client | ||
mock_http_client = MagicMock() | ||
mock_response = MagicMock() | ||
mock_response.status_code = 201 | ||
mock_response.json.return_value = {"message": "created"} | ||
mock_http_client.request.return_value = mock_response | ||
mock_auth_client.return_value = mock_http_client | ||
|
||
config = Config( | ||
client_id="test-client-id", | ||
client_secret="test-client-secret", | ||
token_url="https://mock.token.url/oauth/token", | ||
audience="https://mock.audience", | ||
) | ||
client = DatacosmosClient(config=config) | ||
response = client.post( | ||
"https://mock.api/some-endpoint", json={"key": "value"} | ||
) | ||
|
||
# Assertions | ||
assert response.status_code == 201 | ||
assert response.json() == {"message": "created"} | ||
mock_http_client.request.assert_called_once_with( | ||
"POST", | ||
"https://mock.api/some-endpoint", | ||
json={"key": "value"} | ||
) | ||
mock_auth_client.call_count == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest.mock import patch, MagicMock | ||
from datacosmos.client import DatacosmosClient | ||
from config.config import Config | ||
|
||
|
||
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client") | ||
def test_put_request(mock_auth_client): | ||
""" | ||
Test that the client performs a PUT request correctly. | ||
""" | ||
# Mock the HTTP client | ||
mock_http_client = MagicMock() | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_response.json.return_value = {"message": "updated"} | ||
mock_http_client.request.return_value = mock_response | ||
mock_auth_client.return_value = mock_http_client | ||
|
||
config = Config( | ||
client_id="test-client-id", | ||
client_secret="test-client-secret", | ||
token_url="https://mock.token.url/oauth/token", | ||
audience="https://mock.audience", | ||
) | ||
client = DatacosmosClient(config=config) | ||
response = client.put( | ||
"https://mock.api/some-endpoint", json={"key": "updated-value"} | ||
) | ||
|
||
# Assertions | ||
assert response.status_code == 200 | ||
assert response.json() == {"message": "updated"} | ||
mock_http_client.request.assert_called_once_with( | ||
"PUT", | ||
"https://mock.api/some-endpoint", | ||
json={"key": "updated-value"} | ||
) | ||
mock_auth_client.call_count == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters