Skip to content

Commit

Permalink
fix test cases failing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustaballer committed Oct 23, 2023
1 parent 42b4cc5 commit 2da73dd
Showing 1 changed file with 48 additions and 17 deletions.
65 changes: 48 additions & 17 deletions hackathon_site/event/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,6 @@ def check_can_leave_cancelled_or_returned(self):
self.assertNotEqual(old_team.pk, self.user.profile.team.pk)
self.assertFalse(Team.objects.filter(team_code=old_team.team_code).exists())

def check_can_leave_cancelled(self):
old_team = self.profile.team
sample_team = self._make_event_team(self_users=False, num_users=2)
response = self.client.post(self._build_view(sample_team.team_code))
self.user.refresh_from_db()

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["id"], self.user.profile.team.pk)
self.assertNotEqual(old_team.pk, self.user.profile.team.pk)
self.assertFalse(Team.objects.filter(team_code=old_team.team_code).exists())

def test_cannot_leave_with_order(self):
"""
check user cannot join another team when there
Expand Down Expand Up @@ -571,7 +560,7 @@ def test_user_not_logged_in(self):
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_user_can_have_profile(self):
self._review(application=self._apply_as_user(self.user))
self._review(application=self._apply_as_user(self.user, rsvp=True))
self._login()
response = self.client.post(self.view, self.request_body)
data = response.json()
Expand All @@ -588,15 +577,15 @@ def test_user_can_have_profile(self):
self.assertEqual(self.expected_response, data)

def test_not_including_required_fields(self):
self._review(application=self._apply_as_user(self.user))
self._review(application=self._apply_as_user(self.user, rsvp=True))
self._login()
response = self.client.post(self.view, {"e_signature": "user signature",})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
response = self.client.post(self.view, {"acknowledge_rules": True,})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_acknowledge_rules_is_false(self):
self._review(application=self._apply_as_user(self.user))
self._review(application=self._apply_as_user(self.user, rsvp=True))
self._login()
response = self.client.post(
self.view, {"e_signature": "user signature", "acknowledge_rules": False,},
Expand All @@ -608,7 +597,7 @@ def test_acknowledge_rules_is_false(self):
)

def test_e_signature_is_empty(self):
self._review(application=self._apply_as_user(self.user))
self._review(application=self._apply_as_user(self.user, rsvp=True))
self._login()
response = self.client.post(
self.view, {"e_signature": "", "acknowledge_rules": True,},
Expand Down Expand Up @@ -637,19 +626,46 @@ def test_user_has_not_completed_application(self):
"User has not completed their application to the hackathon. Please do so to access the Hardware Signout Site",
)

def test_user_has_not_been_reviewed(self):
def test_user_has_not_rsvp(self):
self._apply_as_user(self.user)
self._login()
response = self.client.post(self.view, self.request_body)
data = response.json()
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
data[0],
"User has not RSVP'd to the hackathon. Please RSVP to access the Hardware Signout Site",
)

def test_user_has_not_been_reviewed(self):
self._apply_as_user(self.user, rsvp=True)
self._login()
response = self.client.post(self.view, self.request_body)
data = response.json()
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
data[0],
"User has not been reviewed yet, Hardware Signout Site cannot be accessed until reviewed",
)

def test_user_has_been_reviewed_but_not_sent(self):
self._review(
application=self._apply_as_user(self.user, rsvp=True),
decision_sent_date=None,
)
self._login()
response = self.client.post(self.view, self.request_body)
data = response.json()
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
data[0],
"User has not been reviewed yet, Hardware Signout Site cannot be accessed until reviewed",
)

def test_user_review_rejected(self):
self._review(application=self._apply_as_user(self.user), status="Rejected")
self._review(
application=self._apply_as_user(self.user, rsvp=True), status="Rejected"
)
self._login()
response = self.client.post(self.view, self.request_body)
data = response.json()
Expand Down Expand Up @@ -862,8 +878,10 @@ def setUp(self, **kwargs):

self.permissions = Permission.objects.filter(
Q(content_type__app_label="event", codename="view_team")
| Q(content_type__app_label="event", codename="change_team")
| Q(content_type__app_label="event", codename="delete_team"),
)

super().setUp()

def _build_view(self, team_code):
Expand Down Expand Up @@ -916,6 +934,19 @@ def test_team_delete_with_returned_orders(self):
response = self.client.delete(self._build_view(self.team3.team_code))
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

def test_team_patch_not_login(self):
response = self.client.patch(
self._build_view("56ABD"), data={"project_description": "New description"}
)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_team_patch_no_permissions(self):
self._login()
response = self.client.patch(
self._build_view("56ABD"), data={"project_description": "New description"}
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)


class TeamOrderDetailViewTestCase(SetupUserMixin, APITestCase):
def setUp(self):
Expand Down

0 comments on commit 2da73dd

Please sign in to comment.