Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vcai122 committed Dec 1, 2023
1 parent a0701c6 commit 825462a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 126 deletions.
106 changes: 0 additions & 106 deletions backend/gsr_booking/group_logic.py

This file was deleted.

17 changes: 0 additions & 17 deletions backend/gsr_booking/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import requests
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.utils import timezone
from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout


User = get_user_model()
Expand Down Expand Up @@ -46,20 +43,6 @@ def save(self, *args, **kwargs):

def check_wharton(self):
return WhartonGSRBooker.is_wharton(self.user)

Check warning on line 45 in backend/gsr_booking/models.py

View check run for this annotation

Codecov / codecov/patch

backend/gsr_booking/models.py#L45

Added line #L45 was not covered by tests
# not using api_wrapper.py to prevent circular dependency
url = f"https://apps.wharton.upenn.edu/gsr/api/v1/{self.user.username}/privileges"
try:
response = requests.get(
url, headers={"Authorization": f"Token {settings.WHARTON_TOKEN}"}
)

if response.status_code != 200:
return None

res_json = response.json()
return res_json.get("type") == "whartonMBA" or res_json.get("type") == "whartonUGR"
except (ConnectTimeout, ReadTimeout, KeyError, ConnectionError):
return None

class Meta:
verbose_name = "Group Membership"
Expand Down
28 changes: 25 additions & 3 deletions backend/tests/gsr_booking/test_gsr_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth import get_user_model
from django.core.management import call_command
from django.test import TestCase
from django.utils import timezone
from rest_framework.test import APIClient

from gsr_booking.api_wrapper import GSRBooker, WhartonGSRBooker
Expand Down Expand Up @@ -117,7 +118,6 @@ def test_book_libcal(self):
"2021-12-05T16:30:00-05:00",
self.user,
)
print("here", book_libcal)
self.assertEquals("VP WIC Booth 01", book_libcal.gsrbooking_set.first().room_name)

@mock.patch(
Expand Down Expand Up @@ -184,12 +184,15 @@ def test_group_book_libcal(self):
# add user to the group
GroupMembership.objects.create(user=self.user, group=self.group, accepted=True)

start = timezone.localtime()
end = start + timedelta(hours=2)

reservation = GSRBooker.book_room(
1889,
7192,
"VP WIC Booth 01",
"2021-12-05T16:00:00-05:00",
"2021-12-05T18:00:00-05:00",
start.strftime("%Y-%m-%dT%H:%M:%S%z"),
end.strftime("%Y-%m-%dT%H:%M:%S%z"),
self.user,
self.group,
)
Expand All @@ -203,3 +206,22 @@ def test_group_book_libcal(self):
self.assertEqual(total_time, timedelta(hours=2))
# check reservation exists
self.assertIsNotNone(Reservation.objects.get(pk=reservation.id))

res = GSRBooker.get_reservations(self.user, self.group)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]["room_name"], "[Me] VP WIC Booth 01")

@mock.patch("gsr_booking.api_wrapper.WhartonBookingWrapper.request", mock_requests_get)
def test_group_wharton_availability(self):
GroupMembership.objects.create(
user=self.user, group=self.group, accepted=True, is_wharton=True
)
availability = GSRBooker.get_availability(
"JMHH", 1, "2021-01-07", "2022-01-08", self.group_user, self.group
)
self.assertIn("name", availability)
self.assertIn("gid", availability)
self.assertIn("rooms", availability)
self.assertIn("room_name", availability["rooms"][0])
self.assertIn("id", availability["rooms"][0])
self.assertIn("availability", availability["rooms"][0])

0 comments on commit 825462a

Please sign in to comment.