-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add project files to datasets from service #877
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
Changes from all commits
ee1277a
341ed22
61e78c4
2f76b4d
13d7e85
be1e125
2f4f2b5
5d9b02f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import requests | ||
| import yaml | ||
|
|
||
| from renku.cli import cli | ||
|
|
@@ -1278,6 +1279,7 @@ def test_avoid_empty_commits(runner, client, directory_tree): | |
| result = runner.invoke( | ||
| cli, ['dataset', 'add', 'my-dataset', directory_tree.strpath] | ||
| ) | ||
|
|
||
| assert 0 == result.exit_code | ||
|
|
||
| commit_sha_after = client.repo.head.object.hexsha | ||
|
|
@@ -1291,18 +1293,59 @@ def test_avoid_empty_commits(runner, client, directory_tree): | |
|
|
||
| commit_sha_after = client.repo.head.object.hexsha | ||
| assert commit_sha_before == commit_sha_after | ||
| assert 'Error: There is nothing to commit.' in result.output | ||
| assert 'Error: File already exists in dataset.' in result.output | ||
|
|
||
|
|
||
| def test_add_removes_credentials(runner, client): | ||
| """Test credentials are removed when adding to a dataset.""" | ||
| url = 'https://username:password@example.com/index.html' | ||
| result = runner.invoke(cli, ['dataset', 'add', '-c', 'my-dataset', url]) | ||
| def test_multiple_dataset_commits(runner, client, directory_tree): | ||
| """Check adding existing data to multiple datasets.""" | ||
| commit_sha_before = client.repo.head.object.hexsha | ||
| result = runner.invoke( | ||
| cli, ['dataset', 'add', '-c', 'my-dataset1', directory_tree.strpath] | ||
| ) | ||
|
|
||
| assert 0 == result.exit_code | ||
|
|
||
| with client.with_dataset('my-dataset') as dataset: | ||
| file_ = dataset.files[0] | ||
| assert file_.url == 'https://example.com/index.html' | ||
| commit_sha_after = client.repo.head.object.hexsha | ||
| assert commit_sha_before != commit_sha_after | ||
|
|
||
| commit_sha_before = commit_sha_after | ||
| result = runner.invoke( | ||
| cli, ['dataset', 'add', '-c', 'my-dataset2', directory_tree.strpath] | ||
| ) | ||
| assert 0 == result.exit_code | ||
|
|
||
| commit_sha_after = client.repo.head.object.hexsha | ||
| assert commit_sha_before != commit_sha_after | ||
|
|
||
|
|
||
| def test_add_same_filename_multiple(runner, client, directory_tree): | ||
| """Check adding same filename multiple times.""" | ||
| result = runner.invoke( | ||
| cli, ['dataset', 'add', '-c', 'my-dataset1', directory_tree.strpath] | ||
| ) | ||
|
|
||
| assert 0 == result.exit_code | ||
|
|
||
| result = runner.invoke( | ||
| cli, ['dataset', 'add', 'my-dataset1', directory_tree.strpath] | ||
| ) | ||
| assert 1 == result.exit_code | ||
| assert 'Error: File already exists in dataset.' in result.output | ||
|
|
||
| result = runner.invoke( | ||
| cli, | ||
| ['dataset', 'add', '--force', 'my-dataset1', directory_tree.strpath] | ||
| ) | ||
| assert 1 == result.exit_code | ||
| assert 'Error: There is nothing to commit.' in result.output | ||
|
|
||
| result = runner.invoke( | ||
| cli, [ | ||
| 'dataset', 'add', '--force', 'my-dataset1', directory_tree.strpath, | ||
| 'Dockerfile' | ||
| ] | ||
| ) | ||
| assert 0 == result.exit_code | ||
|
|
||
|
|
||
| def test_add_removes_local_path_information(runner, client, directory_tree): | ||
|
|
@@ -1316,3 +1359,23 @@ def test_add_removes_local_path_information(runner, client, directory_tree): | |
| for file_ in dataset.files: | ||
| assert file_.url.startswith('file://../') | ||
| assert file_.url.endswith(file_.name) | ||
|
|
||
|
|
||
| def test_add_remove_credentials(runner, client, monkeypatch): | ||
| """Check removal of credentials during adding of remote data files.""" | ||
| url = 'https://username:password@example.com/index.html' | ||
|
|
||
| def get(u): | ||
| """Mocked response.""" | ||
| response = requests.Response() | ||
| response._content = b'{}' | ||
| return response | ||
|
|
||
| result = runner.invoke(cli, ['dataset', 'create', 'my-dataset']) | ||
| assert 0 == result.exit_code | ||
|
|
||
| monkeypatch.setattr(requests, 'get', get) | ||
| dataset = client.load_dataset('my-dataset') | ||
| o = client._add_from_url(dataset, url, client.path) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to avoid calling a non-public method in this test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That client abstraction should really be fixed (IMHO), cause isolating pieces in testable units is almost impossible without resorting to such calls.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get why you removed the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I din't removed anything, that test the way it was written it was integration test and it was not marked as such - I just marked it as an integration test and wrote the actual unit test for the part of what that test is suppose to be testing since @rokroskar requested to have it. I would also be fine just with having it as an integration test, tbh. |
||
|
|
||
| assert 'https://example.com/index.html' == o[0]['url'] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -968,3 +968,15 @@ def test_renku_clone_uses_project_name( | |
| result = runner.invoke(cli, ['clone', REMOTE, path]) | ||
| assert 0 == result.exit_code | ||
| assert (Path(project_path) / expected_path / 'Dockerfile').exists() | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_add_removes_credentials(runner, client): | ||
| """Check removal of credentials during adding of remote data files.""" | ||
| url = 'https://username:password@example.com/index.html' | ||
| result = runner.invoke(cli, ['dataset', 'add', '-c', 'my-dataset', url]) | ||
| assert 0 == result.exit_code | ||
|
|
||
| with client.with_dataset('my-dataset') as dataset: | ||
| file_ = dataset.files[0] | ||
| assert file_.url == 'https://example.com/index.html' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right, it should be other way around - thanks!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do not start the discussion about expected and actual ;). |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug reported in #881 can be solved by moving the commit statement to this
ifblock and removing return from here:Like this we avoid an empty commit if there is no change in data files and we allow the metadata to be updated (which was prevented previously by returning early).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in that case adding ignored files would fail to be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Added ignored files show up as dirty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How? If they are ignored it means that they are part of the
.gitignoreand git won't register them at all.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If users do not use
--forceand there are ignored files then this function raises an exception and won't reach this point.