Skip to content

Commit 887695f

Browse files
committed
tests(gsr_booking): remove duplicate tests
1 parent 766a519 commit 887695f

3 files changed

Lines changed: 38 additions & 144 deletions

File tree

backend/tests/gsr_booking/test_gsr_booking.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ def test_bulk_invite(self):
7979
)
8080
self.assertEqual(200, response.status_code)
8181

82-
def test_invite_no_permission(self):
83-
self.client.login(username="user2", password="password")
84-
response = self.client.post(
85-
"/gsr/membership/invite/", {"user": "user2", "group": self.group.pk}
86-
)
87-
self.assertEqual(200, response.status_code)
88-
8982
def test_invite_logged_out_fails(self):
9083
self.client.logout()
9184
response = self.client.post(

backend/tests/gsr_booking/test_gsr_views.py

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ def setUp(self):
100100
self.client = APIClient()
101101
self.client.force_authenticate(user=self.user)
102102

103-
@mock.patch("gsr_booking.views.WhartonGSRBooker.is_wharton", return_value=False)
104-
@mock.patch("gsr_booking.views.PennGroupsGSRBooker.is_seas", return_value=False)
105-
def test_get_location(self, mock_is_seas, mock_is_wharton):
103+
def test_get_location(self):
104+
"""Test that the locations endpoint returns all GSRs without auth checks"""
106105
response = self.client.get(reverse("locations"))
107106
res_json = json.loads(response.content)
108107
for entry in res_json:
@@ -116,30 +115,18 @@ def test_get_location(self, mock_is_seas, mock_is_wharton):
116115
@mock.patch("gsr_booking.views.WhartonGSRBooker.is_wharton", return_value=False)
117116
@mock.patch("gsr_booking.views.PennGroupsGSRBooker.is_seas", return_value=False)
118117
def test_get_user_location(self, mock_is_seas, mock_is_wharton):
119-
"""Test that regular users do not see Wharton or PennGroups GSRs"""
118+
"""Test that regular users only see LibCal GSRs"""
120119
response = self.client.get(reverse("user-locations"))
121120
res_json = json.loads(response.content)
122121

123122
gsr_ids = [entry["id"] for entry in res_json]
124123

125-
# Use class variables
126124
self.assertNotIn(self.huntsman_gsr.id, gsr_ids)
127125
self.assertNotIn(self.agh_gsr.id, gsr_ids)
128126
self.assertIn(self.weigle_gsr.id, gsr_ids)
129-
130127
self.assertEqual(len(res_json), 1)
131128

132-
@mock.patch("gsr_booking.views.WhartonGSRBooker.is_wharton", return_value=False)
133-
@mock.patch("gsr_booking.views.PennGroupsGSRBooker.is_seas", return_value=False)
134-
def test_get_user_location_regular_user(self, mock_is_seas, mock_is_wharton):
135-
"""Test that regular users only see LibCal GSRs"""
136-
response = self.client.get(reverse("user-locations"))
137-
res_json = json.loads(response.content)
138-
139-
# Regular users should only see LibCal GSRs
140-
# Check kinds from response data directly
141129
for entry in res_json:
142-
self.assertIn("kind", entry)
143130
self.assertEqual(entry["kind"], GSR.KIND_LIBCAL)
144131

145132
@mock.patch("gsr_booking.views.WhartonGSRBooker.is_wharton", return_value=True)
@@ -228,28 +215,11 @@ def test_get_user_location_penn_labs_member(self, mock_is_wharton, mock_is_seas)
228215
self.assertIn(self.agh_gsr.id, gsr_ids, "AGH GSR should be visible")
229216
self.assertIn(self.weigle_gsr.id, gsr_ids, "Weigle GSR should be visible")
230217

231-
@mock.patch("gsr_booking.views.WhartonGSRBooker.is_wharton", return_value=False)
232-
@mock.patch("gsr_booking.views.PennGroupsGSRBooker.is_seas", return_value=False)
233-
def test_get_user_location_api_error_handling(self, mock_is_seas, mock_is_wharton):
234-
"""Test that when permission checks return False, users only see LibCal GSRs"""
235-
response = self.client.get(reverse("user-locations"))
236-
res_json = json.loads(response.content)
237-
238-
# When permission checks return False, users should only see LibCal GSRs
239-
for entry in res_json:
240-
self.assertIn("kind", entry)
241-
self.assertEqual(entry["kind"], GSR.KIND_LIBCAL)
242-
243218

244219
class TestGSRFunctions(TestCase):
245220
@classmethod
246221
def setUpTestData(cls):
247222
create_test_gsrs(cls)
248-
test_user = User.objects.create_user("user1", "user")
249-
with mock.patch(
250-
"gsr_booking.models.PennGroupsGSRBooker.is_seas", return_value=False
251-
), mock.patch("gsr_booking.models.WhartonGSRBooker.is_wharton", return_value=False):
252-
Group.objects.create(owner=test_user, name="Penn Labs", color="blue")
253223

254224
def setUp(self):
255225
self.user = User.objects.create_user("user", "user@seas.upenn.edu", "user")
@@ -388,11 +358,6 @@ class TestSEASViews(TestCase):
388358
@classmethod
389359
def setUpTestData(cls):
390360
create_test_gsrs(cls)
391-
test_user = User.objects.create_user("user1", "user")
392-
with mock.patch(
393-
"gsr_booking.models.PennGroupsGSRBooker.is_seas", return_value=False
394-
), mock.patch("gsr_booking.models.WhartonGSRBooker.is_wharton", return_value=False):
395-
Group.objects.create(owner=test_user, name="Penn Labs", color="blue")
396361

397362
def setUp(self):
398363
self.user = User.objects.create_user("user", "user@seas.upenn.edu", "user")
@@ -453,11 +418,6 @@ class TestPennGroupsViews(TestCase):
453418
@classmethod
454419
def setUpTestData(cls):
455420
create_test_gsrs(cls)
456-
test_user = User.objects.create_user("user1", "user")
457-
with mock.patch(
458-
"gsr_booking.models.PennGroupsGSRBooker.is_seas", return_value=False
459-
), mock.patch("gsr_booking.models.WhartonGSRBooker.is_wharton", return_value=False):
460-
Group.objects.create(owner=test_user, name="Penn Labs", color="blue")
461421

462422
def setUp(self):
463423
self.user = User.objects.create_user("user", "user@seas.upenn.edu", "user")

backend/tests/gsr_booking/test_gsr_wrapper.py

Lines changed: 35 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)