Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/unit_tests/test_tethys_cli/test_db_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ def test_db_command_init(self):
**kwargs,
)

@mock.patch("tethys_cli.db_commands.sys.platform", "win32")
def test_db_command_init_windows(self):
mock_args = mock.MagicMock()
mock_args.command = "init"
db_command(mock_args)
kwargs = self._get_kwargs(remove=["db_dir"])
self.mock_run_process.assert_called_with(
[
"initdb",
"-U",
"postgres",
"-D",
"foo/data",
"--encoding",
"UTF8",
"--locale",
"C",
],
'Initializing Postgresql database server in "foo/data"...',
"Could not initialize the Postgresql database.",
**kwargs,
)

@mock.patch("tethys_cli.db_commands.write_error")
@mock.patch("tethys_cli.db_commands.create_db_user")
def test_db_command_create_error_code_without_exit(
Expand Down Expand Up @@ -296,6 +319,8 @@ def test_db_command_create_db_user(self):
"postgres",
"-E",
"utf-8",
"--template",
"template0",
"-p",
self.options["port"],
"-O",
Expand Down
4 changes: 4 additions & 0 deletions tethys_cli/db_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def init_db_server(db_dir=None, **kwargs):
msg = f'Initializing Postgresql database server in "{db_dir}/data"...'
err_msg = "Could not initialize the Postgresql database."
args = ["initdb", "-U", "postgres", "-D", f"{db_dir}/data"]
if sys.platform == "win32":
args.extend(["--encoding", "UTF8", "--locale", "C"])
return _run_process(args, msg, err_msg, **kwargs)


Expand Down Expand Up @@ -316,6 +318,8 @@ def create_db_user(
"postgres",
"-E",
"utf-8",
"--template",
"template0",
"-p",
f"{port}",
"-O",
Expand Down
Loading