def testConfirmationCode(self): """ Tests the submission of a confirmation code. """ activity = test_utils.create_event() activity.event_date = datetime.datetime.today() - datetime.timedelta( days=1, seconds=30) activity.save() ConfirmationCode.generate_codes_for_activity(activity, 10) code = ConfirmationCode.objects.filter(action=activity)[0] response = self.client.post(reverse("activity_add_task", args=("event", "test-event")), { "response": code.code, "code": 1, }, follow=True) self.failUnlessEqual(response.status_code, 200) self.assertEqual( ConfirmationCode.objects.filter(action=activity, is_active=False).count(), 1) code = ConfirmationCode.objects.filter(action=activity)[0] self.assertTrue(activity.action_ptr in self.user.action_set.filter( actionmember__award_date__isnull=False)) # Try submitting the code again and check if we have an error message. code = ConfirmationCode.objects.filter(action=activity)[1] response = self.client.post(reverse("activity_add_task", args=("event", "test-event")), { "response": code.code, "code": 1, }, follow=True) self.assertContains( response, "You have already redeemed a code for this action.") # Try creating a new activity with codes and see if we can submit a code for one activity # for another. code = ConfirmationCode.objects.filter(action=activity)[2] activity = test_utils.create_event(slug="test-event2") activity.event_date = datetime.datetime.today() - datetime.timedelta( days=1, seconds=30) activity.save() ConfirmationCode.generate_codes_for_activity(activity, 1) response = self.client.post(reverse("activity_add_task", args=("event", "test-event2")), { "response": code.code, "code": 1, }, follow=True) self.assertContains( response, "This confirmation code is not valid for this action.")
def testChangeEmailReminder(self): """ Test that we can adjust a reminder. """ event = test_utils.create_event() original_date = event.event_date - datetime.timedelta(hours=2) reminder = EmailReminder( user=self.user, action=event, email_address="*****@*****.**", send_at=original_date, ) reminder.save() reminder_count = self.user.emailreminder_set.count() response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": True, "email": "*****@*****.**", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) reminder = self.user.emailreminder_set.get(action=event) profile = Profile.objects.get(user=self.user) self.assertEqual(reminder.email_address, "*****@*****.**", "Email address should have changed.") self.assertEqual(profile.user.email, "*****@*****.**", "Profile email address should have changed.") self.assertNotEqual(reminder.send_at, original_date, "Send time should have changed.") self.assertEqual(self.user.emailreminder_set.count(), reminder_count, "No new reminders should have been created.")
def setUp(self): """ Create a test event and a test user. """ self.event = test_utils.create_event() self.user = User.objects.create_user("testuser", "*****@*****.**")
def testViewCodesAndRsvps(self): """test view code and rsvp.""" activity = test_utils.create_event() ConfirmationCode.generate_codes_for_activity(activity, 5) response = self.client.get( reverse('activity_view_codes', args=(activity.type, activity.slug))) self.failUnlessEqual(response.status_code, 404) response = self.client.get( reverse('activity_view_rsvps', args=(activity.type, activity.slug))) self.assertEqual(response.status_code, 404) self.user.is_staff = True self.user.save() response = self.client.get( reverse('activity_view_codes', args=(activity.type, activity.slug))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'view_codes.html') response = self.client.get( reverse('activity_view_rsvps', args=(activity.type, activity.slug))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'rsvps.html')
def testRemoveTextReminder(self): """ Test that we can adjust a text reminder. """ event = test_utils.create_event() reminder = TextReminder( user=self.user, action=event, text_number="8085551234", text_carrier="att", send_at=event.event_date - datetime.timedelta(hours=2), ) reminder.save() reminder_count = self.user.textreminder_set.count() response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": False, "email": "", "email_advance": "1", "send_text": False, "text_number": "", "text_carrier": "sprint", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertEqual(self.user.textreminder_set.count(), reminder_count - 1, "User should not have a reminder.")
def testRemoveTextReminder(self): """ Test that we can adjust a text reminder. """ event = test_utils.create_event() reminder = TextReminder( user=self.user, action=event, text_number="8085551234", text_carrier="att", send_at=event.event_date - datetime.timedelta(hours=2), ) reminder.save() reminder_count = self.user.textreminder_set.count() response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": False, "email": "", "email_advance": "1", "send_text": False, "text_number": "", "text_carrier": "sprint", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertEqual(self.user.textreminder_set.count(), reminder_count - 1, "User should not have a reminder.")
def testViewCodesAndRsvps(self): """test view code and rsvp.""" activity = test_utils.create_event() ConfirmationCode.generate_codes_for_activity(activity, 5) response = self.client.get( reverse('activity_view_codes', args=(activity.type, activity.id))) self.failUnlessEqual(response.status_code, 404) response = self.client.get( reverse('activity_view_rsvps', args=(activity.type, activity.id))) self.assertEqual(response.status_code, 404) self.user.is_staff = True self.user.save() response = self.client.get( reverse('activity_view_codes', args=(activity.type, activity.id))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'admin/view_codes.html') response = self.client.get( reverse('activity_view_rsvps', args=(activity.type, activity.id))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'admin/rsvps.html')
def testRemoveEmailReminder(self): """ Test that unchecking send_email will remove the reminder. """ event = test_utils.create_event() reminder = EmailReminder( user=self.user, action=event, email_address="*****@*****.**", send_at=event.event_date - datetime.timedelta(hours=2), ) reminder.save() reminder_count = self.user.emailreminder_set.count() response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": False, "email": "", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertEqual(self.user.emailreminder_set.count(), reminder_count - 1, "User should not have a reminder.")
def testRemoveEmailReminder(self): """ Test that unchecking send_email will remove the reminder. """ event = test_utils.create_event() reminder = EmailReminder( user=self.user, action=event, email_address="*****@*****.**", send_at=event.event_date - datetime.timedelta(hours=2), ) reminder.save() reminder_count = self.user.emailreminder_set.count() response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": False, "email": "", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertEqual(self.user.emailreminder_set.count(), reminder_count - 1, "User should not have a reminder.")
def testConfirmationCode(self): """ Tests the submission of a confirmation code. """ activity = test_utils.create_event() activity.event_date = datetime.datetime.today() - datetime.timedelta(days=1, seconds=30) activity.save() ConfirmationCode.generate_codes_for_activity(activity, 10) code = ConfirmationCode.objects.filter(action=activity)[0] response = self.client.post(reverse("activity_add_task", args=("event", "test-event")), { "response": code.code, "code": 1, }, follow=True) self.failUnlessEqual(response.status_code, 200) self.assertEqual(ConfirmationCode.objects.filter( action=activity, is_active=False).count(), 1) code = ConfirmationCode.objects.filter(action=activity)[0] self.assertTrue( activity.action_ptr in self.user.action_set.filter( actionmember__award_date__isnull=False)) # Try submitting the code again and check if we have an error message. code = ConfirmationCode.objects.filter(action=activity)[1] response = self.client.post(reverse("activity_add_task", args=("event", "test-event")), { "response": code.code, "code": 1, }, follow=True) print response self.assertContains(response, "You have already redeemed a code for this action.") # Try creating a new activity with codes and see if we can submit a code for one activity # for another. code = ConfirmationCode.objects.filter(action=activity)[2] activity = test_utils.create_event(slug="test-event2") activity.event_date = datetime.datetime.today() - datetime.timedelta(days=1, seconds=30) activity.save() ConfirmationCode.generate_codes_for_activity(activity, 1) response = self.client.post(reverse("activity_add_task", args=("event", "test-event2")), { "response": code.code, "code": 1, }, follow=True) self.assertContains(response, "This confirmation code is not valid for this action.")
def testAddTextReminder(self): """ Test that a user can create a text reminder. """ event = test_utils.create_event() reminders = self.user.textreminder_set.count() # Test invalid forms response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "", "text_carrier": "att", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid phone number is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.textreminder_set.count(), reminders, "Should not have added a reminder") response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "555", "text_carrier": "att", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid phone number is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.textreminder_set.count(), reminders, "Should not have added a reminder") # Test valid form response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "808-555-1234", "text_carrier": "att", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertEqual(self.user.textreminder_set.count(), reminders + 1, "Should have added a reminder") profile = Profile.objects.get(user=self.user) self.assertEqual(profile.contact_text, "808-555-1234", "Check that the user now has a contact number.") self.assertEqual(profile.contact_carrier, "att", "Check that the user now has a contact carrier.")
def setUp(self): """Generate test user and activity. Set the competition settings to the current date for testing.""" challenge_mgr.init() self.user = User.objects.create_user('user', '*****@*****.**') self.user.save() self.activity = test_utils.create_activity() self.event = test_utils.create_event() self.current_round = "Round 1" test_utils.set_competition_round()
def setUp(self): """Sets up the environment for running the tests.""" self.user = test_utils.setup_user(username="******", password="******") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() self.client.login(username="******", password="******") test_utils.set_competition_round() self.activity = test_utils.create_activity(slug=None, unlock_condition=None) self.activity.save() self.commitment = test_utils.create_commitment(slug=None, unlock_condition=None) self.commitment.save() self.event = test_utils.create_event(slug=None, unlock_condition=None) self.event.save()
def testAddEmailReminder(self): """ Test that the user can create a email reminder. """ event = test_utils.create_event() reminders = self.user.emailreminder_set.count() # Test invalid forms response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": True, "email": "", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid email address is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.emailreminder_set.count(), reminders, "Should not have added a reminder") response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": True, "email": "foo", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid email address is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.emailreminder_set.count(), reminders, "Should not have added a reminder") # Test valid form response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": True, "email": "*****@*****.**", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) profile = Profile.objects.get(user=self.user) self.assertEqual(profile.user.email, "*****@*****.**", "Profile should now have a contact email.") self.assertEqual(self.user.emailreminder_set.count(), reminders + 1, "Should have added a reminder")
def testChangeTextReminder(self): """ Test that we can adjust a text reminder. """ event = test_utils.create_event() original_date = event.event_date - datetime.timedelta(hours=2) reminder = TextReminder( user=self.user, action=event, text_number="8085551234", text_carrier="att", send_at=original_date, ) reminder.save() reminder_count = self.user.textreminder_set.count() response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "18085556789", "text_carrier": "sprint", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) reminder = self.user.textreminder_set.get(action=event) # print profile.contact_text profile = Profile.objects.get(user=self.user) self.assertEqual(reminder.text_number, "808-555-6789", "Text number should have updated.") self.assertEqual(profile.contact_text, "808-555-6789", "Profile text number should have updated.") self.assertNotEqual(reminder.send_at, original_date, "Send time should have changed.") self.assertEqual(self.user.textreminder_set.count(), reminder_count, "No new reminders should have been created.")
def testChangeEmailReminder(self): """ Test that we can adjust a reminder. """ event = test_utils.create_event() original_date = event.event_date - datetime.timedelta(hours=2) reminder = EmailReminder( user=self.user, action=event, email_address="*****@*****.**", send_at=original_date, ) reminder.save() reminder_count = self.user.emailreminder_set.count() response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": True, "email": "*****@*****.**", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) reminder = self.user.emailreminder_set.get(action=event) profile = Profile.objects.get(user=self.user) self.assertEqual(reminder.email_address, "*****@*****.**", "Email address should have changed.") self.assertEqual(profile.user.email, "*****@*****.**", "Profile email address should have changed.") self.assertNotEqual(reminder.send_at, original_date, "Send time should have changed.") self.assertEqual(self.user.emailreminder_set.count(), reminder_count, "No new reminders should have been created.")
def testChangeTextReminder(self): """ Test that we can adjust a text reminder. """ event = test_utils.create_event() original_date = event.event_date - datetime.timedelta(hours=2) reminder = TextReminder( user=self.user, action=event, text_number="8085551234", text_carrier="att", send_at=original_date, ) reminder.save() reminder_count = self.user.textreminder_set.count() response = self.client.post(reverse("activity_reminder", args=(event.type, event.slug,)), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "18085556789", "text_carrier": "sprint", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) reminder = self.user.textreminder_set.get(action=event) # print profile.contact_text profile = Profile.objects.get(user=self.user) self.assertEqual(reminder.text_number, "808-555-6789", "Text number should have updated.") self.assertEqual(profile.contact_text, "808-555-6789", "Profile text number should have updated.") self.assertNotEqual(reminder.send_at, original_date, "Send time should have changed.") self.assertEqual(self.user.textreminder_set.count(), reminder_count, "No new reminders should have been created.")
def testAddEmailReminder(self): """ Test that the user can create a email reminder. """ event = test_utils.create_event() reminders = self.user.emailreminder_set.count() # Test invalid forms response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": True, "email": "", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid email address is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.emailreminder_set.count(), reminders, "Should not have added a reminder") response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": True, "email": "foo", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid email address is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.emailreminder_set.count(), reminders, "Should not have added a reminder") # Test valid form response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": True, "email": "*****@*****.**", "email_advance": "1", "send_text": False, "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) profile = Profile.objects.get(user=self.user) self.assertEqual(profile.user.email, "*****@*****.**", "Profile should now have a contact email.") self.assertEqual(self.user.emailreminder_set.count(), reminders + 1, "Should have added a reminder")
def testAddTextReminder(self): """ Test that a user can create a text reminder. """ event = test_utils.create_event() reminders = self.user.textreminder_set.count() # Test invalid forms response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "", "text_carrier": "att", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid phone number is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.textreminder_set.count(), reminders, "Should not have added a reminder") response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "555", "text_carrier": "att", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertContains(response, "A valid phone number is required.", count=1, msg_prefix="Error text should be displayed.") self.assertEqual(self.user.textreminder_set.count(), reminders, "Should not have added a reminder") # Test valid form response = self.client.post(reverse("activity_reminder", args=( event.type, event.slug, )), { "send_email": False, "email": "", "email_advance": "1", "send_text": True, "text_number": "808-555-1234", "text_carrier": "att", "text_advance": "1", }, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.failUnlessEqual(response.status_code, 200) self.assertEqual(self.user.textreminder_set.count(), reminders + 1, "Should have added a reminder") profile = Profile.objects.get(user=self.user) self.assertEqual(profile.contact_text, "808-555-1234", "Check that the user now has a contact number.") self.assertEqual(profile.contact_carrier, "att", "Check that the user now has a contact carrier.")