Replace all uses of runner.isolated_filesystem, refs #1406

pull/1418/head
Simon Willison 2021-07-31 11:49:08 -07:00
rodzic 96b1d0b7b4
commit ff253f5242
3 zmienionych plików z 284 dodań i 292 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
from click.testing import CliRunner
from datasette import cli
from unittest import mock
import os
import pathlib
import pytest
@ -32,7 +33,7 @@ def test_package(mock_call, mock_which, tmp_path_factory):
runner = CliRunner()
capture = CaptureDockerfile()
mock_call.side_effect = capture
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(cli.cli, ["package", "test.db", "--secret", "sekrit"])
@ -48,7 +49,7 @@ def test_package_with_port(mock_call, mock_which, tmp_path_factory):
capture = CaptureDockerfile()
mock_call.side_effect = capture
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(

Wyświetl plik

@ -2,6 +2,7 @@ from click.testing import CliRunner
from datasette import cli
from unittest import mock
import json
import os
import pytest
import textwrap
@ -11,7 +12,7 @@ import textwrap
def test_publish_cloudrun_requires_gcloud(mock_which, tmp_path_factory):
mock_which.return_value = False
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(cli.cli, ["publish", "cloudrun", "test.db"])
@ -42,26 +43,19 @@ def test_publish_cloudrun_prompts_for_service(
mock_output.return_value = "myproject"
mock_which.return_value = True
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
cli.cli, ["publish", "cloudrun", "test.db"], input="input-service"
)
assert (
"""
Please provide a service name for this deployment
Using an existing service name will over-write it
Your existing services:
existing - created 2019-01-01 - http://www.example.com/
Service name: input-service
""".strip()
== result.output.strip()
)
"Please provide a service name for this deployment\n\n"
"Using an existing service name will over-write it\n\n"
"Your existing services:\n\n"
" existing - created 2019-01-01 - http://www.example.com/\n\n"
"Service name: input-service"
) == result.output.strip()
assert 0 == result.exit_code
tag = "gcr.io/myproject/datasette"
mock_call.assert_has_calls(
@ -85,7 +79,7 @@ def test_publish_cloudrun(mock_call, mock_output, mock_which, tmp_path_factory):
mock_output.return_value = "myproject"
mock_which.return_value = True
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
@ -126,7 +120,7 @@ def test_publish_cloudrun_memory(
mock_output.return_value = "myproject"
mock_which.return_value = True
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
@ -162,7 +156,7 @@ def test_publish_cloudrun_plugin_secrets(
mock_output.return_value = "myproject"
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
with open("metadata.yml", "w") as fp:
@ -225,9 +219,9 @@ def test_publish_cloudrun_plugin_secrets(
"title": "Hello from metadata YAML",
"plugins": {
"datasette-auth-github": {
"foo": "bar",
"client_id": {"$env": "DATASETTE_AUTH_GITHUB_CLIENT_ID"},
}
"foo": "bar",
},
},
} == json.loads(metadata)
@ -243,7 +237,7 @@ def test_publish_cloudrun_apt_get_install(
mock_output.return_value = "myproject"
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
@ -312,7 +306,7 @@ def test_publish_cloudrun_extra_options(
mock_output.return_value = "myproject"
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(

Wyświetl plik

@ -1,6 +1,7 @@
from click.testing import CliRunner
from datasette import cli
from unittest import mock
import os
import pytest
@ -9,7 +10,7 @@ import pytest
def test_publish_heroku_requires_heroku(mock_which, tmp_path_factory):
mock_which.return_value = False
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(cli.cli, ["publish", "heroku", "test.db"])
@ -27,7 +28,7 @@ def test_publish_heroku_installs_plugin(
mock_which.return_value = True
mock_check_output.side_effect = lambda s: {"['heroku', 'plugins']": b""}[repr(s)]
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("t.db", "w") as fp:
fp.write("data")
result = runner.invoke(cli.cli, ["publish", "heroku", "t.db"], input="y\n")
@ -61,12 +62,10 @@ def test_publish_heroku(mock_call, mock_check_output, mock_which, tmp_path_facto
"['heroku', 'apps:create', 'datasette', '--json']": b'{"name": "f"}',
}[repr(s)]
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
cli.cli, ["publish", "heroku", "test.db", "--tar", "gtar"]
)
result = runner.invoke(cli.cli, ["publish", "heroku", "test.db", "--tar", "gtar"])
assert 0 == result.exit_code, result.output
mock_call.assert_has_calls(
[
@ -99,7 +98,7 @@ def test_publish_heroku_plugin_secrets(
"['heroku', 'apps:create', 'datasette', '--json']": b'{"name": "f"}',
}[repr(s)]
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
@ -126,8 +125,6 @@ def test_publish_heroku_plugin_secrets(
"DATASETTE_AUTH_GITHUB_CLIENT_ID=x-client-id",
]
),
mock.call(
["heroku", "builds:create", "-a", "f", "--include-vcs-ignore"]
),
mock.call(["heroku", "builds:create", "-a", "f", "--include-vcs-ignore"]),
]
)