Add pytest suite and wire it into CI (#85) (#86)
* Add pytest suite and wire it into CI
Stands up the first automated tests for the repo (151 tests) and turns on
the CI test step.
- Lift slack-bot handlers out of create_app() closures to module level so
they're unit-testable; create_app is now a thin Bolt-wiring layer. No
behavior change (handler entrypoints and create_app signature unchanged).
- tests/ mirrors src/: shared layer (schedule, blocks, 3CX client,
ring_scheduler, secrets) + all four Lambdas (pay math, drop/swap/pick/
admin/register/rate, pickup button, roster sync, queue scheduler).
- All boundaries mocked: DynamoDB/SES/Secrets via moto, 3CX HTTP via
responses, Slack via fakes, time via freezegun. No real network/AWS.
- pyproject.toml pytest config (pythonpath=src/shared, importlib mode);
per-package conftest loads each app.py under a unique name to avoid the
four-app.py collision. tests/requirements.txt for test-only deps.
- ci.yaml: run-tests: true (reusable workflow auto-installs deps) and lint
the tests dir too.
- README Testing section.
Closes #85
* Add least-privilege permissions block to CI workflow
Resolves the CodeQL actions/missing-workflow-permissions alert: the CI
workflow now restricts GITHUB_TOKEN to contents: read (it only checks out,
lints, and runs tests).
* Stop logging extension numbers in 3CX queue updates
Resolves 3 high CodeQL py/clear-text-logging-sensitive-data alerts: the
queue/ring-group forwarding logs no longer include the routed extension
values (closed/holiday/extension). Non-sensitive context (resource id,
queue number) is retained.
2026-06-01 19:07:08 -04:00
|
|
|
|
"""Tests for slack-bot parse_date — flexible date parsing."""
|
|
|
|
|
|
|
|
|
|
|
|
from freezegun import freeze_time
|
|
|
|
|
|
|
|
|
|
|
|
# All frozen to Monday 2026-06-01 (ET 08:00).
|
|
|
|
|
|
FROZEN = "2026-06-01 12:00:00"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_today(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("today").strftime("%Y-%m-%d") == "2026-06-01"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_tomorrow(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("tomorrow").strftime("%Y-%m-%d") == "2026-06-02"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_future_day_name(slackbot_app):
|
|
|
|
|
|
# Friday of the same week.
|
|
|
|
|
|
assert slackbot_app.parse_date("friday").strftime("%Y-%m-%d") == "2026-06-05"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_same_day_name_jumps_a_week(slackbot_app):
|
|
|
|
|
|
# Monday on a Monday → next Monday, never today.
|
|
|
|
|
|
assert slackbot_app.parse_date("monday").strftime("%Y-%m-%d") == "2026-06-08"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_iso_date(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("2026-07-04").strftime("%Y-%m-%d") == "2026-07-04"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_month_slash_day(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("7/4").strftime("%Y-%m-%d") == "2026-07-04"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_month_dash_day(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("7-4").strftime("%Y-%m-%d") == "2026-07-04"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_past_month_day_wraps_to_next_year(slackbot_app):
|
|
|
|
|
|
# Jan 1 is well in the past → assume next year.
|
|
|
|
|
|
assert slackbot_app.parse_date("1/1").year == 2027
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_case_insensitive(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date(" FRIDAY ").strftime("%Y-%m-%d") == "2026-06-05"
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-26 15:07:02 -04:00
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_two_digit_year_slash(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("7/3/26").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_two_digit_year_padded(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("07/03/26").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_two_digit_year_dash(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("7-3-26").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_four_digit_year_dash(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("7-3-2026").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_two_digit_year_century_boundary(slackbot_app):
|
|
|
|
|
|
# Python's %y maps 00–68 → 2000s and 69–99 → 1900s. Pin it so nobody
|
|
|
|
|
|
# "fixes" the ambiguity by accident later.
|
|
|
|
|
|
assert slackbot_app.parse_date("12/31/99").year == 1999
|
|
|
|
|
|
assert slackbot_app.parse_date("1/1/68").year == 2068
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_two_digit_year_past_not_rolled(slackbot_app):
|
|
|
|
|
|
# Explicit two-digit year in the past stays put — no roll-forward.
|
|
|
|
|
|
assert slackbot_app.parse_date("1/1/26").strftime("%Y-%m-%d") == "2026-01-01"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_month_name_short(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("jul 3").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_month_name_full(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("july 3").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_month_name_with_year(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("july 3 2026").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_month_name_ordinal(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("july 3rd").strftime("%Y-%m-%d") == "2026-07-03"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_month_name_past_wraps_to_next_year(slackbot_app):
|
|
|
|
|
|
# Year-less month name in the past rolls forward, like m/d.
|
|
|
|
|
|
assert slackbot_app.parse_date("jan 1").year == 2027
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_eastern_tz_stamped(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("7/3/26").tzinfo is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
Add pytest suite and wire it into CI (#85) (#86)
* Add pytest suite and wire it into CI
Stands up the first automated tests for the repo (151 tests) and turns on
the CI test step.
- Lift slack-bot handlers out of create_app() closures to module level so
they're unit-testable; create_app is now a thin Bolt-wiring layer. No
behavior change (handler entrypoints and create_app signature unchanged).
- tests/ mirrors src/: shared layer (schedule, blocks, 3CX client,
ring_scheduler, secrets) + all four Lambdas (pay math, drop/swap/pick/
admin/register/rate, pickup button, roster sync, queue scheduler).
- All boundaries mocked: DynamoDB/SES/Secrets via moto, 3CX HTTP via
responses, Slack via fakes, time via freezegun. No real network/AWS.
- pyproject.toml pytest config (pythonpath=src/shared, importlib mode);
per-package conftest loads each app.py under a unique name to avoid the
four-app.py collision. tests/requirements.txt for test-only deps.
- ci.yaml: run-tests: true (reusable workflow auto-installs deps) and lint
the tests dir too.
- README Testing section.
Closes #85
* Add least-privilege permissions block to CI workflow
Resolves the CodeQL actions/missing-workflow-permissions alert: the CI
workflow now restricts GITHUB_TOKEN to contents: read (it only checks out,
lints, and runs tests).
* Stop logging extension numbers in 3CX queue updates
Resolves 3 high CodeQL py/clear-text-logging-sensitive-data alerts: the
queue/ring-group forwarding logs no longer include the routed extension
values (closed/holiday/extension). Non-sensitive context (resource id,
queue number) is retained.
2026-06-01 19:07:08 -04:00
|
|
|
|
@freeze_time(FROZEN)
|
|
|
|
|
|
def test_invalid_returns_none(slackbot_app):
|
|
|
|
|
|
assert slackbot_app.parse_date("notaday") is None
|