def test_should_return_mailjet_data_with_correct_information_when_offer_is_an_event( self, build_pc_pro_offer_link): # Given user = create_user(public_name="John Doe", first_name="John", last_name="Doe", email="*****@*****.**") offerer = create_offerer() venue = create_venue(offerer, name="Venue name") 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, stock=stock, venue=venue, quantity=2, token="12345") bookings = [booking] # When mailjet_data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation( bookings) # Then assert mailjet_data == { "MJ-TemplateID": 1116333, "MJ-TemplateLanguage": True, "Vars": { "offer_name": "My Event", "lien_offre_pcpro": "http://pc_pro.com/offer_link", "venue_name": "Venue name", "price": "12.52", "is_event": 1, "event_date": "09-Oct-2019", "event_hour": "12h20", "quantity": 2, "reservations_number": 1, "users": [{ "countermark": "12345", "email": "*****@*****.**", "firstName": "John", "lastName": "Doe" }], }, }
def test_should_return_mailjet_data_when_multiple_bookings_and_offer_is_a_thing(self, build_pc_pro_offer_link): # Given beneficiary = users_factories.BeneficiaryGrant18Factory( publicName="John Doe", firstName="John", lastName="Doe", email="*****@*****.**" ) offer = offer_factories.ThingOfferFactory( venue__name="La petite librairie", venue__publicName="La grande librairie", product__name="Le récit de voyage", ) booking = booking_factories.IndividualBookingFactory( user=beneficiary, individualBooking__user=beneficiary, stock__offer=offer, stock__price=0, token="12346", quantity=6, ) other_beneficiary = users_factories.BeneficiaryGrant18Factory( publicName="James Bond", firstName="James", lastName="Bond", email="*****@*****.**" ) booking2 = booking_factories.IndividualBookingFactory( user=other_beneficiary, individualBooking__user=other_beneficiary, stock__offer=offer, stock__price=0, token="12345", quantity=1, ) bookings = [booking, booking2] # When mailjet_data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation(bookings) # Then assert mailjet_data == { "MJ-TemplateID": 1116333, "MJ-TemplateLanguage": True, "Vars": { "offer_name": "Le récit de voyage", "lien_offre_pcpro": "http://pc_pro.com/offer_link", "venue_name": "La grande librairie", "price": "Gratuit", "is_event": 0, "event_date": "", "event_hour": "", "quantity": 7, "reservations_number": 2, "users": [ {"countermark": "12346", "email": "*****@*****.**", "firstName": "John", "lastName": "Doe"}, {"countermark": "12345", "email": "*****@*****.**", "firstName": "James", "lastName": "Bond"}, ], }, }
def test_should_send_mail_to_offerer_and_pass_culture_administration_when_feature_send_mail_to_users_is_enabled( self, feature_send_mail_to_users_enabled ): # Given user = create_user() offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) event_occurrence = create_event_occurrence(offer) stock = create_stock_from_event_occurrence(event_occurrence) booking = create_booking(user=user, stock=stock) bookings = [booking] recipients = "[email protected], [email protected]" # When mailjet_data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation(bookings, recipients) # Then assert mailjet_data["To"] == "[email protected], [email protected]"
def test_should_return_mailjet_data_when_multiple_bookings_and_offer_is_a_thing( self, format_environment_for_email, build_pc_pro_offer_link, feature_send_mail_to_users_enabled ): # Given user = create_user(public_name="John Doe", first_name="John", last_name="Doe", email="*****@*****.**") offerer = create_offerer() venue = create_venue(offerer, name="La petite librairie", public_name="La grande librairie") thing_product = create_product_with_thing_type(thing_name="Le récit de voyage") offer = create_offer_with_thing_product(venue=venue, product=thing_product) stock = create_stock_from_offer(offer, price=0) booking = create_booking(user=user, stock=stock, token="12346", quantity=6) user2 = create_user(public_name="James Bond", first_name="James", last_name="Bond", email="*****@*****.**") booking2 = create_booking(user=user2, stock=stock, token="12345") recipients = "[email protected], [email protected]" bookings = [booking, booking2] # When mailjet_data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation(bookings, recipients) # Then assert mailjet_data == { "FromEmail": "*****@*****.**", "MJ-TemplateID": 1116333, "MJ-TemplateLanguage": True, "To": "*****@*****.**", "Vars": { "offer_name": "Le récit de voyage", "lien_offre_pcpro": "http://pc_pro.com/offer_link", "venue_name": "La grande librairie", "price": "Gratuit", "is_event": 0, "event_date": "", "event_hour": "", "quantity": 7, "reservations_number": 2, "env": "-testing", "users": [ {"countermark": "12346", "email": "*****@*****.**", "firstName": "John", "lastName": "Doe"}, {"countermark": "12345", "email": "*****@*****.**", "firstName": "James", "lastName": "Bond"}, ], }, }
def test_should_return_mailjet_data_with_correct_information_when_offer_is_an_event(self, build_pc_pro_offer_link): # Given beneficiary = users_factories.BeneficiaryGrant18Factory( publicName="John Doe", firstName="John", lastName="Doe", email="*****@*****.**" ) offer = offer_factories.EventOfferFactory( venue__name="Venue name", product__name="My Event", ) booking = booking_factories.IndividualBookingFactory( user=beneficiary, individualBooking__user=beneficiary, stock__offer=offer, stock__beginningDatetime=datetime(2019, 10, 9, 10, 20, 00), stock__price=12.52, quantity=2, token="12345", ) bookings = [booking] # When mailjet_data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation(bookings) # Then assert mailjet_data == { "MJ-TemplateID": 1116333, "MJ-TemplateLanguage": True, "Vars": { "offer_name": "My Event", "lien_offre_pcpro": "http://pc_pro.com/offer_link", "venue_name": "Venue name", "price": "12.52", "is_event": 1, "event_date": "09-Oct-2019", "event_hour": "12h20", "quantity": 2, "reservations_number": 1, "users": [ {"countermark": "12345", "email": "*****@*****.**", "firstName": "John", "lastName": "Doe"} ], }, }
def send_offerer_bookings_recap_email_after_offerer_cancellation(bookings: list[Booking]) -> None: offerer_booking_email = bookings[0].stock.offer.bookingEmail if offerer_booking_email: data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation(bookings) mails.send(recipients=[offerer_booking_email], data=data)
def send_offerer_bookings_recap_email_after_offerer_cancellation( bookings: List[Booking]) -> None: recipients = _build_recipients_list(bookings[0]) data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation( bookings) mails.send(recipients=recipients, data=data)
def send_offerer_bookings_recap_email_after_offerer_cancellation( bookings: List[Booking], send_email: Callable[..., bool]) -> None: recipients = _build_recipients_list(bookings[0]) data = retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation( bookings, recipients) send_email(data=data)