Przejdź do treści

Test ReservationTest

Test jednostkowy dla klasy Reservation, weryfikujący poprawność działania logiki rezerwacyjnej.

Zakres testów obejmuje: - poprawne tworzenie rezerwacji na podstawie gościa, pokoju i zakresu dat, - obliczanie liczby nocy (get_duration) i kosztu pobytu (get_total_price), - poprawność danych zwracanych przez metodę get_summary, - walidację typów danych (gość, pokój, daty), - obsługę nieprawidłowego zakresu dat (check-out przed check-in), - poprawność reprezentacji tekstowej (__str__, __repr__).

Testy zapewniają pełne pokrycie funkcjonalności klasy, w tym przypadków błędnych danych wejściowych.


Dokumentacja techniczna

Bases: TestCase

Testy jednostkowe dla klasy Reservation.

setUp()

Tworzy obiekty Guest i Room do wykorzystania w testach.

Source code in tests/unit/test_reservation.py
def setUp(self):
    """Tworzy obiekty Guest i Room do wykorzystania w testach."""
    self.guest = Guest("Jan", "Kowalski", "jan@example.com", "987654321")
    self.room = Room("101", "double", 250.0, 2)
    self.check_in = date(2025, 7, 1)
    self.check_out = date(2025, 7, 5)

test_checkout_before_checkin()

Test zgłoszenia błędu, gdy data wymeldowania jest wcześniejsza niż zameldowania.

Source code in tests/unit/test_reservation.py
def test_checkout_before_checkin(self):
    """Test zgłoszenia błędu, gdy data wymeldowania jest wcześniejsza niż zameldowania."""
    with self.assertRaises(ValueError):
        Reservation(self.guest, self.room, date(2025, 7, 5), date(2025, 7, 1))

test_create_reservation()

Test poprawnego utworzenia rezerwacji.

Source code in tests/unit/test_reservation.py
def test_create_reservation(self):
    """Test poprawnego utworzenia rezerwacji."""
    reservation = Reservation(self.guest, self.room, self.check_in, self.check_out)
    self.assertIsInstance(reservation.reservation_id, str)
    self.assertEqual(reservation.guest, self.guest)
    self.assertEqual(reservation.room, self.room)
    self.assertEqual(reservation.check_in, self.check_in)
    self.assertEqual(reservation.check_out, self.check_out)

test_get_duration()

Test poprawnego obliczenia liczby nocy.

Source code in tests/unit/test_reservation.py
def test_get_duration(self):
    """Test poprawnego obliczenia liczby nocy."""
    reservation = Reservation(self.guest, self.room, self.check_in, self.check_out)
    self.assertEqual(reservation.get_duration(), 4)

test_get_summary()

Test poprawności danych zwracanych przez get_summary.

Source code in tests/unit/test_reservation.py
def test_get_summary(self):
    """Test poprawności danych zwracanych przez get_summary."""
    reservation = Reservation(self.guest, self.room, self.check_in, self.check_out)
    summary = reservation.get_summary()
    self.assertEqual(summary["guest_name"], "Jan Kowalski")
    self.assertEqual(summary["room_number"], "101")
    self.assertEqual(summary["check_in"], "2025-07-01")
    self.assertEqual(summary["check_out"], "2025-07-05")
    self.assertEqual(summary["nights"], 4)
    self.assertEqual(summary["total_price"], 1000.0)

test_get_total_price()

Test obliczenia całkowitego kosztu pobytu.

Source code in tests/unit/test_reservation.py
def test_get_total_price(self):
    """Test obliczenia całkowitego kosztu pobytu."""
    reservation = Reservation(self.guest, self.room, self.check_in, self.check_out)
    self.assertEqual(reservation.get_total_price(), 1000.0)

test_invalid_date_type()

Test zgłoszenia błędu, gdy daty są w złym formacie.

Source code in tests/unit/test_reservation.py
def test_invalid_date_type(self):
    """Test zgłoszenia błędu, gdy daty są w złym formacie."""
    with self.assertRaises(TypeError):
        Reservation(self.guest, self.room, "2025-07-01", "2025-07-05")

test_invalid_guest_type()

Test zgłoszenia błędu, gdy gość nie jest instancją klasy Guest.

Source code in tests/unit/test_reservation.py
def test_invalid_guest_type(self):
    """Test zgłoszenia błędu, gdy gość nie jest instancją klasy Guest."""
    with self.assertRaises(TypeError):
        Reservation("NieGość", self.room, self.check_in, self.check_out)

test_invalid_room_type()

Test zgłoszenia błędu, gdy pokój nie jest instancją klasy Room.

Source code in tests/unit/test_reservation.py
def test_invalid_room_type(self):
    """Test zgłoszenia błędu, gdy pokój nie jest instancją klasy Room."""
    with self.assertRaises(TypeError):
        Reservation(self.guest, "NiePokój", self.check_in, self.check_out)

test_repr_representation()

Test czy metoda repr zawiera kluczowe dane techniczne.

Source code in tests/unit/test_reservation.py
def test_repr_representation(self):
    """Test czy metoda __repr__ zawiera kluczowe dane techniczne."""
    reservation = Reservation(self.guest, self.room, self.check_in, self.check_out)
    rep = repr(reservation)
    self.assertIn("reservation_id", rep)
    self.assertIn("zameldowanie=2025-07-01", rep)
    self.assertIn("wymeldowanie=2025-07-05", rep)

test_str_representation()

Test czy metoda str zawiera kluczowe informacje.

Source code in tests/unit/test_reservation.py
def test_str_representation(self):
    """Test czy metoda __str__ zawiera kluczowe informacje."""
    reservation = Reservation(self.guest, self.room, self.check_in, self.check_out)
    self.assertIn("Jan Kowalski", str(reservation))
    self.assertIn("101", str(reservation))