Skip to content

test: add unit tests for _safe_path and get_subsidy_overview#5

Open
sugukurukabe wants to merge 1 commit intodigital-go-jp:mainfrom
sugukurukabe:test/unit-tests
Open

test: add unit tests for _safe_path and get_subsidy_overview#5
sugukurukabe wants to merge 1 commit intodigital-go-jp:mainfrom
sugukurukabe:test/unit-tests

Conversation

@sugukurukabe
Copy link
Copy Markdown

概要 / Summary

ライブAPIに依存しないユニットテスト(14件)を追加します。

Adds 14 unit tests that do not depend on the live J-Grants API.


テスト内容 / What is tested

_safe_path (4件)

テスト 検証内容
test_valid_path_within_base 正常パスを正しく返す
test_path_traversal_raises ../ によるパストラバーサルを検出
test_nested_traversal_raises ネストした ../../ も検出
test_same_base_returns_base . は基底ディレクトリ自身を返す

get_subsidy_overview (10件)

テスト 検証内容
test_accepting_count_currently_open 受付開始済みの補助金が accepting にカウントされる ※1
test_accepting_count_not_yet_started 受付開始前は accepting にカウントしない
test_this_month_bucket 締切30日以内 → this_month
test_next_month_bucket 締切31〜60日 → next_month
test_urgent_deadline_flagged 締切14日以内 → urgent_deadlines に含まれる
test_expired_subsidy_excluded 期限切れ補助金は集計から除外
test_amount_range_under_1m 上限額 < 100万円 → under_1m
test_amount_range_unspecified 上限額未設定 → unspecified
test_error_propagated 内部APIエラーが呼び出し元に伝播
test_csv_output_contains_header output_format='csv' で正常終了

※1 test_accepting_count_currently_open は現在の main では 意図的に FAIL します。
by_deadline_period.accepting が常に 0 になるバグ(PR #2 で修正済み)を文書化するテストです。
PR #2 がマージされると全14件が PASS します。


実行方法 / How to run

pip install -r requirements.txt
pytest tests/test_unit.py -v

Expected output on current main: 13 passed, 1 failed (test_accepting_count_currently_open)
Expected output after PR #2 merges: 14 passed

Made with Cursor

14 tests covering:
- _safe_path: path traversal prevention (4 cases)
- get_subsidy_overview: accepting count, deadline buckets, urgency
  flag, expired exclusion, amount ranges, error propagation, CSV mode

test_accepting_count_currently_open intentionally FAILS on the current
main branch, documenting the bug fixed in PR digital-go-jp#2. All other 13 tests
pass. The test suite will be fully green once PR digital-go-jp#2 is merged.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant