Exemple #1
0
 def test_set_mail_template(self):
     set_mail_template('simple',
                       'Hey',
                       'Hello world!',
                       current_user=self.admin)
     self.assertEqual(MailTemplate.query.get('simple').text, 'Hello world!')
     self.assertEqual(MailTemplate.query.get('simple').subject, 'Hey')
Exemple #2
0
 def test_set_mail_template_forbidden(self):
     for user in (self.applicant, self.recruiter, self.senior_recruiter):
         with self.assertRaises(ForbiddenException):
             set_mail_template('simple',
                               'Subject',
                               'Hello world!',
                               current_user=user)
Exemple #3
0
 def test_get_mail_with_field(self):
     set_mail_template('simple',
                       'Subject',
                       'Hello {name}!',
                       current_user=self.admin)
     subject, mail_text = get_mail_text('simple', name='Bob')
     self.assertEqual(mail_text, 'Hello Bob!')
     self.assertEqual(subject, 'Subject')
Exemple #4
0
 def test_set_mail_template_with_field(self):
     set_mail_template('simple',
                       'Hey',
                       'Hello {character_name}!',
                       current_user=self.admin)
     self.assertEqual(
         MailTemplate.query.get('simple').text, 'Hello {character_name}!')
     self.assertEqual(MailTemplate.query.get('simple').subject, 'Hey')
Exemple #5
0
 def test_get_mail_with_multiple_fields(self):
     set_mail_template('simple',
                       'Subject',
                       '{salutation} {character_name}!',
                       current_user=self.admin)
     subject, mail_text = get_mail_text('simple',
                                        character_name='Bob',
                                        salutation='Hello')
     self.assertEqual(mail_text, 'Hello Bob!')
     self.assertEqual(subject, 'Subject')
Exemple #6
0
 def test_overwrite_mail_template(self):
     set_mail_template('simple',
                       'Subj',
                       'Hello {character_name}!',
                       current_user=self.admin)
     set_mail_template('simple',
                       'Subjec',
                       'Hi {character_name}!',
                       current_user=self.admin)
     self.assertEqual(
         MailTemplate.query.get('simple').text, 'Hi {character_name}!')
     self.assertEqual(MailTemplate.query.get('simple').subject, 'Subjec')
Exemple #7
0
 def test_get_mail_template_with_field(self):
     set_mail_template('simple',
                       'Hey',
                       'Hello {character_name}!',
                       current_user=self.admin)
     self.assertEqual(
         MailTemplate.query.get('simple').text, 'Hello {character_name}!')
     self.assertEqual(MailTemplate.query.get('simple').subject, 'Hey')
     response = get_mail_template('simple', current_user=self.admin)
     self.assertIn('info', response)
     data = response['info']
     self.assertIn('subject', data)
     self.assertIn('text', data)
     self.assertEqual(data['subject'], 'Hey')
     self.assertEqual(data['text'], 'Hello {character_name}!')
Exemple #8
0
def api_set_mail_template():
    """
    Sets a template.

    Template can include {name} in parts like 'Congratulations {name}', which
    will be filled using the to-character's name automatically later.

    Args:
        name (str) the endpoint name of the template" {'invite' | 'accept'}
        subject (str) email subject line
        template (str)

    Returns:
        {'status': 'ok'}

    Error codes:
        Forbidden (403): If logged in user is not an admin.
        Bad request (400): If any arguments are missing.
    """
    name = request.get_json().get('name')
    subject = request.get_json().get('subject')
    template = request.get_json().get('template')
    if name is None:
        raise BadRequestException('name argument is missing.')
    elif template is None:
        raise BadRequestException('template argument is missing.')
    elif subject is None:
        raise BadRequestException('subject argument is missing.')
    else:
        return jsonify(
            set_mail_template(name,
                              subject=subject,
                              text=template,
                              current_user=current_user))