diff --git a/tests/unit_tests/test_tethys_cli/test_db_commands.py b/tests/unit_tests/test_tethys_cli/test_db_commands.py index 61ca543e5..d95dfaf3c 100644 --- a/tests/unit_tests/test_tethys_cli/test_db_commands.py +++ b/tests/unit_tests/test_tethys_cli/test_db_commands.py @@ -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( @@ -296,6 +319,8 @@ def test_db_command_create_db_user(self): "postgres", "-E", "utf-8", + "--template", + "template0", "-p", self.options["port"], "-O", diff --git a/tethys_cli/db_commands.py b/tethys_cli/db_commands.py index ae1fdd0cf..2600935f3 100644 --- a/tethys_cli/db_commands.py +++ b/tethys_cli/db_commands.py @@ -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) @@ -316,6 +318,8 @@ def create_db_user( "postgres", "-E", "utf-8", + "--template", + "template0", "-p", f"{port}", "-O",