From 41d8ffc404d20ef7d55890780d0df850ccae1b84 Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Tue, 19 May 2026 15:28:44 +0200 Subject: [PATCH] refactor: rename startWecker/stopWecker mutations to startRinging/stopRinging 'Wecker' is a Swiss-German term with no meaning in English. Renaming to startRinging/stopRinging for better clarity. --- README.md | 4 ++-- api/schema.py | 4 ++-- tests/test_api.py | 43 +++++++++++++++++++++---------------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8627aef..ea5e881 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ mutation { **Start the alarm immediately:** ```graphql mutation { - startWecker + startRinging } ``` Returns `true` if the alarm started, `false` if it was already ringing (ignored). @@ -110,7 +110,7 @@ Returns `true` if the alarm started, `false` if it was already ringing (ignored) **Stop the alarm immediately:** ```graphql mutation { - stopWecker + stopRinging } ``` Returns `true` if the alarm was stopped, `false` if it wasn't ringing. diff --git a/api/schema.py b/api/schema.py index a7abd68..c4238a8 100644 --- a/api/schema.py +++ b/api/schema.py @@ -98,7 +98,7 @@ class Mutation: return False @strawberry.field - def start_wecker(self) -> bool: + def start_ringing(self) -> bool: """Start the wecker alarm if it is not already ringing. Returns True if started, False if already ringing.""" if is_wecker_ringing(): @@ -110,7 +110,7 @@ class Mutation: return True @strawberry.field - def stop_wecker(self) -> bool: + def stop_ringing(self) -> bool: """Stop the wecker alarm if it is currently ringing. Returns True if stopped, False if not ringing.""" if not is_wecker_ringing(): diff --git a/tests/test_api.py b/tests/test_api.py index 4940d81..e7b7b5f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -203,8 +203,8 @@ def test_graphql_workflow(): assert res.json()["data"]["getAlarms"] == [] -def test_start_wecker_starts_process_when_not_ringing(): - """startWecker returns True and spawns wecker.py when not already ringing.""" +def test_start_ringing_starts_process_when_not_ringing(): + """startRinging returns True and spawns wecker.py when not already ringing.""" from api.schema import Mutation mutation = Mutation() @@ -213,30 +213,29 @@ def test_start_wecker_starts_process_when_not_ringing(): patch("subprocess.Popen") as mock_popen: mock_proc = mock_popen.return_value mock_proc.pid = 9999 - result = mutation.start_wecker() + result = mutation.start_ringing() assert result is True mock_popen.assert_called_once() - # Verify the command contains wecker.py args, kwargs = mock_popen.call_args assert "wecker.py" in args[0] assert kwargs.get("shell") is True -def test_start_wecker_ignores_when_already_ringing(): - """startWecker returns False when wecker is already ringing.""" +def test_start_ringing_ignores_when_already_ringing(): + """startRinging returns False when already ringing.""" from api.schema import Mutation mutation = Mutation() with patch("api.schema.is_wecker_ringing", return_value=True), \ - patch("api.schema.subprocess.Popen") as mock_popen: - result = mutation.start_wecker() + patch("subprocess.Popen") as mock_popen: + result = mutation.start_ringing() assert result is False mock_popen.assert_not_called() -def test_stop_wecker_kills_process_when_ringing(): - """stopWecker returns True and kills the process wecker is ringing.""" +def test_stop_ringing_kills_process_when_ringing(): + """stopRinging returns True and kills the process when ringing.""" from api.schema import Mutation mutation = Mutation() @@ -248,30 +247,30 @@ def test_stop_wecker_kills_process_when_ringing(): mock_f = mock_open.return_value.__enter__.return_value mock_f.read.return_value = "1234" mock_kill.return_value = None - result = mutation.stop_wecker() + result = mutation.stop_ringing() assert result is True mock_kill.assert_called_with(1234, 15) -def test_stop_wecker_does_nothing_when_not_ringing(): - """stopWecker returns False when wecker is not ringing.""" +def test_stop_ringing_does_nothing_when_not_ringing(): + """stopRinging returns False when not ringing.""" from api.schema import Mutation mutation = Mutation() with patch("api.schema.is_wecker_ringing", return_value=False), \ patch("api.schema.os.kill") as mock_kill: - result = mutation.stop_wecker() + result = mutation.stop_ringing() assert result is False mock_kill.assert_not_called() -def test_start_wecker_graphql_endpoint(): - """GraphQL mutation startWecker works via the API.""" +def test_start_ringing_graphql_endpoint(): + """GraphQL mutation startRinging works via the API.""" headers = {"X-API-Key": "test-secret"} mutation_str = """ mutation { - startWecker + startRinging } """ @@ -281,15 +280,15 @@ def test_start_wecker_graphql_endpoint(): mock_proc.pid = 9999 res = client.post("/graphql", json={"query": mutation_str}, headers=headers) assert res.status_code == 200 - assert res.json()["data"]["startWecker"] is True + assert res.json()["data"]["startRinging"] is True -def test_stop_wecker_graphql_endpoint(): - """GraphQL mutation stopWecker works via the API.""" +def test_stop_ringing_graphql_endpoint(): + """GraphQL mutation stopRinging works via the API.""" headers = {"X-API-Key": "test-secret"} mutation_str = """ mutation { - stopWecker + stopRinging } """ @@ -301,7 +300,7 @@ def test_stop_wecker_graphql_endpoint(): mock_kill.return_value = None res = client.post("/graphql", json={"query": mutation_str}, headers=headers) assert res.status_code == 200 - assert res.json()["data"]["stopWecker"] is True + assert res.json()["data"]["stopRinging"] is True def test_pid_file_same_shared_constant_in_api():