-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Create project with adding
_user_id
for NotFoundException
GitOrigin-RevId: 5fb82814ac62c90c9a9389faa7fc938e1e4ca487
- Loading branch information
1 parent
786ae78
commit 4d3d914
Showing
2 changed files
with
62 additions
and
3 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
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,56 @@ | ||
from unittest.mock import call, patch | ||
|
||
from gretel_client.gretel.interface import Gretel | ||
from gretel_client.projects.projects import Project | ||
from gretel_client.rest.exceptions import NotFoundException | ||
from python.tests.gretel_client.test_errors import MockResponse | ||
|
||
|
||
@patch( | ||
"gretel_client.gretel.interface.get_me", return_value={"_id": "01234567_user_id"} | ||
) | ||
@patch("gretel_client.gretel.interface.add_session_context", return_value=None) | ||
@patch("gretel_client.gretel.interface.configure_session", return_value=None) | ||
@patch("gretel_client.gretel.interface.get_project") | ||
def test_project_creation( | ||
mock_get_project, mock_configure_session, mock_add_session_context, mock_user_id | ||
): | ||
""" | ||
Test Gretel with existing project creates project with user_id suffix. | ||
""" | ||
unique_project_name = "project-name-user_id" | ||
mock_get_project.side_effect = [ | ||
NotFoundException( | ||
http_resp=MockResponse( | ||
reason="NotFound", status=404, resp={"message": "not found"} | ||
) | ||
), | ||
Project( | ||
name=unique_project_name, | ||
project_id="project_id", | ||
project_guid="project_guid", | ||
session=mock_configure_session, | ||
), | ||
] | ||
gretel = Gretel( | ||
project_name="project-name", | ||
api_key="grtu...", | ||
endpoint="https://api-dev.gretel.cloud", | ||
validate=True, | ||
) | ||
assert mock_get_project.call_count == 2 | ||
assert mock_get_project.call_args_list[0] == call( | ||
name="project-name", | ||
display_name="project-name", | ||
desc=None, | ||
create=True, | ||
session=None, | ||
) | ||
assert mock_get_project.call_args_list[1] == call( | ||
name=unique_project_name, | ||
display_name="project-name", | ||
desc=None, | ||
create=True, | ||
session=None, | ||
) | ||
assert gretel._project.name == unique_project_name |