Skip to content

Commit

Permalink
優先券は公演の重なりを無視
Browse files Browse the repository at this point in the history
  • Loading branch information
aozoraUS committed Sep 11, 2024
1 parent e69a58a commit 5438b01
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
13 changes: 3 additions & 10 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,23 +803,16 @@ def create_family_ticket(
HTTP_403_FORBIDDEN, "この公演は整理券を取得できる人が制限されています。"
)

# 優先券配布開始時間よりも現在時刻が後
if datetime.fromisoformat(settings.family_ticket_sell_starts) < datetime.now(
timezone(timedelta(hours=+9))
):
qualified: bool = crud.check_qualified_for_ticket(db, event, user)
if (
crud.count_tickets_for_event(db, event) + 1 <= event.ticket_stock
and qualified
): ##まだチケットが余っていて、同時間帯の公演の整理券取得ではない
# チケットがまだ余っている
if crud.count_tickets_for_event(db, event) + 1 <= event.ticket_stock:
if crud.count_taken_family_ticket(db, user) < 2:
return crud.create_ticket(db, event, user, 1, True)
else:
raise HTTPException(404, "既に保護者用優先券を2枚以上取得しています。")
elif not qualified:
raise HTTPException(
404,
"既にこの公演・この公演と重複する時間帯の公演の整理券を取得している場合、新たに取得はできません。",
)
else:
raise HTTPException(404, "この公演の整理券は売り切れています")
else:
Expand Down
42 changes: 42 additions & 0 deletions app/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,48 @@ def test_create_family_ticket(db):
response_5.json() == 2


def test_create_family_ticket_same_event(db):
# 環境変数書き換え
# テスト実行後に変数は元の値に戻してくれるみたい
settings.family_ticket_sell_starts = (
datetime.now(timezone(timedelta(hours=+9))) + timedelta(days=-1)
).isoformat()

# 団体作成
group1 = models.Group(**factories.group1.dict())
db.add(group1)
db.commit()
db.refresh(group1)

# 公演作成
event_create = schemas.EventCreate(
eventname="テスト公演",
target="everyone",
ticket_stock=20,
starts_at=datetime.now(timezone(timedelta(hours=+10)))
+ timedelta(days=2), # 優先券以外では取得不可の時間設定
ends_at=datetime.now(timezone(timedelta(hours=+9))) + timedelta(days=3),
sell_starts=datetime.now(timezone(timedelta(hours=+9)))
+ timedelta(days=+1, hours=+0),
sell_ends=datetime.now(timezone(timedelta(hours=+9)))
+ timedelta(days=+1, hours=+1),
)
event = crud.create_event(db, group1.id, event_create)

response_1 = client.post(
f"/groups/{group1.id}/events/{event.id}/tickets/family",
headers=factories.authheader(factories.valid_parent_user_28r),
)

response_2 = client.post(
f"/groups/{group1.id}/events/{event.id}/tickets/family",
headers=factories.authheader(factories.valid_parent_user_28r),
)

assert response_1.status_code == 200
assert response_2.status_code == 200


def test_create_family_ticket_wrong_time(db):
# 環境変数書き換え
# テスト実行後に変数は元の値に戻してくれるみたい
Expand Down

0 comments on commit 5438b01

Please sign in to comment.