@@ -37,7 +37,7 @@ def mock_api(monkeypatch: pytest.MonkeyPatch) -> Mock:
3737
3838@pytest .fixture
3939def job_data () -> dict [str , Any ]:
40- """A full schedule including model-specific cleaning settings."""
40+ """A schedule including model-specific cleaning settings."""
4141 return {
4242 "id" : 3878757 ,
4343 "cron" : "05 10 * * ?" ,
@@ -47,10 +47,8 @@ def job_data() -> dict[str, Any]:
4747 }
4848
4949
50- @pytest .mark .parametrize ("enabled" , [False , True ])
51- def test_update_job (mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ], enabled : bool ) -> None :
52- """The CLI passes a complete typed schedule using only the cached account."""
53- job_data ["enabled" ] = enabled
50+ def test_update_job (mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ]) -> None :
51+ """The CLI parses JSON into a schedule and calls the API using cached credentials."""
5452 job_file = tmp_path / "job.json"
5553 job_file .write_text (json .dumps (job_data ), encoding = "utf-8" )
5654
@@ -59,123 +57,31 @@ def test_update_job(mock_api: Mock, tmp_path: Path, job_data: dict[str, Any], en
5957 assert result .exit_code == 0 , result .output
6058 assert result .output == "Updated job 3878757 for device 123456\n "
6159 mock_api .assert_called_once_with (USER_EMAIL )
62- client = mock_api .return_value
63- client .update_job .assert_awaited_once_with (UserData .from_dict (USER_DATA ), "123456" , HomeDataSchedule (** job_data ))
64- client .get_home_data_v3 .assert_not_called ()
65-
66-
67- def test_update_job_api_error (mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ]) -> None :
68- """A cloud rejection produces an unsuccessful command exit."""
69- mock_api .return_value .update_job .side_effect = RoborockException ("Job not found" )
70- job_file = tmp_path / "job.json"
71- job_file .write_text (json .dumps (job_data ), encoding = "utf-8" )
72-
73- result = CliRunner ().invoke (cli , ["update-job" , "--device_id" , "123456" , "--job-file" , str (job_file )])
74-
75- assert result .exit_code == 1
76- assert result .output == "Error: Job not found\n "
77- mock_api .return_value .update_job .assert_awaited_once ()
60+ mock_api .return_value .update_job .assert_awaited_once_with (
61+ UserData .from_dict (USER_DATA ), "123456" , HomeDataSchedule (** job_data )
62+ )
7863
7964
80- def test_update_job_requires_login (mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ]) -> None :
81- """Missing cached credentials fail without creating a cloud client."""
82- (tmp_path / ".roborock" ).unlink ()
65+ def test_update_job_invalid_json (mock_api : Mock , tmp_path : Path ) -> None :
66+ """A JSON parsing failure is reported without calling the cloud API."""
8367 job_file = tmp_path / "job.json"
84- job_file .write_text (json . dumps ( job_data ) , encoding = "utf-8" )
68+ job_file .write_text ("[" , encoding = "utf-8" )
8569
8670 result = CliRunner ().invoke (cli , ["update-job" , "--device_id" , "123456" , "--job-file" , str (job_file )])
8771
8872 assert result .exit_code == 1
89- assert result .output == "Error: You must login first\n "
90- mock_api .assert_not_called ()
91-
92-
93- @pytest .mark .parametrize ("field" , ["id" , "cron" , "repeated" , "enabled" , "param" ])
94- def test_update_job_missing_fields (mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ], field : str ) -> None :
95- """Partial schedule files cannot reach the update endpoint."""
96- del job_data [field ]
97- job_file = tmp_path / "job.json"
98- job_file .write_text (json .dumps (job_data ), encoding = "utf-8" )
99-
100- result = CliRunner ().invoke (cli , ["update-job" , "--device_id" , "123456" , "--job-file" , str (job_file )])
101-
102- assert result .exit_code == 2
103- assert f"Complete job required; missing fields: { field } " in result .output
104- mock_api .assert_not_called ()
105-
106-
107- @pytest .mark .parametrize (
108- ("field" , "value" ),
109- [
110- ("id" , True ),
111- ("id" , "3878757" ),
112- ("id" , 1.5 ),
113- ("cron" , None ),
114- ("cron" , " " ),
115- ("repeated" , 1 ),
116- ("enabled" , "false" ),
117- ("param" , None ),
118- ("param" , []),
119- ("param" , "{}" ),
120- ],
121- )
122- def test_update_job_invalid_fields (
123- mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ], field : str , value : Any
124- ) -> None :
125- """Malformed scalar types are rejected instead of silently coerced."""
126- job_data [field ] = value
127- job_file = tmp_path / "job.json"
128- job_file .write_text (json .dumps (job_data ), encoding = "utf-8" )
129-
130- result = CliRunner ().invoke (cli , ["update-job" , "--device_id" , "123456" , "--job-file" , str (job_file )])
131-
132- assert result .exit_code == 2
133- assert f"'{ field } ' must be" in result .output
73+ assert "Error: Expecting value" in result .output
13474 mock_api .assert_not_called ()
13575
13676
137- def test_update_job_unknown_fields (mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ]) -> None :
138- """Unknown top-level settings cannot be silently discarded during replacement ."""
139- job_data [ "additionalSetting" ] = { "value" : 1 }
77+ def test_update_job_api_error (mock_api : Mock , tmp_path : Path , job_data : dict [str , Any ]) -> None :
78+ """A cloud rejection is reported with an unsuccessful command exit ."""
79+ mock_api . return_value . update_job . side_effect = RoborockException ( "Job not found" )
14080 job_file = tmp_path / "job.json"
14181 job_file .write_text (json .dumps (job_data ), encoding = "utf-8" )
14282
14383 result = CliRunner ().invoke (cli , ["update-job" , "--device_id" , "123456" , "--job-file" , str (job_file )])
14484
145- assert result .exit_code == 2
146- assert "Unknown job fields: additionalSetting" in result .output
147- mock_api .assert_not_called ()
148-
149-
150- @pytest .mark .parametrize ("contents" , ["[" , "[]" , "null" , '"schedule"' ])
151- def test_update_job_invalid_json (mock_api : Mock , tmp_path : Path , contents : str ) -> None :
152- """Invalid JSON and non-object roots fail before creating a cloud client."""
153- job_file = tmp_path / "job.json"
154- job_file .write_text (contents , encoding = "utf-8" )
155-
156- result = CliRunner ().invoke (cli , ["update-job" , "--device_id" , "123456" , "--job-file" , str (job_file )])
157-
158- assert result .exit_code == 2
159- assert "Invalid value for '--job-file'" in result .output
160- mock_api .assert_not_called ()
161-
162-
163- def test_update_job_missing_file (mock_api : Mock , tmp_path : Path ) -> None :
164- """A nonexistent input file fails without cloud access."""
165- result = CliRunner ().invoke (
166- cli , ["update-job" , "--device_id" , "123456" , "--job-file" , str (tmp_path / "missing.json" )]
167- )
168-
169- assert result .exit_code == 2
170- assert "does not exist" in result .output
171- mock_api .assert_not_called ()
172-
173-
174- def test_update_job_help (mock_api : Mock ) -> None :
175- """Help explains that this operation replaces all schedule settings."""
176- result = CliRunner ().invoke (cli , ["update-job" , "--help" ])
177-
178- assert result .exit_code == 0
179- assert "Include all existing settings" in result .output
180- assert "id, cron, repeated, enabled, and param" in result .output
181- mock_api .assert_not_called ()
85+ assert result .exit_code == 1
86+ assert result .output == "Error: Job not found\n "
87+ mock_api .return_value .update_job .assert_awaited_once ()
0 commit comments