-
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.
Tests: api-server in test_context and not as arg
Signed-off-by: Martin Vrachev <[email protected]>
- Loading branch information
Showing
4 changed files
with
71 additions
and
69 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
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 |
---|---|---|
|
@@ -257,7 +257,7 @@ def test__get_succinct_roles_failed_parsing(self, monkeypatch): | |
|
||
|
||
class TestImportArtifactsGroupCLI: | ||
def test_import_artifacts(self): | ||
def test_import_artifacts(self, test_context): | ||
# Required to properly mock functions imported inside import_artifacts | ||
import sqlalchemy | ||
|
||
|
@@ -293,16 +293,18 @@ def test_import_artifacts(self): | |
) | ||
|
||
args = [ | ||
"--api-server", | ||
"http://127.0.0.1", | ||
"--db-uri", | ||
"postgresql://postgres:[email protected]:5433", | ||
"--csv", | ||
"artifacts1of2.csv", | ||
"--csv", | ||
"artifacts2of2.csv", | ||
] | ||
result = invoke_command(import_artifacts.import_artifacts, [], args) | ||
test_context["settings"].SERVER = "http://127.0.0.1" | ||
|
||
result = invoke_command( | ||
import_artifacts.import_artifacts, [], args, test_context | ||
) | ||
assert result.exit_code == 0, result.output | ||
assert "Finished." in result.output | ||
assert import_artifacts.bootstrap_status.calls == [ | ||
|
@@ -343,7 +345,7 @@ def test_import_artifacts_no_api_server_config_no_param(self): | |
assert result.exit_code == 1, result.stderr | ||
assert "Requires '--api-server' " in result.stderr | ||
|
||
def test_import_artifacts_skip_publish_artifacts(self): | ||
def test_import_artifacts_skip_publish_artifacts(self, test_context): | ||
# Required to properly mock functions imported inside import_artifacts | ||
import sqlalchemy | ||
|
||
|
@@ -379,8 +381,6 @@ def test_import_artifacts_skip_publish_artifacts(self): | |
) | ||
|
||
args = [ | ||
"--api-server", | ||
"http://127.0.0.1", | ||
"--db-uri", | ||
"postgresql://postgres:[email protected]:5433", | ||
"--csv", | ||
|
@@ -389,7 +389,11 @@ def test_import_artifacts_skip_publish_artifacts(self): | |
"artifacts2of2.csv", | ||
"--skip-publish-artifacts", | ||
] | ||
result = invoke_command(import_artifacts.import_artifacts, [], args) | ||
test_context["settings"].SERVER = "http://127.0.0.1" | ||
|
||
result = invoke_command( | ||
import_artifacts.import_artifacts, [], args, test_context | ||
) | ||
assert result.exit_code == 0, result.output | ||
assert "Finished." in result.output | ||
assert "No artifacts published" in result.output | ||
|
@@ -408,7 +412,7 @@ def test_import_artifacts_skip_publish_artifacts(self): | |
assert import_artifacts.publish_artifacts.calls == [] | ||
assert import_artifacts.task_status.calls == [] | ||
|
||
def test_import_artifacts_sqlalchemy_import_fails(self): | ||
def test_import_artifacts_sqlalchemy_import_fails(self, test_context): | ||
import builtins | ||
|
||
real_import = builtins.__import__ | ||
|
@@ -423,60 +427,69 @@ def fake_import(name, *args, **kwargs): | |
|
||
builtins.__import__ = fake_import | ||
|
||
args = ["--api-server", "", "--db-uri", "", "--csv", ""] | ||
args = ["--db-uri", "", "--csv", ""] | ||
test_context["settings"].SERVER = "" | ||
with pytest.raises(ModuleNotFoundError) as exc: | ||
invoke_command( | ||
import_artifacts.import_artifacts, | ||
[], | ||
args, | ||
test_context, | ||
std_err_empty=False, | ||
) | ||
|
||
# Return the original import to not cause other exceptions. | ||
builtins.__import__ = real_import | ||
assert "pip install repository-service-tuf[sqlalchemy" in str(exc) | ||
|
||
def test_import_artifacts_bootstrap_check_failed(self): | ||
def test_import_artifacts_bootstrap_check_failed(self, test_context): | ||
|
||
import_artifacts.bootstrap_status = pretend.raiser( | ||
import_artifacts.click.ClickException("Server ERROR") | ||
) | ||
|
||
args = [ | ||
"--api-server", | ||
"http://127.0.0.1", | ||
"--db-uri", | ||
"postgresql://postgres:[email protected]:5433", | ||
"--csv", | ||
"artifacts1of2.csv", | ||
"--csv", | ||
"artifacts2of2.csv", | ||
] | ||
test_context["settings"].SERVER = "http://127.0.0.1" | ||
|
||
result = invoke_command( | ||
import_artifacts.import_artifacts, [], args, std_err_empty=False | ||
import_artifacts.import_artifacts, | ||
[], | ||
args, | ||
test_context, | ||
std_err_empty=False, | ||
) | ||
assert result.exit_code == 1 | ||
assert "Server ERROR" in result.stderr, result.stderr | ||
|
||
def test_import_artifacts_without_bootstrap(self): | ||
def test_import_artifacts_without_bootstrap(self, test_context): | ||
|
||
import_artifacts.bootstrap_status = pretend.call_recorder( | ||
lambda *a: {"data": {"bootstrap": False}, "message": "some msg"} | ||
) | ||
|
||
args = [ | ||
"--api-server", | ||
"http://127.0.0.1", | ||
"--db-uri", | ||
"postgresql://postgres:[email protected]:5433", | ||
"--csv", | ||
"artifacts1of2.csv", | ||
"--csv", | ||
"artifacts2of2.csv", | ||
] | ||
test_context["settings"].SERVER = "http://127.0.0.1" | ||
|
||
result = invoke_command( | ||
import_artifacts.import_artifacts, [], args, std_err_empty=False | ||
import_artifacts.import_artifacts, | ||
[], | ||
args, | ||
test_context, | ||
std_err_empty=False, | ||
) | ||
assert result.exit_code == 1, result.stderr | ||
assert ( | ||
|
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