def test_should_return_mailjet_data_with_no_ongoing_booking( self, mock_is_offer_active, mock_build_pc_pro_offer_link): # Given stock = offers_factories.EventStockFactory( beginningDatetime=datetime(2019, 10, 9, 10, 20, 00)) booking = bookings_factories.CancelledIndividualBookingFactory( stock=stock, quantity=2) # When mailjet_data = retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking) # Then venue = stock.offer.venue assert mailjet_data == { "MJ-TemplateID": 780015, "MJ-TemplateLanguage": True, "Vars": { "departement": venue.departementCode, "nom_offre": stock.offer.name, "lien_offre_pcpro": "http://pc_pro.com/offer_link", "nom_lieu": venue.name, "prix": f"{stock.price}", "is_event": 1, "date": "09-Oct-2019", "heure": "12h20", "quantite": booking.quantity, "user_name": booking.publicName, "user_email": booking.email, "is_active": 1, "nombre_resa": 0, "users": [], }, }
def test_should_return_mailjet_data_on_thing_offer( self, mock_is_offer_active, mock_build_pc_pro_offer_link): # Given stock = offers_factories.ThingStockFactory() booking1 = bookings_factories.CancelledIndividualBookingFactory( stock=stock, quantity=2) booking2 = bookings_factories.IndividualBookingFactory(stock=stock, quantity=1) # When mailjet_data = retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking1) # Then venue = stock.offer.venue assert mailjet_data == { "MJ-TemplateID": 780015, "MJ-TemplateLanguage": True, "Vars": { "departement": venue.departementCode, "nom_offre": stock.offer.name, "lien_offre_pcpro": "http://pc_pro.com/offer_link", "nom_lieu": venue.name, "prix": f"{stock.price}", "is_event": 0, "date": "", "heure": "", "quantite": booking1.quantity, "user_name": booking1.publicName, "user_email": booking1.email, "is_active": 0, "nombre_resa": 1, "users": [{ "contremarque": booking2.token, "email": booking2.email, "firstName": booking2.firstName, "lastName": booking2.lastName, }], }, }
def test_should_return_mailjet_data_with_no_ongoing_booking( self, mock_is_offer_active, mock_build_pc_pro_offer_link): # Given user = create_user(email="*****@*****.**", public_name="Jean Dupont") offerer = create_offerer() venue = create_venue(offerer, name="Venue name", departement_code="75") offer = create_offer_with_event_product(venue, event_name="My Event") stock = create_stock_from_offer(offer, price=12.52, beginning_datetime=datetime( 2019, 10, 9, 10, 20, 00)) booking = create_booking(user=user, stock=stock, venue=venue, is_cancelled=True, quantity=2) recipients = "*****@*****.**" # When mailjet_data = retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking, recipients) # Then assert mailjet_data == { "FromEmail": "*****@*****.**", "MJ-TemplateID": 780015, "MJ-TemplateLanguage": True, "To": "*****@*****.**", "Vars": { "departement": "75", "nom_offre": "My Event", "lien_offre_pcpro": "http://pc_pro.com/offer_link", "nom_lieu": "Venue name", "prix": "12.52", "is_event": 1, "date": "09-Oct-2019", "heure": "12h20", "quantite": 2, "user_name": "Jean Dupont", "user_email": "*****@*****.**", "is_active": 1, "nombre_resa": 0, "env": "-development", "users": [], }, }
def send_user_driven_cancellation_email_to_offerer(booking: Booking) -> None: offerer_booking_email = booking.stock.offer.bookingEmail if offerer_booking_email: data = retrieve_offerer_booking_recap_email_data_after_user_cancellation(booking) mails.send(recipients=[offerer_booking_email], data=data)
def test_should_return_numerique_when_venue_is_virtual( self, mock_is_offer_active, mock_build_pc_pro_offer_link): # Given user1 = create_user(email="*****@*****.**", public_name="Jean Dupont") user2 = create_user(email="*****@*****.**", public_name="Jean Val", first_name="John", last_name="Doe") offerer = create_offerer() venue = create_venue(offerer, name="Venue name", is_virtual=True) offer = create_offer_with_thing_product(venue, thing_name="My Thing") stock = create_stock_from_offer(offer, price=12) booking1 = create_booking(user=user1, stock=stock, venue=venue, is_cancelled=True, quantity=2) create_booking(user=user2, stock=stock, venue=venue, is_cancelled=False, quantity=1, token="29JM9Q") # When mailjet_data = retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking1) # Then assert mailjet_data == { "MJ-TemplateID": 780015, "MJ-TemplateLanguage": True, "Vars": { "departement": "numérique", "nom_offre": "My Thing", "lien_offre_pcpro": "http://pc_pro.com/offer_link", "nom_lieu": "Venue name", "prix": "12", "is_event": 0, "date": "", "heure": "", "quantite": 2, "user_name": "Jean Dupont", "user_email": "*****@*****.**", "is_active": 0, "nombre_resa": 1, "users": [{ "contremarque": "29JM9Q", "email": "*****@*****.**", "firstName": "John", "lastName": "Doe" }], }, }
def test_should_return_mailjet_data_with_ongoing_bookings( self, mock_is_offer_active, mock_build_pc_pro_offer_link): # Given user1 = create_user(email="*****@*****.**", public_name="Jean Dupont") user2 = create_user(email="*****@*****.**", public_name="Jean Val", first_name="John", last_name="Doe") offerer = create_offerer() venue = create_venue(offerer, name="Venue name", departement_code="75") offer = create_offer_with_event_product(venue, event_name="My Event") stock = create_stock_from_offer(offer, price=0, beginning_datetime=datetime( 2019, 10, 9, 10, 20, 00)) booking1 = create_booking(user=user1, stock=stock, venue=venue, is_cancelled=True, quantity=2) create_booking(user=user2, stock=stock, venue=venue, is_cancelled=False, quantity=1, token="29JM9Q") # When mailjet_data = retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking1) # Then assert mailjet_data == { "MJ-TemplateID": 780015, "MJ-TemplateLanguage": True, "Vars": { "departement": "75", "nom_offre": "My Event", "lien_offre_pcpro": "http://pc_pro.com/offer_link", "nom_lieu": "Venue name", "prix": "Gratuit", "is_event": 1, "date": "09-Oct-2019", "heure": "12h20", "quantite": 2, "user_name": "Jean Dupont", "user_email": "*****@*****.**", "is_active": 1, "nombre_resa": 1, "users": [{ "contremarque": "29JM9Q", "email": "*****@*****.**", "firstName": "John", "lastName": "Doe" }], }, }
def send_user_driven_cancellation_email_to_offerer(booking: Booking) -> None: recipients = _build_recipients_list(booking) data = retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking) mails.send(recipients=recipients, data=data)
def send_user_driven_cancellation_email_to_offerer( booking: Booking, send_email: Callable[..., bool]) -> None: recipients = _build_recipients_list(booking) data = retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking, recipients) send_email(data=data)