Exemple #1
0
def test_should_return_digital_thing_specific_data_for_email_when_offer_is_a_digital_thing(
    mock_format_environment_for_email, ):
    booking = make_booking(
        quantity=10,
        stock__price=0,
        stock__offer__product__type=str(models.ThingType.AUDIOVISUEL),
        stock__offer__product__url="http://example.com",
        stock__offer__name="Super offre numérique",
    )
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(
        booking)

    expected = get_expected_base_email_data(
        booking,
        mediation,
        all_but_not_virtual_thing=0,
        all_things_not_virtual_thing=0,
        event_date="",
        event_hour="",
        is_event=0,
        is_single_event=0,
        offer_name="Super offre numérique",
        offer_price="Gratuit",
        can_expire=1,
    )
    assert email_data == expected
Exemple #2
0
    def test_use_activation_code_instead_of_token_if_possible(self):
        booking = bookings_factories.IndividualBookingFactory(
            individualBooking__user__email="*****@*****.**",
            quantity=10,
            stock__price=0,
            stock__offer__product__subcategoryId=subcategories.VOD.id,
            stock__offer__product__url="http://example.com?token={token}&offerId={offerId}&email={email}",
            stock__offer__name="Super offre numérique",
            dateCreated=datetime.utcnow(),
        )
        offers_factories.ActivationCodeFactory(stock=booking.stock, booking=booking, code="code_toto")
        mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

        email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

        expected = get_expected_base_email_data(
            booking,
            mediation,
            all_but_not_virtual_thing=0,
            all_things_not_virtual_thing=0,
            event_date="",
            event_hour="",
            is_event=0,
            is_single_event=0,
            offer_name="Super offre numérique",
            offer_price="Gratuit",
            can_expire=0,
            offer_token="code_toto",
            is_digital_booking_with_activation_code_and_no_expiration_date=1,
            code_expiration_date="",
            has_offer_url=1,
            digital_offer_url=f"http://example.com?token=code_toto&offerId={humanize(booking.stock.offer.id)}&[email protected]",
            expiration_delay="",
        )
        assert email_data == expected
Exemple #3
0
    def test_should_return_digital_thing_specific_data_for_email_when_offer_is_a_digital_thing(self):
        booking = bookings_factories.IndividualBookingFactory(
            quantity=10,
            stock__price=0,
            stock__offer__product__subcategoryId=subcategories.VOD.id,
            stock__offer__product__url="http://example.com",
            stock__offer__name="Super offre numérique",
            dateCreated=datetime.utcnow(),
        )
        mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

        email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

        expected = get_expected_base_email_data(
            booking,
            mediation,
            all_but_not_virtual_thing=0,
            all_things_not_virtual_thing=0,
            event_date="",
            event_hour="",
            is_event=0,
            is_single_event=0,
            offer_name="Super offre numérique",
            offer_price="Gratuit",
            can_expire=0,
            has_offer_url=1,
            digital_offer_url="http://example.com",
            expiration_delay="",
        )
        assert email_data == expected
Exemple #4
0
def test_should_return_event_specific_data_for_email_when_offer_is_an_event():
    booking = make_booking()
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(
        booking)

    expected = get_expected_base_email_data(booking, mediation)
    assert email_data == expected
Exemple #5
0
def test_should_return_event_specific_data_for_email_when_offer_is_an_event():
    booking = bookings_factories.IndividualBookingFactory(
        stock=offers_factories.EventStockFactory(price=23.99), dateCreated=datetime.utcnow()
    )
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)
    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

    expected = get_expected_base_email_data(booking, mediation)
    assert email_data == expected
Exemple #6
0
def test_digital_offer_without_departement_code_information():
    """
    Test that a user without any postal code information can book a digital
    offer. The booking date information should use the default timezone:
    metropolitan France.
    """
    offer = offers_factories.DigitalOfferFactory()
    stock = offers_factories.StockFactory(offer=offer)
    date_created = datetime(2021, 7, 1, 10, 0, 0, tzinfo=timezone.utc)
    booking = bookings_factories.IndividualBookingFactory(
        stock=stock, dateCreated=date_created, user__departementCode=None
    )

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)
    assert email_data["Vars"]["booking_date"] == "1 juillet 2021"
    assert email_data["Vars"]["booking_hour"] == "12h00"
Exemple #7
0
def test_should_return_event_specific_data_for_email_when_offer_is_a_duo_event(
        mock_format_environment_for_email):
    booking = make_booking(quantity=2)
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(
        booking)

    expected = get_expected_base_email_data(
        booking,
        mediation,
        is_duo_event=1,
        is_single_event=0,
        offer_price="47.98",
    )
    assert email_data == expected
Exemple #8
0
def test_should_return_withdrawal_details_when_available():
    withdrawal_details = "Conditions de retrait spécifiques."
    booking = bookings_factories.IndividualBookingFactory(
        stock__offer__withdrawalDetails=withdrawal_details,
        dateCreated=datetime.utcnow(),
    )
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

    expected = get_expected_base_email_data(
        booking,
        mediation,
        offer_withdrawal_details=withdrawal_details,
        **{key: value for key, value in email_data["Vars"].items() if key != "offer_withdrawal_details"},
    )
    assert email_data == expected
Exemple #9
0
def test_should_use_public_name_when_available():
    booking = bookings_factories.IndividualBookingFactory(
        stock__offer__venue__name="LIBRAIRIE GENERALE UNIVERSITAIRE COLBERT",
        stock__offer__venue__publicName="Librairie Colbert",
        dateCreated=datetime.utcnow(),
    )
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

    expected = get_expected_base_email_data(
        booking,
        mediation,
        venue_name="Librairie Colbert",
        **{key: value for key, value in email_data["Vars"].items() if key != "venue_name"},
    )
    assert email_data == expected
Exemple #10
0
    def test_hide_cancellation_policy_on_bookings_with_activation_code(self):
        offer = offers_factories.OfferFactory(
            venue__name="Lieu de l'offreur",
            venue__managingOfferer__name="Théâtre du coin",
            product=offers_factories.DigitalProductFactory(name="Super offre numérique", url="http://example.com"),
        )
        digital_stock = offers_factories.StockWithActivationCodesFactory()
        first_activation_code = digital_stock.activationCodes[0]
        booking = bookings_factories.UsedIndividualBookingFactory(
            stock__offer=offer,
            activationCode=first_activation_code,
            dateCreated=datetime(2018, 1, 1),
        )

        mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

        email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)
        expected = get_expected_base_email_data(
            booking,
            mediation,
            all_but_not_virtual_thing=0,
            all_things_not_virtual_thing=0,
            event_date="",
            event_hour="",
            is_event=0,
            is_single_event=0,
            offer_name="Super offre numérique",
            offer_price="10.00 €",
            offer_token=booking.activationCode.code,
            can_expire=0,
            is_digital_booking_with_activation_code_and_no_expiration_date=1,
            has_offer_url=1,
            digital_offer_url="http://example.com",
            user_first_name="Jeanne",
            venue_address="1 boulevard Poissonnière",
            venue_city="Paris",
            venue_postal_code="75000",
            booking_date="1 janvier 2018",
            booking_hour="01h00",
            expiration_delay="",
        )

        assert email_data == expected
Exemple #11
0
def test_should_return_thing_specific_data_for_email_when_offer_is_a_thing():
    booking = make_booking(
        stock__offer__product__type=str(models.ThingType.AUDIOVISUEL),
        stock__offer__name="Super bien culturel",
    )
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(
        booking)

    expected = get_expected_base_email_data(
        booking,
        mediation,
        all_things_not_virtual_thing=1,
        event_date="",
        event_hour="",
        is_event=0,
        is_single_event=0,
        offer_name="Super bien culturel",
        can_expire=1,
    )
    assert email_data == expected
Exemple #12
0
    def test_add_expiration_date_from_activation_code(self):
        booking = bookings_factories.IndividualBookingFactory(
            quantity=10,
            stock__price=0,
            stock__offer__product__subcategoryId=subcategories.VOD.id,
            stock__offer__product__url="http://example.com",
            stock__offer__name="Super offre numérique",
            dateCreated=datetime.utcnow(),
        )
        offers_factories.ActivationCodeFactory(
            stock=booking.stock,
            booking=booking,
            code="code_toto",
            expirationDate=datetime(2030, 1, 1),
        )
        mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

        email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

        expected = get_expected_base_email_data(
            booking,
            mediation,
            all_but_not_virtual_thing=0,
            all_things_not_virtual_thing=0,
            event_date="",
            event_hour="",
            is_event=0,
            is_single_event=0,
            offer_name="Super offre numérique",
            offer_price="Gratuit",
            can_expire=0,
            offer_token="code_toto",
            code_expiration_date="1 janvier 2030",
            has_offer_url=1,
            digital_offer_url="http://example.com",
            expiration_delay="",
        )
        assert email_data == expected
Exemple #13
0
    def test_should_return_new_expiration_delay_data_for_email_when_offer_is_a_book(self):
        booking = bookings_factories.IndividualBookingFactory(
            stock__offer__product__subcategoryId=subcategories.LIVRE_PAPIER.id,
            stock__offer__name="Super livre",
            dateCreated=datetime.utcnow(),
        )
        mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

        email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

        expected = get_expected_base_email_data(
            booking,
            mediation,
            all_things_not_virtual_thing=1,
            event_date="",
            event_hour="",
            is_event=0,
            is_single_event=0,
            offer_name="Super livre",
            can_expire=1,
            expiration_delay=10,
        )
        assert email_data == expected
Exemple #14
0
def test_should_return_thing_specific_data_for_email_when_offer_is_a_thing():
    stock = offers_factories.ThingStockFactory(
        price=23.99,
        offer__product__subcategoryId=subcategories.SUPPORT_PHYSIQUE_FILM.id,
        offer__name="Super bien culturel",
    )
    booking = bookings_factories.IndividualBookingFactory(stock=stock, dateCreated=datetime.utcnow())
    mediation = offers_factories.MediationFactory(offer=booking.stock.offer)

    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(booking.individualBooking)

    expected = get_expected_base_email_data(
        booking,
        mediation,
        all_things_not_virtual_thing=1,
        event_date="",
        event_hour="",
        is_event=0,
        is_single_event=0,
        offer_name="Super bien culturel",
        can_expire=1,
        expiration_delay=30,
    )
    assert email_data == expected
Exemple #15
0
def send_booking_confirmation_email_to_beneficiary(
        booking: Booking, send_email: Callable[..., bool]) -> None:
    data = retrieve_data_for_beneficiary_booking_confirmation_email(booking)
    send_email(data=data)
Exemple #16
0
def test_should_return_total_price_for_duo_offers():
    booking = bookings_factories.BookingFactory(quantity=2, stock__price=10)
    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(
        booking)
    assert email_data["Vars"]["offer_price"] == "20.00"
Exemple #17
0
def test_should_send_email_to_users_address_when_environment_is_production(
        mock_feature_send_mail_to_users_enabled):
    booking = bookings_factories.BookingFactory(user__email="*****@*****.**")
    email_data = retrieve_data_for_beneficiary_booking_confirmation_email(
        booking)
    assert email_data["To"] == "*****@*****.**"
def send_individual_booking_confirmation_email_to_beneficiary(individual_booking: IndividualBooking) -> None:
    data = retrieve_data_for_beneficiary_booking_confirmation_email(individual_booking)
    mails.send(recipients=[individual_booking.user.email], data=data)
def send_booking_confirmation_email_to_beneficiary(booking: Booking) -> None:
    data = retrieve_data_for_beneficiary_booking_confirmation_email(booking)
    mails.send(recipients=[booking.user.email], data=data)