|
@@ -2,6 +2,9 @@ import pathlib
|
|
|
import subprocess
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
+import pytest
|
|
|
+import yaml
|
|
|
+
|
|
|
|
|
|
import tooncher._cli
|
|
|
|
|
@@ -88,3 +91,65 @@ def test_engine_path_env_config(launch_mock, tmpdir):
|
|
|
args, kwargs = launch_mock.call_args
|
|
|
assert not args
|
|
|
assert kwargs["engine_path"] == pathlib.Path("/opt/ttr/TTREnvine")
|
|
|
+
|
|
|
+
|
|
|
+@patch("tooncher.launch")
|
|
|
+def test_account(launch_mock, tmpdir):
|
|
|
+ config_file = tmpdir.join("config")
|
|
|
+ config_file.write(
|
|
|
+ yaml.safe_dump(
|
|
|
+ {
|
|
|
+ "engine_path": "/opt/conf/TTR",
|
|
|
+ "accounts": [
|
|
|
+ {"username": "someone", "password": "secret"},
|
|
|
+ {"username": "toon", "password": "town"},
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+ with patch("sys.argv", ["", "--config", config_file.strpath, "toon"]):
|
|
|
+ tooncher._cli.main()
|
|
|
+ launch_mock.assert_called_once_with(
|
|
|
+ engine_path=pathlib.Path("/opt/conf/TTR"),
|
|
|
+ username="toon",
|
|
|
+ password="town",
|
|
|
+ validate_ssl_certs=True,
|
|
|
+ cpu_limit_percent=None,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_account_duplicate_username(tmpdir):
|
|
|
+ config_file = tmpdir.join("config")
|
|
|
+ config_file.write(
|
|
|
+ yaml.safe_dump(
|
|
|
+ {
|
|
|
+ "engine_path": "/opt/conf/TTR",
|
|
|
+ "accounts": [
|
|
|
+ {"username": "someone", "password": "secret"},
|
|
|
+ {"username": "toon", "password": "town"},
|
|
|
+ {"username": "toon", "password": "town2"},
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+ with patch("sys.argv", ["", "--config", config_file.strpath, "toon"]):
|
|
|
+ with pytest.raises(ValueError, match=r"multiple .* username"):
|
|
|
+ tooncher._cli.main()
|
|
|
+
|
|
|
+
|
|
|
+def test_account_unknown_username(tmpdir):
|
|
|
+ config_file = tmpdir.join("config")
|
|
|
+ config_file.write(
|
|
|
+ yaml.safe_dump(
|
|
|
+ {
|
|
|
+ "engine_path": "/opt/conf/TTR",
|
|
|
+ "accounts": [
|
|
|
+ {"username": "someone", "password": "secret"},
|
|
|
+ {"username": "toon", "password": "town"},
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+ with patch("sys.argv", ["", "--config", config_file.strpath, "player"]):
|
|
|
+ with pytest.raises(ValueError, match=r"not found"):
|
|
|
+ tooncher._cli.main()
|