Skip to content

Commit

Permalink
Add unit test for bookingss resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Subash Pradhan committed Nov 4, 2024
1 parent a20b346 commit c2262e6
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 6 deletions.
44 changes: 38 additions & 6 deletions nylas/resources/bookings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
UpdatablePatchApiResource,
DestroyableApiResource,
)
from nylas.models.scheduler import Booking, CreateBookingRequest, CreateBookingQueryParams, ConfirmBookingRequest, DestroyBookingQueryParams
from nylas.models.scheduler import (
Booking,
CreateBookingRequest,
CreateBookingQueryParams,
ConfirmBookingRequest,
FindBookingQueryParams,
DeleteBookingRequest,
RescheduleBookingQueryParams,
DestroyBookingQueryParams,
ConfirmBookingQueryParams
)
from nylas.models.response import Response, DeleteResponse

class Bookings(
Expand All @@ -28,22 +38,27 @@ class Bookings(
"""

def find(
self, identifier: str, booking_id: str, overrides: RequestOverrides = None
self,
booking_id: str,
query_params: FindBookingQueryParams,
overrides: RequestOverrides = None
) -> Response[Booking]:
"""
Return a Booking.
Args:
identifier: The identifier of the Grant to act upon.
booking_id: The identifier of the Booking to get.
query_params: The query parameters to include in the request.
overrides: The request overrides to use for the request.
Returns:
The Booking.
"""

return super().find(
path=f"/v3/grants/{identifier}/bookings/{booking_id}",
path=f"/v3/scheduling/bookings/{booking_id}",
query_params=query_params,
response_type=Booking,
overrides=overrides,
)
Expand Down Expand Up @@ -76,14 +91,19 @@ def create(
)

def confirm(
self, booking_id: str, request_body:ConfirmBookingRequest, overrides: RequestOverrides = None
self,
booking_id: str,
request_body:ConfirmBookingRequest,
query_params: ConfirmBookingQueryParams = None,
overrides: RequestOverrides = None
) -> Response[Booking]:
"""
Confirm a Booking.
Args:
booking_id: The identifier of the Booking to confirm.
request_body: The values to confirm booking with.
query_params: The query parameters to include in the request.
overrides: The request overrides to use for the request.
Returns:
Expand All @@ -93,19 +113,25 @@ def confirm(
return super().update(
path=f"/v3/scheduling/bookings/{booking_id}",
request_body=request_body,
query_params=query_params,
response_type=Booking,
overrides=overrides,
)

def reschedule(
self, booking_id: str, request_body:CreateBookingRequest, overrides: RequestOverrides = None
self,
booking_id: str,
request_body:CreateBookingRequest,
query_params: RescheduleBookingQueryParams = None,
overrides: RequestOverrides = None
) -> Response[Booking]:
"""
Reschedule a Booking.
Args:
booking_id: The identifier of the Booking to reschedule.
request_body: The values to reschedule booking with.
query_params: The query parameters to include in the request.
overrides: The request overrides to use for the request.
Returns:
Expand All @@ -115,18 +141,23 @@ def reschedule(
return super().patch(
path=f"/v3/scheduling/bookings/{booking_id}",
request_body=request_body,
query_params=query_params,
response_type=Booking,
overrides=overrides,
)

def destroy(
self, booking_id: str, query_params: DestroyBookingQueryParams = None ,overrides: RequestOverrides = None
self, booking_id: str,
request_body: DeleteBookingRequest,
query_params: DestroyBookingQueryParams = None,
overrides: RequestOverrides = None
) -> DeleteResponse:
"""
Delete a Booking.
Args:
booking_id: The identifier of the Booking to delete.
request_body: The reason to delete booking with.
query_params: The query parameters to include in the request.
overrides: The request overrides to use for the request.
Expand All @@ -136,6 +167,7 @@ def destroy(

return super().destroy(
path=f"/v3/scheduling/bookings/{booking_id}",
request_body=request_body,
query_params=query_params,
overrides=overrides,
)
106 changes: 106 additions & 0 deletions tests/resources/test_bookings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from nylas.resources.bookings import Bookings

from nylas.models.scheduler import Booking

class TestBooking:
def test_booking_deserialization(self):
booking_json = {
"booking_id": "AAAA-BBBB-1111-2222",
"event_id": "CCCC-DDDD-3333-4444",
"title": "My test event",
"organizer": {
"name": "John Doe",
"email": "[email protected]"
},
"status": "booked",
"description": "This is an example of a description."
}

booking = Booking.from_dict(booking_json)

assert booking.booking_id == "AAAA-BBBB-1111-2222"
assert booking.event_id == "CCCC-DDDD-3333-4444"
assert booking.title == "My test event"
assert booking.organizer == {"name": "John Doe", "email": "[email protected]"}
assert booking.status == "booked"
assert booking.description == "This is an example of a description."

def test_find_booking(self, http_client_find_response):
bookings = Bookings(http_client_find_response)

bookings.find(booking_id="booking-123")

http_client_find_response._execute.assert_called_once_with(
"GET", "/v3/scheduling/bookings/booking-123", query_params=None, overrides=None
)

def test_create_booking(self, http_client_create_response):
bookings = Bookings(http_client_create_response)
request_body = {
"start_time": 1730725200,
"end_time": 1730727000,
"participants": [
{
"email": "[email protected]"
}
],
"guest": {
"name": "TEST",
"email": "[email protected]"
}
}
bookings.create(request_body=request_body)
http_client_create_response._execute.assert_called_once_with(
"POST",
"/v3/scheduling/bookings",
query_params=None,
request_body=request_body,
overrides=None
)

def test_confirm_booking(self, http_client_update_response):
bookings = Bookings(http_client_update_response)
request_body = {
"salt": "_zfg12it",
"status": "cancelled",
}

bookings.confirm(booking_id="booking-123", request_body=request_body)
http_client_update_response._execute.assert_called_once_with(
"PUT",
"/v3/scheduling/bookings/booking-123",
query_params=None,
request_body=request_body,
overrides=None
)

def test_reschedule_booking(self, http_client_update_response):
bookings = Bookings(http_client_update_response)
request_body = {
"start_time": 1730725200,
"end_time": 1730727000,
}

bookings.reschedule(booking_id="booking-123", request_body=request_body)
http_client_update_response._execute.assert_called_once_with(
"PATCH",
"/v3/scheduling/bookings/booking-123",
query_params=None,
request_body=request_body,
overrides=None
)

def test_destroy_booking(self, http_client_delete_response):
bookings = Bookings(http_client_delete_response)
request_body = {
"cancellation_reason": "I am no longer available at this time."
}
bookings.destroy(booking_id="booking-123")

http_client_delete_response._execute.assert_called_once_with(
"DELETE",
"/v3/scheduling/bookings/booking-123",
request_body=request_body,
query_params=None,
overrides=None
)

0 comments on commit c2262e6

Please sign in to comment.