fix: use append (>>) instead of overwrite (>) for cron logs and add missing dependencies
- Fixed api/schema.py to generate cron jobs using '>> wecker.log' so logs aren't truncated. - Added test_bugfix_default_command_uses_append_for_logs in tests/test_api.py to prevent regression. - Added RPi.GPIO and pygame to pyproject.toml via 'uv add' to fix ModuleNotFoundError in cron jobs. - Updated README.md to reflect that system python packages are no longer needed.
This commit is contained in:
@@ -40,6 +40,59 @@ def test_auth_invalid():
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
def test_bugfix_default_command_uses_append_for_logs():
|
||||
"""
|
||||
Test for bugfix: Ensure the default command appends (>>) to wecker.log
|
||||
instead of overwriting (>) it.
|
||||
"""
|
||||
from api.schema import Mutation
|
||||
|
||||
mutation = Mutation()
|
||||
# Call the resolver directly without command to trigger default command generation
|
||||
alarm = mutation.set_alarm(cron_expression="0 9 * * *")
|
||||
|
||||
# Verify the generated command string
|
||||
command = alarm.command
|
||||
assert ">> wecker.log 2>&1" in command, (
|
||||
f"Command must use append '>>' syntax. Got: {command}"
|
||||
)
|
||||
assert "> wecker.log 2>&1" not in command.replace(">> wecker.log", "REPLACED"), (
|
||||
"Command must not use overwrite '>'"
|
||||
)
|
||||
|
||||
# Cleanup
|
||||
mutation.delete_alarm(id=alarm.id)
|
||||
|
||||
|
||||
def test_set_alarm_default_command_append():
|
||||
headers = {"X-API-Key": "test-secret"}
|
||||
mutation = """
|
||||
mutation {
|
||||
setAlarm(cronExpression: "0 9 * * *") {
|
||||
id
|
||||
command
|
||||
}
|
||||
}
|
||||
"""
|
||||
res = client.post("/graphql", json={"query": mutation}, headers=headers)
|
||||
assert res.status_code == 200
|
||||
data = res.json()["data"]["setAlarm"]
|
||||
|
||||
# Assert the command contains the correct append syntax (>>) and not just overwrite (>)
|
||||
command = data["command"]
|
||||
assert ">> wecker.log 2>&1" in command
|
||||
assert "> wecker.log 2>&1" not in command.replace(">> wecker.log", "REPLACED")
|
||||
|
||||
# Cleanup so we don't break subsequent tests
|
||||
alarm_id = data["id"]
|
||||
mutation_delete = f"""
|
||||
mutation {{
|
||||
deleteAlarm(id: "{alarm_id}")
|
||||
}}
|
||||
"""
|
||||
client.post("/graphql", json={"query": mutation_delete}, headers=headers)
|
||||
|
||||
|
||||
def test_graphql_workflow():
|
||||
headers = {"X-API-Key": "test-secret"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user