@@ -478,6 +478,9 @@ def test_groupmembership_auto_sets_is_seas_false(self, mock_model_is_seas, mock_
478478 @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
479479 @mock .patch ("requests.get" , mock_penngroups_api_get )
480480 @mock .patch ("gsr_booking.api_wrapper.PennGroupsBookingWrapper.request" , mock_agh_libcal_request )
481+ @mock .patch (
482+ "gsr_booking.api_wrapper.PennGroupsBookingWrapper.get_user_pennid" , mock_get_user_pennid
483+ )
481484 def test_penngroups_availability (self , mock_is_seas , mock_is_wharton ):
482485 """Test AGH room availability for SEAS students"""
483486 availability = GSRBooker .get_availability (
@@ -489,11 +492,17 @@ def test_penngroups_availability(self, mock_is_seas, mock_is_wharton):
489492 self .assertIn ("rooms" , availability )
490493 self .assertEqual ("Amy Gutmann Hall" , availability ["name" ])
491494
492- if len (availability ["rooms" ]) > 0 :
493- room = availability ["rooms" ][0 ]
494- self .assertIn ("room_name" , room )
495- self .assertIn ("id" , room )
496- self .assertIn ("availability" , room )
495+ rooms = availability ["rooms" ]
496+ self .assertGreater (len (rooms ), 0 )
497+ room = rooms [0 ]
498+ self .assertIn ("room_name" , room )
499+ self .assertIn ("id" , room )
500+ self .assertIn ("availability" , room )
501+
502+ # Verify only authorized rooms are returned
503+ room_names = [r ["room_name" ] for r in rooms ]
504+ self .assertIn ("AGH 206" , room_names )
505+ self .assertIn ("AGH 334" , room_names )
497506
498507 @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = True )
499508 @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
@@ -504,6 +513,9 @@ def test_penngroups_availability(self, mock_is_seas, mock_is_wharton):
504513 )
505514 def test_book_penngroups (self , mock_is_seas , mock_is_wharton ):
506515 """Test booking an AGH room"""
516+ initial_reservation_count = Reservation .objects .count ()
517+ initial_booking_count = GSRBooking .objects .count ()
518+
507519 book_agh = GSRBooker .book_room (
508520 42437 ,
509521 172129 ,
@@ -512,7 +524,22 @@ def test_book_penngroups(self, mock_is_seas, mock_is_wharton):
512524 "2025-10-31T00:00:00-04:00" ,
513525 self .user ,
514526 )
515- self .assertEqual ("AGH 206" , book_agh .gsrbooking_set .first ().room_name )
527+
528+ # Verify reservation and booking counts incremented
529+ self .assertEqual (Reservation .objects .count (), initial_reservation_count + 1 )
530+ self .assertEqual (GSRBooking .objects .count (), initial_booking_count + 1 )
531+
532+ # Verify reservation details
533+ self .assertEqual (book_agh .creator , self .user )
534+ self .assertIsNotNone (book_agh .start )
535+ self .assertIsNotNone (book_agh .end )
536+
537+ # Verify booking details
538+ booking = book_agh .gsrbooking_set .first ()
539+ self .assertEqual (booking .room_name , "AGH 206" )
540+ self .assertEqual (booking .room_id , 172129 )
541+ self .assertEqual (booking .user , self .user )
542+ self .assertIsNotNone (booking .booking_id )
516543
517544 @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False )
518545 @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
@@ -583,27 +610,6 @@ def test_group_book_penngroups(self, mock_model_is_seas, mock_is_wharton):
583610 # Check reservation exists
584611 self .assertIsNotNone (Reservation .objects .get (pk = reservation .id ))
585612
586- @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = True )
587- @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
588- @mock .patch ("requests.get" , mock_penngroups_api_get )
589- @mock .patch ("gsr_booking.api_wrapper.PennGroupsBookingWrapper.request" , mock_agh_libcal_request )
590- @mock .patch (
591- "gsr_booking.api_wrapper.PennGroupsBookingWrapper.get_user_pennid" , mock_get_user_pennid
592- )
593- def test_penngroups_authorization_filtering (self , mock_is_seas , mock_is_wharton ):
594- """Test that only authorized rooms are returned for SEAS students"""
595- # User authorized for rooms 206 and 334
596- availability = GSRBooker .get_availability (
597- "20157" , 42437 , "2025-10-30" , "2025-10-31" , self .user
598- )
599-
600- rooms = availability ["rooms" ]
601- room_names = [room ["room_name" ] for room in rooms ]
602-
603- # Should only include authorized rooms
604- self .assertIn ("AGH 206" , room_names )
605- self .assertIn ("AGH 334" , room_names )
606-
607613 @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False )
608614 @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
609615 @mock .patch ("requests.get" , mock_non_seas_get )
@@ -763,8 +769,7 @@ def test_group_penngroups_availability_no_seas_members(
763769 self .assertIn ("rooms" , availability )
764770 self .assertEqual (0 , len (availability ["rooms" ]))
765771
766- @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
767- def test_extract_room_number (self , mock_is_wharton ):
772+ def test_extract_room_number (self ):
768773 """Test room number extraction from LibCal room names"""
769774 from gsr_booking .api_wrapper import PennGroupsGSRBooker
770775
@@ -782,8 +787,7 @@ def test_extract_room_number(self, mock_is_wharton):
782787 self .assertIsNone (PennGroupsGSRBooker .extract_room_number ("" ))
783788 self .assertIsNone (PennGroupsGSRBooker .extract_room_number ("206" ))
784789
785- @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
786- def test_is_room_authorized (self , mock_is_wharton ):
790+ def test_is_room_authorized (self ):
787791 """Test room authorization checking logic"""
788792 from gsr_booking .api_wrapper import PennGroupsGSRBooker
789793
@@ -832,69 +836,6 @@ def json(self):
832836 PennGroupsGSRBooker .get_authorized_rooms (self .user )
833837 self .assertIn ("timeout" , str (context .exception ).lower ())
834838
835- @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = True )
836- @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
837- @mock .patch ("requests.get" , mock_penngroups_api_get )
838- @mock .patch ("gsr_booking.api_wrapper.PennGroupsBookingWrapper.request" , mock_agh_libcal_request )
839- @mock .patch (
840- "gsr_booking.api_wrapper.PennGroupsBookingWrapper.get_user_pennid" , mock_get_user_pennid
841- )
842- def test_penngroups_booking_creates_reservation (self , mock_is_seas , mock_is_wharton ):
843- """Test that booking creates proper database records"""
844- initial_reservation_count = Reservation .objects .count ()
845- initial_booking_count = GSRBooking .objects .count ()
846-
847- book_agh = GSRBooker .book_room (
848- 42437 ,
849- 172129 ,
850- "AGH 206" ,
851- "2025-10-30T23:30:00-04:00" ,
852- "2025-10-31T00:00:00-04:00" ,
853- self .user ,
854- )
855-
856- # Verify reservation was created
857- self .assertEqual (Reservation .objects .count (), initial_reservation_count + 1 )
858- self .assertEqual (GSRBooking .objects .count (), initial_booking_count + 1 )
859-
860- # Verify reservation details
861- self .assertEqual (book_agh .creator , self .user )
862- self .assertIsNotNone (book_agh .start )
863- self .assertIsNotNone (book_agh .end )
864-
865- # Verify booking details
866- booking = book_agh .gsrbooking_set .first ()
867- self .assertEqual (booking .room_name , "AGH 206" )
868- self .assertEqual (booking .room_id , 172129 )
869- self .assertEqual (booking .user , self .user )
870- self .assertIsNotNone (booking .booking_id )
871-
872- @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = True )
873- @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
874- @mock .patch ("requests.get" , mock_penngroups_api_get )
875- @mock .patch ("gsr_booking.api_wrapper.PennGroupsBookingWrapper.request" , mock_agh_libcal_request )
876- def test_penngroups_availability_date_filtering (self , mock_is_seas , mock_is_wharton ):
877- """Test that availability respects date filtering"""
878- # Get availability for a specific date range
879- availability = GSRBooker .get_availability (
880- "20157" , 42437 , "2025-10-30" , "2025-10-31" , self .user
881- )
882-
883- # Verify structure
884- self .assertIn ("rooms" , availability )
885- rooms = availability ["rooms" ]
886-
887- # Verify each room has availability slots
888- for room in rooms :
889- self .assertIn ("availability" , room )
890- # Verify availability slots are within the requested date range
891- for slot in room ["availability" ]:
892- self .assertIn ("start_time" , slot )
893- self .assertIn ("end_time" , slot )
894- # Verify times are properly formatted
895- self .assertRegex (slot ["start_time" ], r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}" )
896- self .assertRegex (slot ["end_time" ], r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}" )
897-
898839 @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False )
899840 @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
900841 @mock .patch ("gsr_booking.api_wrapper.PennGroupsBookingWrapper.request" , mock_agh_libcal_request )
0 commit comments