diff --git a/webapp/tests/signup_fixture.py b/webapp/tests/signup_fixture.py new file mode 100644 index 0000000..b55a43c --- /dev/null +++ b/webapp/tests/signup_fixture.py @@ -0,0 +1,31 @@ +from webapp.models import Signup, SignupForm +from django.utils import timezone +from webapp.utils import month_from_now + +ALL_QUESTION_TYPES = [ + +] + + +def createSignupForm(name="Form1", start_time=timezone.now(), end_time=month_from_now(), questions=ALL_QUESTION_TYPES, visible=True): + return SignupForm.objects.create( + title=name, + start_time=start_time, + end_time=end_time, + questions=questions, + visible=visible + ) + + +def createSignupObject(form, answer): + return Signup.objects.create( + signupForm=form, + answer=answer + ) + + +def createSignupJSON(form_id, answer): + return { + "signupForm": form_id, + "answer": answer + } diff --git a/webapp/tests/test_event.py b/webapp/tests/test_event.py index 095a6e5..4ecc175 100644 --- a/webapp/tests/test_event.py +++ b/webapp/tests/test_event.py @@ -8,6 +8,7 @@ from webapp.models import Event from webapp.serializers import EventSerializer from webapp.tests.tag_fixture import tagBuilder, createTagIcon from webapp.tests.event_fixture import createEventObject, createEventJSON +from webapp.tests.signup_fixture import createSignupForm URL = "/api/events/" @@ -44,6 +45,8 @@ class EventTestCase(APITestCase): self.testEventId = test1.id self.assertEqual(Event.objects.count(), 4) + self.signupFormId = createSignupForm().id + username, password = "test_admin", "password123" self.authClient = User.objects.create_superuser(username, "myemail@test.com", password) @@ -99,7 +102,7 @@ class EventTestCase(APITestCase): self.client.force_authenticate(user=self.authClient) response = self.client.post( URL, - createEventJSON(tag_id=[self.testTagId]), + createEventJSON(tag_id=[self.testTagId], signup_id=[self.signupFormId]), format="json" ) @@ -109,7 +112,7 @@ class EventTestCase(APITestCase): def test_post_event_unauth(self): response = self.client.post( URL, - createEventJSON(tag_id=[self.testTagId]), + createEventJSON(tag_id=[self.testTagId], signup_id=[self.signupFormId]), format="json" ) @@ -120,7 +123,7 @@ class EventTestCase(APITestCase): # Authenticate self.client.force_authenticate(user=self.authClient) event = Event.objects.get(id=self.testEventId) - new = createEventJSON(name="Update1") + new = createEventJSON(name="Update1", signup_id=[self.signupFormId]) response = self.client.put( f"{URL}{self.testEventId}/", new, diff --git a/webapp/tests/test_signup.py b/webapp/tests/test_signup.py index cf822d4..73e8d19 100644 --- a/webapp/tests/test_signup.py +++ b/webapp/tests/test_signup.py @@ -1,51 +1,21 @@ from django.test import TestCase from django.contrib.auth.models import User -from django.utils import timezone from rest_framework import status from rest_framework.test import APITestCase, force_authenticate -from webapp.models import Signup, SignupForm from webapp.serializers import SignupSerializer, SignupFormSerializer +from webapp.models import Signup from webapp.tests.event_fixture import createEventObject -from webapp.utils import month_from_now +from webapp.tests.signup_fixture import createSignupForm, createSignupObject, createSignupJSON, ALL_QUESTION_TYPES URL = "/api/signup/" -ALL_QUESTION_TYPES = [ - -] - - -def createSignupForm(name="Form1", start_time=timezone.now(), end_time=month_from_now(), questions=ALL_QUESTION_TYPES, visible=True): - return SignupForm.objects.create( - title=name, - start_time=start_time, - end_time=end_time, - questions=questions, - visible=visible - ) - - -def createSignupObject(form, answer): - return Signup.objects.create( - signupForm=form, - answer=answer - ) - - -def createSignupJSON(form_id, answer): - return { - "signupForm": form_id, - "answer": answer - } - class SignupTestCase(APITestCase): def setUp(self): self.signupForm = createSignupForm() self.hiddenForm = createSignupForm(visible=False) - # self.event = createEventObject(signup_id=self.signupForm.id) self.signup1 = createSignupObject(self.signupForm, []) self.signup2 = createSignupObject(self.signupForm, []) diff --git a/webapp/tests/test_templateQuestions.py b/webapp/tests/test_templateQuestions.py index 8cfa4fd..28eea70 100644 --- a/webapp/tests/test_templateQuestions.py +++ b/webapp/tests/test_templateQuestions.py @@ -5,10 +5,7 @@ from rest_framework.test import APITestCase, force_authenticate from webapp.models import TemplateQuestion from webapp.serializers import SavedQuestionsSerializer - -ALL_QUESTION_TYPES = [ - -] +from webapp.tests.signup_fixture import ALL_QUESTION_TYPES class TemplateQuestionCase(APITestCase):