def mail_service_invitation(context, service, recipients, preview=False): if not preview: _store_mail(None, SERVICE_INVITATION_MAIL, recipients) context = {**context, **{"expiry_period": calculate_expiry_period(context["invitation"])}, "service": service} return _do_send_mail( subject=f"Invitation to become service admin for {service.name}", recipients=recipients, template="service_invitation", context=context, preview=preview )
def mail_organisation_invitation(context, organisation, recipients, preview=False): if not preview: _store_mail(None, ORGANISATION_INVITATION_MAIL, recipients) context = {**context, **{"expiry_period": calculate_expiry_period(context["invitation"])}, "organisation": organisation} return _do_send_mail( subject=f"Invitation to join organisation {organisation.name}", recipients=recipients, template="organisation_invitation", context=context, preview=preview )
def mail_collaboration_invitation(context, collaboration, recipients, preview=False): if not preview: _store_mail(None, COLLABORATION_INVITATION_MAIL, recipients) context = {**context, **{"expiry_period": calculate_expiry_period(context["invitation"])}, "collaboration": collaboration} return _do_send_mail( subject=f"Invitation to join collaboration {collaboration.name}", recipients=recipients, template="collaboration_invitation", context=context, preview=preview )
def test_calculate_expiry_period_db_object(self): invitation = Invitation(expiry_date=datetime.datetime.today() + datetime.timedelta(minutes=15)) period = calculate_expiry_period(invitation) self.assertTrue(period.endswith("minutes"))
def test_calculate_expiry_period_with_today_day(self): today = datetime.datetime.today() invitation = Invitation(expiry_date=today + datetime.timedelta(days=1)) period = calculate_expiry_period(invitation, today=today) self.assertEqual("1 day", period)
def test_calculate_expiry_period_diff(self): today = datetime.datetime.today() period = calculate_expiry_period(munchify({"expiry_date": today + datetime.timedelta(minutes=15)}), today=today) self.assertEqual("15 minutes", period)
def test_calculate_expiry_period_default(self): period = calculate_expiry_period({}) self.assertEqual("15 days", period) period = calculate_expiry_period(Invitation()) self.assertEqual("15 days", period)
def test_calculate_expiry_period_today(self): today = datetime.datetime.today() period = calculate_expiry_period(munchify({"expiry_date": today}), today=today) self.assertEqual("0 minutes", period)
def test_calculate_expiry_period_hours(self): today = datetime.datetime.today() period = calculate_expiry_period(munchify({"expiry_date": today + datetime.timedelta(hours=6)}), today=today) self.assertTrue(period.endswith("hours"))
def test_calculate_expiry_period_days(self): period = calculate_expiry_period( munchify({"expiry_date": datetime.datetime.today() + datetime.timedelta(days=15)})) self.assertTrue(period.endswith("days"))