def test_duplicate_ident(self, clear_automated_email_fixtures, render_empty_attendee_template): AutomatedEmailFixture(Attendee, 'subject', 'template.txt', lambda x: True, 'ident') with pytest.raises(AssertionError): AutomatedEmailFixture(Attendee, 'subject', 'template.txt', lambda x: True, 'ident')
def __init__(self, event): AutomatedEmailFixture.__init__( self, SeasonPassTicket, subject='Claim your {} badges with your MAGFest Season Pass'.format(event.name), ident='magprime_season_supporter_{}_invite'.format(event.slug), template='season_supporter_event_invite.txt', when=before(event.deadline), extra_data={'event': event})
def automated_email_fixtures(clear_automated_email_fixtures, render_empty_attendee_template): """ Generates 8 AutomatedEmails. Of those: * 4 are currently active (within the sending window) * 6 can be approved (already active, or will become active in the future) * 4 are html formatted """ for i, when in enumerate(ACTIVE_WHEN): template_ext = ['html', 'txt'][i % 2] AutomatedEmailFixture( Attendee, '{EVENT_NAME} {EVENT_YEAR} {EVENT_DATE} {{ attendee.full_name }}', 'attendee.{}'.format(template_ext), filter=lambda a: True, ident='attendee_{}{}'.format( template_ext, '_{}'.format('_'.join( w.active_when for w in when)).replace(' ', '_') if when else ''), when=when, sender='test_{}@example.com'.format('odd' if bool(i % 2) else 'even'), needs_approval=False, allow_at_the_con=False, allow_post_con=False, extra_data={'extra_data': 'EXTRA DATA'}) AutomatedEmail.reconcile_fixtures()
def automated_email_fixture(clear_automated_email_fixtures, render_empty_attendee_template): """ Generates a single AutomatedEmail that is currently active. """ AutomatedEmailFixture( Attendee, '{EVENT_NAME} {EVENT_YEAR} {EVENT_DATE} {{ attendee.full_name }}', 'attendee.txt', filter=lambda a: True, ident='attendee_txt', sender='*****@*****.**', extra_data={'extra_data': 'EXTRA DATA'}) AutomatedEmail.reconcile_fixtures()
def test_email_templates(plugins, expected, monkeypatch): monkeypatch.setattr(JinjaEnv, '_env', None) monkeypatch.setattr(JinjaEnv, '_exportable_functions', {}) monkeypatch.setattr(JinjaEnv, '_filter_functions', {}) monkeypatch.setattr(JinjaEnv, '_test_functions', {}) monkeypatch.setattr(JinjaEnv, '_template_dirs', []) monkeypatch.setattr(AutomatedEmail, '_fixtures', OrderedDict()) for plugin in plugins: JinjaEnv.insert_template_dir( os.path.join(__here__, plugin, 'templates')) with Session() as session: for email in session.query(AutomatedEmail).all(): session.delete(email) for i in range(1, 4): AutomatedEmailFixture(Attendee, 'Test Template {}'.format(i), 'test_template.txt', lambda a: True, needs_approval=False, ident='test_template_{}'.format(i)) AutomatedEmail.reconcile_fixtures() with Session() as session: attendee = Attendee(first_name='Test', last_name='Email', email='*****@*****.**') for i in range(1, 4): automated_email = session.query(AutomatedEmail).filter_by( ident='test_template_{}'.format(i)).one() for i in range(1, 4): assert expected == automated_email.render_body( attendee).strip(), 'render() call {}'.format(i)
def test_invalid_template(self, clear_automated_email_fixtures): with pytest.raises(TemplateNotFound): AutomatedEmailFixture(Attendee, 'subject', 'template.txt', lambda x: True, 'ident').body
def test_empty_ident(self, clear_automated_email_fixtures, render_empty_attendee_template, ident): AutomatedEmailFixture(Attendee, 'subject', 'template.txt', lambda x: True, ident)
from datetime import timedelta from uber.automated_emails import AutomatedEmailFixture, BandEmailFixture, StopsEmailFixture from uber.config import c from uber.models import Attendee from uber.utils import before, days_before AutomatedEmailFixture(Attendee, '{EVENT_NAME} food for guests', 'guest_food_restrictions.txt', lambda a: a.badge_type == c.GUEST_BADGE, ident='magwest_guest_food_restrictions', sender="MAGWest Tea Room <*****@*****.**>") AutomatedEmailFixture(Attendee, '{EVENT_NAME} hospitality suite information', 'guest_food_info.txt', lambda a: a.badge_type == c.GUEST_BADGE, ident='magwest_guest_food_info', sender="MAGWest Tea Room <*****@*****.**>") AutomatedEmailFixture( Attendee, '{EVENT_NAME} Volunteer Food', 'volunteer_food_info.txt', lambda a: a.staffing and days_before(7, c.FINAL_EMAIL_DEADLINE), ident='magwest_volunteer_food_info', sender="MAGWest Tea Room <*****@*****.**>") AutomatedEmailFixture(Attendee, '{EVENT_NAME} FAQ',
self, SeasonPassTicket, subject='Claim your {} badges with your MAGFest Season Pass'.format(event.name), ident='magprime_season_supporter_{}_invite'.format(event.slug), template='season_supporter_event_invite.txt', when=before(event.deadline), extra_data={'event': event}) for _event in SeasonEvent.instances.values(): SeasonSupporterEmailFixture(_event) AutomatedEmailFixture( Attendee, 'MAGFest schedule, maps, and other FAQs', 'precon_faqs.html', filter=lambda a: ( a.badge_status not in [c.INVALID_STATUS, c.DEFERRED_STATUS] and a.paid != c.NOT_PAID and (a.paid != c.PAID_BY_GROUP or a.group and not a.group.amount_unpaid)), ident='magprime_precon_faqs', when=days_before(7, c.EPOCH), sender='MAGFest <*****@*****.**>') AutomatedEmailFixture( Attendee, 'MAGFest food for guests', 'guest_food_restrictions.txt', lambda a: a.badge_type == c.GUEST_BADGE, sender='MAGFest Staff Suite <*****@*****.**>', ident='magprime_guest_food_restrictions') AutomatedEmailFixture( Attendee, 'MAGFest hospitality suite information', 'guest_food_info.txt', lambda a: a.badge_type == c.GUEST_BADGE, sender='MAGFest Staff Suite <*****@*****.**>',
def __init__(self, subject, template, filter, ident, **kwargs): AutomatedEmailFixture.__init__(self, ArtShowApplication, subject, template, lambda app: True and filter(app), ident, sender=c.ART_SHOW_EMAIL, **kwargs)
from datetime import timedelta from uber.automated_emails import AutomatedEmailFixture, BandEmailFixture, StopsEmailFixture from uber.config import c from uber.models import Attendee from uber.utils import before, days_before, days_after AutomatedEmailFixture(Attendee, '{EVENT_NAME} food for guests', 'guest_food_restrictions.txt', lambda a: a.badge_type == c.GUEST_BADGE, ident='magwest_guest_food_restrictions', sender="MAGWest Tea Room <*****@*****.**>") AutomatedEmailFixture(Attendee, '{EVENT_NAME} hospitality suite information', 'guest_food_info.txt', lambda a: a.badge_type == c.GUEST_BADGE, ident='magwest_guest_food_info', sender="MAGWest Tea Room <*****@*****.**>") AutomatedEmailFixture( Attendee, '{EVENT_NAME} Volunteer Food', 'volunteer_food_info.txt', lambda a: a.staffing and days_before(7, c.FINAL_EMAIL_DEADLINE), ident='magwest_volunteer_food_info', sender="MAGWest Tea Room <*****@*****.**>") AutomatedEmailFixture(Attendee, '{EVENT_NAME} FAQ',
_original_AutomatedEmail_reconcile = email.AutomatedEmail.reconcile def _AutomatedEmail_reconcile(self, fixture): _original_AutomatedEmail_reconcile(self, fixture) if self.ident == 'band_charity_reminder': self.subject = '{} charity raffle reminder'.format(c.EVENT_NAME) return self email.AutomatedEmail.reconcile = _AutomatedEmail_reconcile AutomatedEmailFixture( Attendee, '{EVENT_NAME} Check-in Barcode', 'checkin_barcode.html', lambda a: a.badge_status == c.COMPLETED_STATUS and days_before(7, c.FINAL_EMAIL_DEADLINE), ident='maglabs_checkin_barcode') AutomatedEmailFixture( Attendee, '{EVENT_NAME} FAQ', 'prefest_faq.html', lambda a: a.badge_status == c.COMPLETED_STATUS and days_before(7, c.FINAL_EMAIL_DEADLINE), ident='maglabs_prefest_faq') AutomatedEmailFixture( Room, '{EVENT_NAME} Hotel Room Assignment Update', 'hotel/room_assignment_update.txt', lambda r: r.locked_in,