def signup(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] zip_code = form.cleaned_data['zip_code'] if Registration.validate_email(email): registration = Registration.signup(email, zip_code) if registration: registration.send_signup_email() return redirect('signup-sent') else: return redirect(reverse('signup-failure') + "?signup_fail") else: return redirect(reverse('signup-failure') + "?validate_fail") # Method was not post, so we need to show the form else: form = RegistrationForm() return render_to_response('signup_form.tpl.html', RequestContext(request, { 'form': form, }))
def test_send_new_registration_board_message(self, send_email): registration = Registration( language="en", email="*****@*****.**", first_name="John", last_name="Doe", pk=0, ) emails.send_new_registration_board_message(registration) send_email.assert_called_once_with( settings.BOARD_NOTIFICATION_ADDRESS, "New registration", "registrations/email/registration_board.txt", { "name": registration.get_full_name(), "url": ( "https://thalia.localhost" + reverse( "admin:registrations_registration_change", args=[registration.pk], ) ), }, )
def test_save_model(self): reg = Registration(status=Registration.STATUS_REVIEW, birthday=timezone.now()) with self.subTest("Status review saves"): reg.first_name = "Test1" self.admin.save_model({}, reg, None, True) self.assertTrue( Registration.objects.filter(first_name="Test1").exists()) with self.subTest("Status accepted, no save"): reg.first_name = "Test2" reg.status = Registration.STATUS_ACCEPTED self.admin.save_model({}, reg, None, True) self.assertFalse( Registration.objects.filter(first_name="Test2").exists()) with self.subTest("Status reject, no save"): reg.first_name = "Test2" reg.status = Registration.STATUS_REJECTED self.admin.save_model({}, reg, None, True) self.assertFalse( Registration.objects.filter(first_name="Test2").exists()) with self.subTest("Status completed, no save"): reg.first_name = "Test2" reg.status = Registration.STATUS_COMPLETED self.admin.save_model({}, reg, None, True) self.assertFalse( Registration.objects.filter(first_name="Test2").exists())
def test_send_references_information_message(self, send_email): with self.subTest("Registrations"): registration = Registration( language="en", email="*****@*****.**", first_name="John", last_name="Doe", pk=uuid.uuid4(), ) emails.send_references_information_message(registration) send_email.assert_called_once_with( "*****@*****.**", "Information about references", "registrations/email/references_information.txt", { "name": registration.get_full_name(), "reference_link": ( "https://thalia.localhost" + reverse("registrations:reference", args=[registration.pk]) ), }, ) send_email.reset_mock() with self.subTest("Renewals"): member = Member( email="*****@*****.**", first_name="John", last_name="Doe", profile=Profile(language="en"), ) renewal = Renewal(pk=uuid.uuid4(), member=member) emails.send_references_information_message(renewal) send_email.assert_called_once_with( "*****@*****.**", "Information about references", "registrations/email/references_information.txt", { "name": renewal.member.get_full_name(), "reference_link": ( "https://thalia.localhost" + reverse("registrations:reference", args=[renewal.pk]) ), }, )
def confirm_email(request, uuid): registration = Registration.confirm_email_address(uuid) if registration: registration.fire_geocode_registration_task() return render_to_response("confirmation_success.tpl.html") else: return render_to_response("confirmation_failure.tpl.html")
def test_send_registration_rejected_message(self, send_email): reg = Registration( email="*****@*****.**", first_name="John", last_name="Doe", pk=0, ) emails.send_registration_rejected_message(reg) with translation.override(reg.language): send_email.assert_called_once_with( reg.email, _("Registration rejected"), "registrations/email/registration_rejected.txt", {"name": reg.get_full_name()}, )
def test_payment_status(self): reg = Registration(username="******", payment=Payment(pk="123", )) self.assertEqual( self.admin.payment_status(reg), '<a href="{}">{}</a>'.format("/admin/payments/payment/123/change/", _("Unprocessed")), ) reg.payment.type = Payment.CARD self.assertEqual( self.admin.payment_status(reg), '<a href="{}">{}</a>'.format("/admin/payments/payment/123/change/", _("Processed")), ) reg.payment = None self.assertEqual(self.admin.payment_status(reg), "-")
def test_send_registration_accepted_message(self, send_email): reg = Registration( language="en", email="*****@*****.**", first_name="John", last_name="Doe", pk=0, ) payment = Payment(amount=2,) emails.send_registration_accepted_message(reg, payment) with translation.override(reg.language): send_email.assert_called_once_with( reg.email, _("Registration accepted"), "registrations/email/registration_accepted.txt", {"name": reg.get_full_name(), "fees": floatformat(payment.amount, 2)}, )
def send_registration_rejected_message(registration: Registration) -> None: """ Send the registration rejection email :param registration: the registration entry """ with translation.override(registration.language): _send_email( registration.email, _("Registration rejected"), "registrations/email/registration_rejected.txt", {"name": registration.get_full_name()}, )
def test_send_registration_email_confirmation(self, send_email): reg = Registration( email="*****@*****.**", first_name="John", last_name="Doe", pk=uuid.uuid4(), ) emails.send_registration_email_confirmation(reg) with translation.override(reg.language): send_email.assert_called_once_with( reg.email, _("Confirm email address"), "registrations/email/registration_confirm_mail.txt", { "name": reg.get_full_name(), "confirm_link": ("https://thalia.localhost" + reverse("registrations:confirm-email", args=[reg.pk])), }, )
def send_registration_accepted_message(registration: Registration) -> None: """ Send the registration acceptance email :param registration: the registration entry """ with translation.override(registration.language): _send_email( registration.email, _("Registration accepted"), "registrations/email/registration_accepted.txt", { "name": registration.get_full_name(), "fees": floatformat(registration.contribution, 2), }, )
def send_new_registration_board_message(registration: Registration) -> None: """ Send a notification to the board about a new registration :param registration: the registration entry """ _send_email( settings.BOARD_NOTIFICATION_ADDRESS, "New registration", "registrations/email/registration_board.txt", { "name": registration.get_full_name(), "url": (settings.BASE_URL + reverse("admin:registrations_registration_change", args=[registration.pk])), }, )
def send_registration_email_confirmation(registration: Registration) -> None: """ Send the email confirmation message :param registration: the registration entry """ with translation.override(registration.language): _send_email( registration.email, _("Confirm email address"), "registrations/email/registration_confirm_mail.txt", { "name": registration.get_full_name(), "confirm_link": (settings.BASE_URL + reverse("registrations:confirm-email", args=[registration.pk])), }, )
def test_reject(self, reject_entries): reject_entries.return_value = 1 queryset = [] request = _get_mock_request([]) self.admin.reject_selected(request, queryset) reject_entries.assert_not_called() request = _get_mock_request(["registrations.review_entries"]) self.admin.reject_selected(request, queryset) reject_entries.assert_called_once_with(1, queryset) request._messages.add.assert_called_once_with( messages.SUCCESS, _("Successfully rejected %(count)d %(items)s.") % { "count": 1, "items": model_ngettext(Registration(), 1) }, "", )
def handle(self, *args, **options): if len(args) < 2: sys.exit("Please provide an email address and zip code.") else: email = args[0] zip_code = args[1] registration = Registration.signup(email, zip_code) if not registration: sys.exit("Error: that account is already registered.") registration.confirmation_email_sent = True registration.email_is_confirmed = True registration.confirmed_at = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) registration.updated_at = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) registration.save() registration.fire_geocode_registration_task() sys.exit("Done.")
def test_generate_username(self): username = services._generate_username(self.e1) self.assertEqual(username, "jdoe") self.e1.last_name = ( "famgtjbblvpcxpebclsjfamgtjbblvpcxpebcl" "sjfamgtjbblvpcxpebclsjfamgtjbblvpcxpeb" "clsjfamgtjbblvpcxpebclsjfamgtjbblvpcxp" "ebclsjfamgtjbblvpcxpebclsjfamgtjbblvpc" "xpebclsj" ) username = services._generate_username(self.e1) self.assertEqual( username, "jfamgtjbblvpcxpebclsjfamgtjbblvpcxpebclsjf" "amgtjbblvpcxpebclsjfamgtjbblvpcxpebclsjfam" "gtjbblvpcxpebclsjfamgtjbblvpcxpebclsjfamgt" "jbblvpcxpebclsjfamgtjbbl", ) possibilities = [ ("Bram", "in 't Zandt", "bintzandt"), ("Astrid", "van der Jagt", "avanderjagt"), ("Bart", "van den Boom", "bvandenboom"), ("Richard", "van Ginkel", "rvanginkel"), ("Edwin", "de Koning", "edekoning"), ("Martijn", "de la Cosine", "mdelacosine"), ("Robert", "Hissink Muller", "rhissinkmuller"), ("Robert", "Al-Malak", "ralmalak"), ("Arthur", "Domelé", "adomele"), ("Ben", "Brücker", "bbrucker"), ] for pos in possibilities: username = services._generate_username( Registration(first_name=pos[0], last_name=pos[1]) ) self.assertEqual(username, pos[2])
def test_name(self): reg = Registration( first_name="John", last_name="Doe", ) self.assertEqual(self.admin.name(reg), reg.get_full_name())
def test_get_readonly_fields(self): request = _get_mock_request([]) fields = self.admin.get_readonly_fields(request) self.assertEqual(fields, ["status", "created_at", "updated_at"]) fields = self.admin.get_readonly_fields( request, Registration(status=Entry.STATUS_CONFIRM)) self.assertEqual(fields, ["status", "created_at", "updated_at"]) fields = self.admin.get_readonly_fields( request, Registration(status=Entry.STATUS_REJECTED)) self.assertCountEqual( fields, [ "created_at", "updated_at", "status", "length", "membership_type", "remarks", "entry_ptr", "username", "first_name", "last_name", "birthday", "language", "email", "phone_number", "student_number", "programme", "starting_year", "address_street", "address_street2", "address_postal_code", "address_city", "address_country", "membership", "optin_mailinglist", "optin_birthday", "contribution", ], ) fields = self.admin.get_readonly_fields( request, Registration(status=Entry.STATUS_ACCEPTED)) self.assertCountEqual( fields, [ "created_at", "updated_at", "status", "length", "membership_type", "remarks", "entry_ptr", "username", "first_name", "last_name", "birthday", "language", "email", "phone_number", "student_number", "programme", "starting_year", "address_street", "address_street2", "address_postal_code", "address_city", "address_country", "membership", "optin_mailinglist", "optin_birthday", "contribution", ], ) fields = self.admin.get_readonly_fields( request, Registration(status=Entry.STATUS_COMPLETED)) self.assertCountEqual( fields, [ "created_at", "updated_at", "status", "length", "membership_type", "remarks", "entry_ptr", "username", "first_name", "last_name", "birthday", "language", "email", "phone_number", "student_number", "programme", "starting_year", "address_street", "address_street2", "address_postal_code", "address_city", "address_country", "membership", "optin_mailinglist", "optin_birthday", "contribution", ], )
def unsubscribe(request, uuid): success = Registration.unsubscribe(uuid=uuid) if success: return render_to_response('unsubscribe_success.tpl.html') else: return render_to_response('unsubscribe_failure.tpl.html')