mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-11 04:19:25 +00:00
reservable rooms API
This commit is contained in:
0
reservation/tests/__init__.py
Normal file
0
reservation/tests/__init__.py
Normal file
28
reservation/tests/test_room_api.py
Normal file
28
reservation/tests/test_room_api.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
from model_bakery import baker
|
||||
from ninja_extra.testing import TestClient
|
||||
from pytest_django.asserts import assertNumQueries
|
||||
|
||||
from reservation.api import ReservableRoomController
|
||||
from reservation.models import Room
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestFetchRoom:
|
||||
def test_fetch_simple(self):
|
||||
rooms = baker.make(Room, _quantity=3, _bulk_create=True)
|
||||
response = TestClient(ReservableRoomController).get("")
|
||||
assert response.json() == [
|
||||
{
|
||||
"id": room.id,
|
||||
"name": room.name,
|
||||
"description": room.description,
|
||||
"address": room.address,
|
||||
"club": {"id": room.club.id, "name": room.club.name},
|
||||
}
|
||||
for room in rooms
|
||||
]
|
||||
|
||||
def test_nb_queries(self):
|
||||
with assertNumQueries(1):
|
||||
TestClient(ReservableRoomController).get("")
|
39
reservation/tests/test_slot_api.py
Normal file
39
reservation/tests/test_slot_api.py
Normal file
@ -0,0 +1,39 @@
|
||||
import pytest
|
||||
from model_bakery import baker
|
||||
from ninja_extra.testing import TestClient
|
||||
from pytest_django.asserts import assertNumQueries
|
||||
|
||||
from reservation.api import ReservableRoomController, ReservationSlotController
|
||||
from reservation.models import ReservationSlot
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestFetchRoom:
|
||||
def test_fetch_simple(self):
|
||||
slots = baker.make(ReservationSlot, _quantity=5, _bulk_create=True)
|
||||
response = TestClient(ReservationSlotController).get("")
|
||||
assert response.json() == [
|
||||
{
|
||||
"id": slot.id,
|
||||
"room": slot.room_id,
|
||||
"comment": slot.comment,
|
||||
"nb_people": slot.nb_people,
|
||||
"start": slot.start_at.isoformat(timespec="milliseconds").replace(
|
||||
"+00:00", "Z"
|
||||
),
|
||||
"end": slot.end_at.isoformat(timespec="milliseconds").replace(
|
||||
"+00:00", "Z"
|
||||
),
|
||||
"author": {
|
||||
"id": slot.author.id,
|
||||
"first_name": slot.author.first_name,
|
||||
"last_name": slot.author.last_name,
|
||||
"nick_name": slot.author.nick_name,
|
||||
},
|
||||
}
|
||||
for slot in slots
|
||||
]
|
||||
|
||||
def test_nb_queries(self):
|
||||
with assertNumQueries(1):
|
||||
TestClient(ReservableRoomController).get("")
|
Reference in New Issue
Block a user