def setUp(self): self.member = Member.objects.filter(last_name="Wiggers").first() self.renewal = Renewal( member=self.member, length=Entry.MEMBERSHIP_STUDY, membership_type=Membership.MEMBER, )
def test_form_valid(self, board_mail, references_mail): mock_form = Mock(spec=RenewalFormView) member = Member( email="*****@*****.**", first_name="John", last_name="Doe", profile=Profile(), ) renewal = Renewal(pk=0, member=member) mock_form.save = MagicMock(return_value=renewal) with self.subTest("No references required"): renewal.no_references = True return_value = self.view.form_valid(mock_form) board_mail.assert_called_once_with(renewal) self.assertFalse(references_mail.called) self.assertEqual(return_value.status_code, 302) self.assertEqual(return_value.url, reverse("registrations:renew-success")) board_mail.reset_mock() with self.subTest("References required"): renewal.no_references = False return_value = self.view.form_valid(mock_form) board_mail.assert_called_once_with(renewal) references_mail.assert_called_once_with(renewal) self.assertEqual(return_value.status_code, 302) self.assertEqual(return_value.url, reverse("registrations:renew-success"))
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", "payment"]) fields = self.admin.get_readonly_fields( request, Renewal(status=Entry.STATUS_CONFIRM)) self.assertEqual( fields, ["status", "created_at", "updated_at", "payment", "member"]) fields = self.admin.get_readonly_fields( request, Renewal(status=Entry.STATUS_REJECTED)) self.assertCountEqual( fields, [ "created_at", "updated_at", "status", "length", "membership_type", "remarks", "entry_ptr", "member", "membership", "contribution", ], ) fields = self.admin.get_readonly_fields( request, Renewal(status=Entry.STATUS_ACCEPTED)) self.assertCountEqual( fields, [ "created_at", "updated_at", "status", "length", "membership_type", "remarks", "entry_ptr", "member", "membership", "contribution", ], )
def test_name(self): renewal = Renewal(member=Member( first_name="John", last_name="Doe", )) self.assertEqual(self.admin.name(renewal), renewal.member.get_full_name())
def test_send_renewal_accepted_message(self, send_email): member = Member( email="*****@*****.**", first_name="John", last_name="Doe", profile=Profile(), ) renewal = Renewal(pk=0, member=member, contribution=2) emails.send_renewal_accepted_message(renewal) with translation.override(renewal.member.profile.language): send_email.assert_called_once_with( renewal.member.email, _("Renewal accepted"), "registrations/email/renewal_accepted.txt", { "name": renewal.member.get_full_name(), "fees": floatformat(renewal.contribution, 2), "thalia_pay_enabled": settings.THALIA_PAY_ENABLED_PAYMENT_METHOD, "url": (settings.BASE_URL + reverse("registrations:renew", )), }, )
def setUpTestData(cls): cls.registration = Registration.objects.create( first_name="John", last_name="Doe", email="*****@*****.**", programme="computingscience", starting_year=2014, address_street="Heyendaalseweg 135", address_street2="", address_postal_code="6525AJ", address_city="Nijmegen", address_country="NL", phone_number="06123456789", birthday=timezone.now().replace(year=1990), language="en", length=Entry.MEMBERSHIP_YEAR, membership_type=Membership.MEMBER, status=Entry.STATUS_CONFIRM, ) cls.member = Member.objects.filter(last_name="Wiggers").first() cls.renewal = Renewal( member=cls.member, length=Entry.MEMBERSHIP_STUDY, membership_type=Membership.MEMBER, )
def test_str(self): member = Member.objects.filter(last_name="Wiggers").first() renewal = Renewal( member=member, length=Entry.MEMBERSHIP_YEAR, membership_type=Membership.MEMBER, ) ref = Reference(member=member, entry=renewal) self.assertEqual( str(ref), "Reference from Thom Wiggers (thom) for Thom Wiggers ()")
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 test_send_renewal_complete_message(self, send_email): member = Member( email="*****@*****.**", first_name="John", last_name="Doe", profile=Profile(), ) renewal = Renewal(pk=0, member=member) emails.send_renewal_complete_message(renewal) with translation.override(renewal.member.profile.language): send_email.assert_called_once_with( renewal.member.email, _("Renewal successful"), "registrations/email/renewal_complete.txt", {"name": renewal.member.get_full_name()}, )
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(Renewal(), 1) }, "", )
def test_send_new_renewal_board_message(self, send_email): member = Member( email="*****@*****.**", first_name="John", last_name="Doe", profile=Profile(), ) renewal = Renewal(pk=0, member=member) emails.send_new_renewal_board_message(renewal) send_email.assert_called_once_with( settings.BOARD_NOTIFICATION_ADDRESS, "New renewal", "registrations/email/renewal_board.txt", { "name": renewal.member.get_full_name(), "url": ("https://thalia.localhost" + reverse( "admin:registrations_renewal_change", args=[renewal.pk])), }, )
def test_send_renewal_accepted_message(self, send_email): member = Member( email="*****@*****.**", first_name="John", last_name="Doe", profile=Profile(language="en"), ) renewal = Renewal(pk=0, member=member) payment = Payment(amount=2,) emails.send_renewal_accepted_message(renewal, payment) with translation.override(renewal.member.profile.language): send_email.assert_called_once_with( renewal.member.email, _("Renewal accepted"), "registrations/email/renewal_accepted.txt", { "name": renewal.member.get_full_name(), "fees": floatformat(payment.amount, 2), }, )
def test_email(self): renewal = Renewal(member=Member(email="*****@*****.**")) self.assertEqual(self.admin.email(renewal), "*****@*****.**")
class RenewalTest(TestCase): fixtures = ["members.json"] def setUp(self): self.member = Member.objects.filter(last_name="Wiggers").first() self.renewal = Renewal( member=self.member, length=Entry.MEMBERSHIP_STUDY, contribution=8, membership_type=Membership.MEMBER, ) def test_str(self): self.assertEqual( str(self.renewal), "{} {} ({})".format(self.member.first_name, self.member.last_name, self.member.email), ) def test_save(self): self.renewal.pk = 2 self.renewal.status = Entry.STATUS_ACCEPTED self.renewal.save() self.assertEqual(self.renewal.status, Entry.STATUS_ACCEPTED) self.renewal.pk = None self.renewal.save() self.assertEqual(self.renewal.status, Entry.STATUS_REVIEW) def test_clean_works(self): self.member.membership_set.all().delete() self.renewal.clean() def test_existing_renewal_in_review(self): Renewal.objects.create( member=self.member, length=Entry.MEMBERSHIP_STUDY, membership_type=Membership.MEMBER, ) with self.assertRaises(ValidationError): self.renewal.clean() try: self.renewal.clean() except ValidationError as e: self.assertEqual( e.message, _("You already have a renewal request queued for review.")) def test_not_within_renew_period(self): membership = self.member.latest_membership membership.until = timezone.now().date() + timezone.timedelta(days=32) membership.save() self.renewal.length = Entry.MEMBERSHIP_YEAR with self.assertRaises(ValidationError): self.renewal.clean() try: self.renewal.clean() except ValidationError as e: self.assertCountEqual( e.error_dict, { "length": "You cannot renew your membership at this moment.", }, ) def test_within_renew_period(self): self.renewal.length = Entry.MEMBERSHIP_YEAR membership = self.member.latest_membership membership.until = timezone.now().date() + timezone.timedelta(days=31) membership.save() self.renewal.clean() def test_benefactor_no_study_length(self): self.renewal.length = Entry.MEMBERSHIP_STUDY self.renewal.membership_type = Membership.BENEFACTOR membership = self.member.latest_membership membership.until = timezone.now() membership.save() with self.assertRaises(ValidationError): self.renewal.clean() try: self.renewal.clean() except ValidationError as e: self.assertCountEqual( e.error_dict, { "length": "Benefactors cannot have a membership " "that lasts their entire study duration.", }, ) def test_has_active_membership(self): membership = self.member.current_membership membership.until = None membership.save() with self.assertRaises(ValidationError): self.renewal.clean() try: self.renewal.clean() except ValidationError as e: self.assertCountEqual( e.error_dict, { "length": "You currently have an active membership.", "membership_type": "You currently have an active membership.", }, ) def test_payable_attributes(self): self.assertEqual(self.renewal.payment_amount, 8) self.assertEqual( self.renewal.payment_notes, "Membership renewal member (study). Creation date: Jan. 1, 2019. Completion date: Jan. 1, 2019", ) self.assertEqual(self.renewal.payment_payer, self.renewal.member)