Added a lot of unit tests
This commit is contained in:
parent
0938fb98b7
commit
16d4a0724c
32 changed files with 4268 additions and 497 deletions
|
@ -2,6 +2,7 @@ from enum import Enum
|
|||
from typing import Optional
|
||||
|
||||
import pendulum
|
||||
from pendulum import Date, Time
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
from pydantic_extra_types.pendulum_dt import DateTime
|
||||
|
||||
|
@ -165,6 +166,46 @@ class Booking(BaseModel):
|
|||
def to_lower_case(cls, d: str) -> str:
|
||||
return d.lower()
|
||||
|
||||
def matches(self, booking_filter: BookingFilter) -> bool:
|
||||
"""
|
||||
Check if the booking matches the booking filter
|
||||
|
||||
:param booking_filter: the conditions the booking should meet
|
||||
:return: true if the booking matches the conditions, false otherwise
|
||||
"""
|
||||
return (
|
||||
self.is_same_sport(booking_filter.sport_name)
|
||||
and self.is_same_date(booking_filter.date.date())
|
||||
and self.is_same_time(booking_filter.date.time())
|
||||
)
|
||||
|
||||
def is_same_sport(self, sport: str) -> bool:
|
||||
"""
|
||||
Check if the booking and the booking filter are about the same sport
|
||||
|
||||
:param sport: the sport to test
|
||||
:return: true if the sport matches booking sport, false otherwise
|
||||
"""
|
||||
return self.sport == sport
|
||||
|
||||
def is_same_date(self, date: Date) -> bool:
|
||||
"""
|
||||
Check if the booking filter has the same date as the booking
|
||||
|
||||
:param date: the date to test
|
||||
:return: true if the date matches the booking date, false otherwise
|
||||
"""
|
||||
return self.booking_date.date() == date
|
||||
|
||||
def is_same_time(self, time: Time) -> bool:
|
||||
"""
|
||||
Check if the booking filter has the same time as the booking
|
||||
|
||||
:param time: the time to test
|
||||
:return: true if the time matches the booking time, false otherwise
|
||||
"""
|
||||
return self.start_time.time() == time
|
||||
|
||||
|
||||
class Action(Enum):
|
||||
BOOK = "book"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue