Skip to content

Commit

Permalink
Setting up registration fields (#4)
Browse files Browse the repository at this point in the history
* re-add qrcode dependencies

* update serializers.py

* update applications.js

* updated test_api.py

* updated tests.py

* update views.py

* updated jinja2.py

* updated init.py

* update tests.py

* update admin.py

* update forms.py

* updated application.html

* updated models.py

* updated test_forms.py

* update urls.py

* update views.py

* updated admin.py

* updated accepted_email_body.html

* updated tests.py

* updated views.py

* update review admin.py

* reverse changes

* reverify serializers.py

* reverify application.js

* reverify test_api.py

* reverify event/tests.py

* reverify event/views.py

* reverify hackathon_site/jinja2.py

* reverify settings/init.py

* reverify tests.py

* reverify admin.py

* modify .yml file to reflect newhacks-2024

* reverify admin.py

* reverify forms.py

* reverify application.html

* reverify models.py

* registration/test_forms.py

* reverify test_views.py

* reverify urls.py

* reverify views.py

* reverify other files in review folder

* [TEMP, REVERT LATER]: Change start of registration for testing purposes

* added migration file
  • Loading branch information
carmen-chau authored Jun 30, 2024
1 parent de12520 commit b7771f6
Show file tree
Hide file tree
Showing 23 changed files with 598 additions and 891 deletions.
8 changes: 4 additions & 4 deletions development/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ version: '3'
services:
postgres:
image: postgres:12.2
container_name: hackathon-template_postgres
container_name: newhacks-2024-postgres
ports:
- 5432:5432
environment:
- POSTGRES_DB=hackathon_site
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- hackathon-template_postgres-data:/var/lib/postgresql/data
- newhacks-2024-postgres-data:/var/lib/postgresql/data
redis:
image: redis:6-alpine
container_name: hackathon-template_redis
container_name: newhacks-2024_redis
ports:
- 6379:6379

volumes:
hackathon-template_postgres-data:
newhacks-2024-postgres-data:
27 changes: 9 additions & 18 deletions hackathon_site/event/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from django.contrib.auth.models import Group
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
Expand Down Expand Up @@ -104,22 +102,23 @@ def create(self, validated_data):
.user.groups.filter(name=settings.TEST_USER_GROUP)
.exists()
)

if not is_test_user:
try:
rsvp_status = Application.objects.get(user=current_user).rsvp
if not rsvp_status and settings.RSVP:
raise serializers.ValidationError(
"User has not RSVP'd to the hackathon. Please RSVP to access the Hardware Signout Site"
)
application = Application.objects.get(user=current_user)
# if not rsvp_status:
# raise serializers.ValidationError(
# "User has not RSVP'd to the hackathon. Please RSVP to access the Hardware Signout Site"
# )
except Application.DoesNotExist:
raise serializers.ValidationError(
"User has not completed their application to the hackathon. Please do so to access the Hardware Signout Site"
)

try:
review = Review.objects.get(application__user=current_user)
if review.status != "Accepted":
review_status = Review.objects.get(
application__user=current_user
).status
if review_status != "Accepted":
raise serializers.ValidationError(
f"User has not been accepted to participate in {settings.HACKATHON_NAME}"
)
Expand Down Expand Up @@ -174,14 +173,6 @@ class Meta:
"created_at",
"updated_at",
"profiles",
"project_description",
)
read_only_fields = (
"id",
"team_code",
"created_at",
"updated_at",
"profiles",
)


Expand Down
4 changes: 3 additions & 1 deletion hackathon_site/event/static/event/js/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$(document).ready(function () {
$("#id_q1, #id_q2, #id_q3").characterCounter();
$(
"#id_why_participate, #id_what_technical_experience, #id_what_past_experience"
).characterCounter();
});
100 changes: 8 additions & 92 deletions hackathon_site/event/test_api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.conf import settings
from django.contrib.auth.models import Group
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from hackathon_site.tests import SetupUserMixin
from django.contrib.auth.models import Permission
from django.db.models import Q


from event.models import Profile, User, Team
Expand Down Expand Up @@ -149,7 +147,7 @@ def check_cannot_leave_active(self):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(old_team.pk, self.user.profile.team.pk)

def check_can_leave_cancelled_or_returned(self):
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))
Expand Down Expand Up @@ -560,7 +558,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, rsvp=True))
self._review(application=self._apply_as_user(self.user))
self._login()
response = self.client.post(self.view, self.request_body)
data = response.json()
Expand All @@ -577,15 +575,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, rsvp=True))
self._review(application=self._apply_as_user(self.user))
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, rsvp=True))
self._review(application=self._apply_as_user(self.user))
self._login()
response = self.client.post(
self.view, {"e_signature": "user signature", "acknowledge_rules": False,},
Expand All @@ -597,7 +595,7 @@ def test_acknowledge_rules_is_false(self):
)

def test_e_signature_is_empty(self):
self._review(application=self._apply_as_user(self.user, rsvp=True))
self._review(application=self._apply_as_user(self.user))
self._login()
response = self.client.post(
self.view, {"e_signature": "", "acknowledge_rules": True,},
Expand Down Expand Up @@ -626,33 +624,8 @@ 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_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._apply_as_user(self.user)
self._login()
response = self.client.post(self.view, self.request_body)
data = response.json()
Expand All @@ -663,16 +636,13 @@ def test_user_has_been_reviewed_but_not_sent(self):
)

def test_user_review_rejected(self):
self._review(
application=self._apply_as_user(self.user, rsvp=True), status="Rejected"
)
self._review(application=self._apply_as_user(self.user), status="Rejected")
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],
f"User has not been accepted to participate in {settings.HACKATHON_NAME}",
data[0], "User has not been accepted to participate in hackathon"
)


Expand Down Expand Up @@ -878,10 +848,8 @@ 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 @@ -934,58 +902,6 @@ 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)

def test_team_patch_has_permissions(self):
self._login(self.permissions)
response = self.client.patch(
self._build_view(self.team.team_code),
data={"project_description": "New description"},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
updated_team = Team.objects.get(team_code=self.team.team_code)
self.assertEqual(updated_team.project_description, "New description")

def test_team_patch_invalid_request_data_format(self):
self._login(self.permissions)
response = self.client.patch(
self._build_view(self.team.team_code), data={"Invalid data"}, format="json"
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, "Invalid request data format")

def test_team_patch_invalid_field_for_update(self):
self._login(self.permissions)
response = self.client.patch(
self._build_view(self.team.team_code),
data={"invalid_field": "Invalid data"},
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data, '"invalid_field" is not a valid field for update'
)

def test_team_patch_invalid_project_description(self):
self._login(self.permissions)
response = self.client.patch(
self._build_view(self.team.team_code),
data={"project_description": 12345},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, "project_description must be a string")


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

0 comments on commit b7771f6

Please sign in to comment.