Beispiel #1
0
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
    )
Beispiel #2
0
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
    )
Beispiel #3
0
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
    )
Beispiel #4
0
 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"))
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
    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)
Beispiel #8
0
 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)
Beispiel #9
0
 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"))
Beispiel #10
0
 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"))