Skip to content

Commit 66c0ce0

Browse files
test: add regression test for auth forwarding in post_slack
Verify that post_slack passes the auth dependency to get_events as a keyword argument. Without this, get_events receives a raw Depends() descriptor and check_auth raises 401. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6431ed6 commit 66c0ce0

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/test_unit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,35 @@ def test_post_slack(test_client, auth_headers):
361361
assert response.status_code == 200
362362

363363

364+
@pytest.mark.unit
365+
def test_post_slack_passes_auth_to_get_events(test_client, auth_headers):
366+
"""Regression: post_slack must forward auth to get_events.
367+
368+
Without this, get_events receives a raw Depends() descriptor
369+
and check_auth raises 401.
370+
"""
371+
mock_message = ["Test message"]
372+
373+
with (
374+
patch('main.get_events') as mock_get_events,
375+
patch('main.fmt_json', return_value=mock_message),
376+
patch('main.send_message'),
377+
patch('main.chan_dict', {"test-channel": "C12345"}),
378+
):
379+
response = test_client.post(
380+
"/api/slack",
381+
headers=auth_headers,
382+
params={"location": "Oklahoma City", "exclusions": "Tulsa", "channel_name": "test-channel"},
383+
)
384+
assert response.status_code == 200
385+
# Verify auth was forwarded (not left as default Depends descriptor)
386+
mock_get_events.assert_called_once()
387+
call_kwargs = mock_get_events.call_args
388+
auth_arg = call_kwargs.kwargs.get("auth")
389+
assert auth_arg is not None, "auth must be passed to get_events"
390+
assert isinstance(auth_arg, UserInDB), f"auth should be a User, got {type(auth_arg)}"
391+
392+
364393
@pytest.mark.unit
365394
def test_snooze_slack_post(test_client, auth_headers):
366395
# snooze_slack_post endpoint references undefined `current_user` variable (app bug).

0 commit comments

Comments
 (0)