-
Notifications
You must be signed in to change notification settings - Fork 27
Support creating repositories under organizations during init #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -126,6 +126,7 @@ dmypy.json | |
|
|
||
| # IntelliJ | ||
| .idea/ | ||
| *.iml | ||
|
|
||
| # VSCode | ||
| .vscode/ | ||
|
|
||
This file contains hidden or 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 hidden or 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,86 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| import dagshub | ||
| from dagshub.common.api.repo import RepoNotFoundError | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_repo_api(mocker): | ||
| mock = mocker.patch("dagshub.common.init.RepoAPI") | ||
| mock.return_value.get_repo_info.side_effect = RepoNotFoundError() | ||
| return mock | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_user_api(mocker): | ||
| user = MagicMock() | ||
| user.username = "testuser" | ||
| mock = mocker.patch("dagshub.common.init.UserAPI") | ||
| mock.get_current_user.return_value = user | ||
| mock.get_user_from_token.return_value = user | ||
| return mock | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_create_repo(mocker): | ||
| return mocker.patch("dagshub.common.init.create_repo") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_get_token(mocker): | ||
| return mocker.patch("dagshub.common.init.get_token", return_value="fake-token") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_log_message(mocker): | ||
| return mocker.patch("dagshub.common.init.log_message") | ||
|
|
||
|
|
||
| def test_init_creates_repo_under_org_when_owner_differs( | ||
| mock_repo_api, mock_user_api, mock_create_repo, mock_get_token, mock_log_message | ||
| ): | ||
| dagshub.init(repo_owner="my-org", repo_name="my-repo", mlflow=False, dvc=False) | ||
|
|
||
| mock_user_api.get_current_user.assert_called_once() | ||
| mock_create_repo.assert_called_once_with("my-repo", org_name="my-org", host="https://dagshub.com") | ||
| mock_log_message.assert_any_call( | ||
| 'Repository my-repo doesn\'t exist, creating it under organization "my-org".' | ||
| ) | ||
|
|
||
|
|
||
| def test_init_creates_repo_under_current_user_when_owner_matches( | ||
| mock_repo_api, mock_user_api, mock_create_repo, mock_get_token, mock_log_message | ||
| ): | ||
| dagshub.init(repo_owner="testuser", repo_name="my-repo", mlflow=False, dvc=False) | ||
|
|
||
| mock_user_api.get_current_user.assert_called_once() | ||
| mock_create_repo.assert_called_once_with("my-repo", host="https://dagshub.com") | ||
| mock_log_message.assert_any_call( | ||
| "Repository my-repo doesn't exist, creating it under current user." | ||
| ) | ||
|
|
||
|
|
||
| def test_init_creates_repo_under_current_user_from_url( | ||
| mock_repo_api, mock_user_api, mock_create_repo, mock_get_token, mock_log_message | ||
| ): | ||
| dagshub.init(url="https://dagshub.com/testuser/my-repo", mlflow=False, dvc=False) | ||
|
|
||
| mock_user_api.get_current_user.assert_called_once() | ||
| mock_create_repo.assert_called_once_with("my-repo", host="https://dagshub.com") | ||
| mock_log_message.assert_any_call( | ||
| "Repository my-repo doesn't exist, creating it under current user." | ||
| ) | ||
|
|
||
|
|
||
| def test_init_creates_repo_under_org_from_url( | ||
| mock_repo_api, mock_user_api, mock_create_repo, mock_get_token, mock_log_message | ||
| ): | ||
| dagshub.init(url="https://dagshub.com/my-org/my-repo", mlflow=False, dvc=False) | ||
|
|
||
| mock_user_api.get_current_user.assert_called_once() | ||
| mock_create_repo.assert_called_once_with("my-repo", org_name="my-org", host="https://dagshub.com") | ||
| mock_log_message.assert_any_call( | ||
| 'Repository my-repo doesn\'t exist, creating it under organization "my-org".' | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.