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')
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"
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"
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')
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')
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)
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()
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)
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.'}
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()
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')