Esempio n. 1
0
def test__mail__get_recipient_3(database, setUp):
    """It returns lastname and firstname of external recipient."""
    from sw.allotmentclub import ExternalRecipient, Message, User
    from ..mail import get_recipient
    muster = ExternalRecipient.create(lastname="Muster", firstname="Max")
    Message.create(id=300, externals=[muster], user=User.get(1))
    assert get_recipient(300) == "Muster, Max"
Esempio n. 2
0
def test__mail__MailAssignmentPreview_1(browser):
    """It can send Fehlende Arbeitsstunden."""
    from sw.allotmentclub import Message, User, Member, Assignment
    from sw.allotmentclub import AssignmentAttendee
    from sw.allotmentclub.conftest import import_members
    import_members()
    assignment = Assignment.find_or_create(
        day=datetime.now(),
        accounting_year=datetime.now().year
    )
    AssignmentAttendee.find_or_create(
        assignment=assignment,
        member=Member.query().filter(Member.lastname == 'Wehrmann').one(),
        hours=5)  # No letter
    AssignmentAttendee.find_or_create(
        assignment=assignment,
        member=Member.query().filter(Member.lastname == 'Hennig').one(),
        hours=3)  # Needs to pay less

    verein = Member.find_or_create(lastname="Verein")
    Message.create(id=245, members=[verein], user=User.create(),
                   accounting_year=2018,
                   subject="Fehlende Arbeitsstunden",
                   body=MISSING_ASSIGMENT_BODY)
    transaction.commit()
    browser.login()
    with mock.patch('sw.allotmentclub.browser.letter.datetime') as dt:
        dt.now.return_value = datetime(2016, 3, 25)
        browser.open('http://localhost/mail/245/preview')
    assertFileEqual(browser.contents, 'test_mail_fehlarbeitsstunden_1.pdf')
Esempio n. 3
0
def test__mail__get_recipient_4(database, setUp):
    """It returns Mehrere Empfänger if multiple recipients."""
    from sw.allotmentclub import ExternalRecipient, Message, User
    from ..mail import get_recipient
    muster = ExternalRecipient.create(lastname="Muster", firstname="Max")
    muster2 = ExternalRecipient.create(lastname="Mustermann", firstname="Max")
    Message.create(id=300, externals=[muster, muster2], user=User.get(1))
    assert get_recipient(300) == "Mehrere Empfänger"
Esempio n. 4
0
def get_recipient(value, request=None):
    recipients = Message.get(value).members + Message.get(value).externals
    if recipients:
        if (len(recipients)) > 1:
            return 'Mehrere Empfänger'
        recipient = recipients[0]
        if recipient.lastname == 'Verein':
            return 'Alle Mitglieder'
        return '{}, {}'.format(recipient.lastname, recipient.firstname)
Esempio n. 5
0
def test__mail__MailPreviewView_3(browser):
    """It does not print address and date if no member assigned to message."""
    from sw.allotmentclub import Message, User
    Message.create(id=244, user=User.create(), accounting_year=2015,
                   subject="Info-Brief", body="**Info** an alle Mitglieder")
    transaction.commit()
    browser.login()
    browser.open('http://localhost/mail/244/preview')
    assertFileEqual(browser.contents, 'test_mail_preview_3.pdf')
Esempio n. 6
0
def test__mail__print_or_sent_type_3(database, setUp):
    "It returns `Brief und E-Mail` if message is sent for multiple Members."
    from ..mail import print_or_sent_type, Message
    msg = Message.get(242)
    msg.printed = datetime.now()
    msg.sent = datetime.now()
    assert print_or_sent_type(msg.id) == "Brief und E-Mail"
Esempio n. 7
0
def test__mail__print_or_sent_date_2(database, setUp):
    """It returns sent date if message is sent."""
    from ..mail import print_or_sent_date, Message
    now = datetime(2016, 3, 25, 9, 37)
    msg = Message.get(243)
    msg.sent = now
    assert print_or_sent_date(msg.id) == "25.03.2016 09:37"
Esempio n. 8
0
def test__mail__MailElectricityPreview_1(browser):
    """It can send Energieabrechnungen."""
    from sw.allotmentclub import Message, User, Member
    from sw.allotmentclub.conftest import import_energy_meters, import_members
    import_members()
    import_energy_meters()
    verein = Member.find_or_create(lastname="Verein")
    Message.create(id=245, members=[verein], user=User.create(),
                   accounting_year=2014, subject="Energieabrechnung",
                   body=ENERGIEABRECHNUNG_BODY)
    transaction.commit()
    browser.login()
    with mock.patch('sw.allotmentclub.browser.letter.datetime') as dt:
        dt.now.return_value = datetime(2016, 3, 25)
        browser.open('http://localhost/mail/245/preview')
    assertFileEqual(browser.contents, 'test_mail_energieabrechnung_1.pdf')
Esempio n. 9
0
 def __init__(self, context, request):
     context = Message.create(user=request.user,
                              accounting_year=datetime.now().year)
     context.commit()
     super(MailAddView, self).__init__(context, request)
     log_with_user(user_data_log.info, self.request.user,
                   'Nachricht %s hinzugefügt.', self.context.id)
Esempio n. 10
0
def print_or_sent_type(value, request=None):
    message = Message.get(value)
    if message.sent and message.printed:
        return 'Brief und E-Mail'
    if message.sent:
        return 'E-Mail'
    if message.printed:
        return 'Brief'
Esempio n. 11
0
def setUp():
    from sw.allotmentclub import Member, Message, User, SentMessageInfo
    mustermann = Member.create(lastname="Mustermann", firstname="Max",
                               email='*****@*****.**')
    user = User.create(username='******')
    msg = Message.create(id=242, members=[mustermann], user=user,
                         accounting_year=2016, subject="Test", body="")
    SentMessageInfo.create(message=msg, tag='*****@*****.**',
                           address='*****@*****.**')
    transaction.commit()
Esempio n. 12
0
 def __init__(self, context, request):
     msg = Message.create(user=request.user,
                          in_reply_to=context,
                          accounting_year=datetime.now().year)
     msg.members.extend(context.members)
     msg.externals.extend(context.externals)
     msg.body = self.quote_body(context)
     msg.subject = 'Re: {}'.format(context.subject)
     msg.commit()
     super(MailReplyView, self).__init__(msg, request)
     log_with_user(user_data_log.info, self.request.user,
                   'Nachricht %s hinzugefügt.', self.context.id)
Esempio n. 13
0
def test__mail__MailPreviewView_1(browser, setUp):
    """It generates pdfs for recipients regardless of email."""
    from sw.allotmentclub import Message, Member
    message = Message.get(243)
    message.members.append(Member.create(
        email='*****@*****.**', street='Musterstrasse'))
    transaction.commit()
    browser.login()
    with mock.patch('sw.allotmentclub.browser.letter.datetime') as dt:
        dt.now.return_value = datetime(2016, 3, 25)
        browser.open('http://localhost/mail/243/preview')
    assertFileEqual(browser.contents, 'test_mail_preview_1.pdf')
Esempio n. 14
0
 def update(self):
     message = Message.create(accounting_year=datetime.now().year,
                              members=self.context.members,
                              externals=self.context.externals,
                              subject=self.context.subject,
                              body=self.context.body,
                              user=self.request.user)
     for attachment in self.context.attachments:
         Attachment.create(message=message,
                           filename=attachment.filename,
                           mimetype=attachment.mimetype,
                           size=attachment.size,
                           data=attachment.data)
     self.result = {'status': 'success', 'message': 'Duplikat erstellt.'}
Esempio n. 15
0
def test__mail__MailSentView_1(browser, setUp, mailer):
    """It does not sent mail if already sent."""
    from sw.allotmentclub import Message, Member
    assert 0 == len(mailer.outbox)
    message = Message.get(243)
    message.members.append(Member.create(
        email='*****@*****.**', street='Musterstrasse'))
    transaction.commit()
    browser.login()
    browser.open('http://localhost/mail/243/send')
    assert browser.json['message'] == '1 E-Mail(s) erfolgreich versendet'
    assert 1 == len(mailer.outbox)
    assert 'Willkommen' in mailer.outbox[0].subject

    browser.open('http://localhost/mail/243/send')
    assert browser.json['message'] == 'Keine E-Mail versendet'
    assert 1 == len(mailer.outbox)
    assert browser.json['redirect'] == '/api/mail/243/download'
Esempio n. 16
0
def setUp():
    from sw.allotmentclub import Member, Message, User
    verein = Member.create(lastname="Verein")
    mustermann = Member.create(lastname="Mustermann", firstname="Max")
    user = User.create(username='******')
    greeting = ('Sehr geehrte{{deflection}} {{appellation}} '
                '{{title}} {{lastname}},\n\n')
    Message.create(id=242, members=[verein], user=user, accounting_year=2015,
                   subject="Info-Brief",
                   body=greeting+"**Info** an alle Mitglieder")
    Message.create(id=243, members=[mustermann], user=user,
                   accounting_year=2015, subject="Willkommen",
                   body=greeting+"Willkommen im Verein.")
    Message.create(id=244, members=[mustermann], user=user,
                   accounting_year=2016, subject="Beitragsabrechnung",
                   body=greeting)
    transaction.commit()
Esempio n. 17
0
 def __call__(self):
     data = self.request.json
     sender = data['FromFull']['Email'].lower()
     if sender == '*****@*****.**':
         return Response('ok')
     if data['Subject'].startswith('***** SPAM'):
         return Response('ok')
     message = Message.create(inbound=True,
                              organization_id=self.organization_id,
                              user=User.by_username('system'))
     member = Member.query().filter(Member.email == sender).first()
     if member:
         message.members.append(member)
         message.organization_id = member.organization_id
     else:
         external = (ExternalRecipient.query().filter(
             ExternalRecipient.email == sender).first())
         if not external:
             external = ExternalRecipient.create(email=sender)
             external.lastname = data['FromFull']['Name']
             external.organization_id = self.organization_id
         message.externals.append(external)
         message.organization_id = external.organization_id
     message.subject = data['Subject']
     message.body = (data['HtmlBody']
                     if data['HtmlBody'] else data['TextBody'])
     message.sent = self.sent_date(data)
     message.accounting_year = message.sent.year
     for attachment in data['Attachments']:
         Attachment.create(message=message,
                           organization_id=message.organization_id,
                           filename=attachment["Name"],
                           mimetype=attachment["ContentType"],
                           size=attachment["ContentLength"],
                           data=base64.b64decode(attachment["Content"]))
     return Response('ok')
Esempio n. 18
0
def test__mail__print_or_sent_type_1(database, setUp):
    """It returns `E-Mail` if message is sent."""
    from ..mail import print_or_sent_type, Message
    msg = Message.get(243)
    msg.sent = datetime.now()
    assert print_or_sent_type(msg.id) == "E-Mail"
Esempio n. 19
0
def test__mail__postmark_inbound_webhook_1(browser):
    """It creates an inbound email for every request."""
    from sw.allotmentclub import Message, User
    user = User.find_or_create(username='******')
    browser.post(
        'http://localhost/mail/postmark_inbound_webhook',
        data={"FromName": "Postmarkapp Support",
              "From": "*****@*****.**",
              "FromFull": {
                  "Email": "*****@*****.**",
                  "Name": "Postmarkapp Support",
                  "MailboxHash": ""
              },
              "To": ("\"Firstname Lastname\" "
                     "<*****@*****.**>"),
              "ToFull": [
                  {
                      "Email": "*****@*****.**",
                      "Name": "Firstname Lastname",
                      "MailboxHash": "SampleHash"
                  }
              ],
              "Cc": ("\"First Cc\" "
                     "<*****@*****.**>, [email protected]>"),
              "CcFull": [
                  {
                      "Email": "*****@*****.**",
                      "Name": "First Cc",
                      "MailboxHash": ""
                  },
                  {
                      "Email": "*****@*****.**",
                      "Name": "",
                      "MailboxHash": ""
                  }
              ],
              "OriginalRecipient": "*****@*****.**",
              "Subject": "Test subject",
              "MessageID": "73e6d360-66eb-11e1-8e72-a8904824019b",
              "ReplyTo": "*****@*****.**",
              "MailboxHash": "SampleHash",
              # "Date": "Fri, 1 Aug 2014 16:45:32 -04:00",
              "Date": "Sat, 19 Aug 2017 19:37:23 +0200 (Mitteleurop?ische",
              "TextBody": "This is a test text body.",
              "HtmlBody": ("<html><body><p>"
                           "This is a test html body."
                           "</p></body></html>"),
              "StrippedTextReply": "This is the reply text",
              "Tag": "TestTag",
              "Headers": [
                  {
                      "Name": "X-Header-Test",
                      "Value": ""
                  },
                  {
                      "Name": "X-Spam-Status",
                      "Value": "No"
                  },
                  {
                      "Name": "X-Spam-Score",
                      "Value": "-0.1"
                  },
                  {
                      "Name": "X-Spam-Tests",
                      "Value": "DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_PASS"
                  }
              ],
              "Attachments": [
                  {
                      "Name": "test.pdf",
                      "Content": MINIMAL_TEST_PDF_CONTENTS,
                      "ContentType": "application/pdf",
                      "ContentLength": 739
                  }
              ]})
    mail = Message.query().one()
    assert '*****@*****.**' == mail.externals[0].email
    assert 'Postmarkapp Support' == mail.externals[0].lastname
    assert [] == mail.members
    assert "Test subject" == mail.subject
    assert user == mail.user
    assert mail.inbound is True
    assert ("<html><body><p>"
            "This is a test html body."
            "</p></body></html>" == mail.body)
    assert 1 == len(mail.attachments)
    assert MINIMAL_TEST_PDF_CONTENTS.encode() == base64.b64encode(
        mail.attachments[0].data)
    assert 'application/pdf' == mail.attachments[0].mimetype
    assert 'test.pdf' == mail.attachments[0].filename
    assert int(mail.attachments[0].size) == len(mail.attachments[0].data)
Esempio n. 20
0
def print_or_sent_date(value, request=None):
    message = Message.get(value)
    if message.sent:
        return date_time(message.sent)
    if message.printed:
        return date_time(message.printed)
Esempio n. 21
0
def test__mail__print_or_sent_type_2(database, setUp):
    """It returns `Brief` if message is printed."""
    from ..mail import print_or_sent_type, Message
    msg = Message.get(243)
    msg.printed = datetime.now()
    assert print_or_sent_type(msg.id) == "Brief"