Beispiel #1
0
def test_cancel_bookings_when_offerer_has_one_or_more():
    # Given
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    beneficiary1 = BeneficiaryGrant18Factory(email="*****@*****.**")
    beneficiary2 = BeneficiaryGrant18Factory(email="*****@*****.**")
    fraudulent_user = ProFactory(email="*****@*****.**", )
    offerer_with_bookings = OffererFactory()
    UserOffererFactory(user=fraudulent_user, offerer=offerer_with_bookings)
    offer1 = OfferFactory(venue__managingOfferer=offerer_with_bookings)
    offer2 = OfferFactory(venue__managingOfferer=offerer_with_bookings)
    stock1 = StockFactory(offer=offer1)
    stock2 = StockFactory(offer=offer2)
    booking1 = BookingFactory(user=beneficiary1, stock=stock1)
    booking2 = BookingFactory(user=beneficiary2, stock=stock2)

    # When
    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    # Then
    assert Offerer.query.count() == 1
    assert Venue.query.count() == 2
    assert Offer.query.count() == 2
    assert Stock.query.count() == 2
    assert Booking.query.count() == 2
    assert booking1.isCancelled
    assert booking1.status is BookingStatus.CANCELLED
    assert booking1.cancellationReason is BookingCancellationReasons.FRAUD
    assert booking2.isCancelled
    assert booking2.status is BookingStatus.CANCELLED
    assert booking2.cancellationReason is BookingCancellationReasons.FRAUD
    def test_only_suspend_beneficiary_users_in_given_emails_providers_list(
            self):
        # Given
        fraudulent_emails_providers = ["example.com"]
        admin_user = AdminFactory()
        beneficiary_fraudulent_user = BeneficiaryGrant18Factory(
            email="*****@*****.**")
        beneficiary_fraudulent_user_with_uppercase_domain = BeneficiaryGrant18Factory(
            email="*****@*****.**")
        beneficiary_fraudulent_user_with_subdomain = BeneficiaryGrant18Factory(
            email="*****@*****.**")
        non_beneficiary_fraudulent_user = UserFactory(
            email="*****@*****.**")
        booking_factories.IndividualBookingFactory(
            individualBooking__user=beneficiary_fraudulent_user,
            stock__price=1)

        # When
        suspend_fraudulent_beneficiary_users_by_email_providers(
            fraudulent_emails_providers, admin_user, dry_run=False)

        # Then
        assert not beneficiary_fraudulent_user.isActive
        assert not beneficiary_fraudulent_user_with_uppercase_domain.isActive

        # Do not handle sub-domains
        assert beneficiary_fraudulent_user_with_subdomain.isActive

        assert non_beneficiary_fraudulent_user.isActive
Beispiel #3
0
    def test_should_return_bookings_by_beneficiary_id(self, app):
        # Given
        beneficiary_1 = BeneficiaryGrant18Factory()
        beneficiary_2 = BeneficiaryGrant18Factory()
        offer = EventOfferFactory()
        stock = EventStockFactory(offer=offer)
        booking1 = booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary_1, stock=stock)
        booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary_2, stock=stock)

        # When
        result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary_1.id)

        # Then
        assert len(result.bookings) == 1
        assert result.bookings[0].id == booking1.id
Beispiel #4
0
def test_format_batch_user():
    user = BeneficiaryGrant18Factory(deposit__version=1)
    booking = IndividualBookingFactory(individualBooking__user=user)

    res = format_batch_users([user])

    assert len(res) == 1
    assert res[0].attributes == {
        "date(u.date_created)":
        user.dateCreated.strftime(BATCH_DATETIME_FORMAT),
        "date(u.date_of_birth)":
        user.dateOfBirth.strftime(BATCH_DATETIME_FORMAT),
        "date(u.deposit_expiration_date)":
        user.deposit_expiration_date.strftime(BATCH_DATETIME_FORMAT),
        "date(u.last_booking_date)":
        booking.dateCreated.strftime(BATCH_DATETIME_FORMAT),
        "u.credit":
        49000,
        "u.departement_code":
        "75",
        "u.is_beneficiary":
        True,
        "u.marketing_push_subscription":
        True,
        "u.postal_code":
        None,
        "ut.booking_categories": ["FILM"],
    }
Beispiel #5
0
    def when_user_has_booked_some_offers(self, app):
        # Given
        user = BeneficiaryGrant18Factory(email="*****@*****.**",
                                         postalCode="93020",
                                         deposit__version=1)

        IndividualBookingFactory(individualBooking__user=user, amount=5)

        # When
        response = (TestClient(app.test_client()).with_session_auth(
            "*****@*****.**").get("/beneficiaries/current"))

        # Then
        assert response.json["wallet_balance"] == 495.0
        assert response.json["domainsCredit"] == {
            "all": {
                "initial": 500.0,
                "remaining": 495.0
            },
            "digital": {
                "initial": 200.0,
                "remaining": 200.0
            },
            "physical": {
                "initial": 200.0,
                "remaining": 195.0
            },
        }
Beispiel #6
0
def test_only_suspend_pro_users_in_given_emails_providers_list():
    # Given
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    pro_fraudulent_user_with_uppercase_domain = ProFactory(
        email="*****@*****.**")
    pro_fraudulent_user_with_subdomain = ProFactory(
        email="*****@*****.**")
    beneficiary_fraudulent_user = BeneficiaryGrant18Factory(
        email="*****@*****.**")
    offerer1 = OffererFactory()
    UserOffererFactory(user=pro_fraudulent_user_with_uppercase_domain,
                       offerer=offerer1)
    offerer2 = OffererFactory()
    UserOffererFactory(user=pro_fraudulent_user_with_subdomain,
                       offerer=offerer2)

    # When
    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    # Then
    assert not pro_fraudulent_user_with_uppercase_domain.isActive

    # Do not handle sub-domains
    assert pro_fraudulent_user_with_subdomain.isActive
    assert beneficiary_fraudulent_user.isActive
    def test_should_return_event_data_when_booking_is_an_event(self):
        # Given
        booking = factories.CancelledIndividualBookingFactory(
            individualBooking__user=BeneficiaryGrant18Factory(
                email="*****@*****.**", firstName="Fabien"),
            stock=EventStockFactory(
                price=10.2,
                beginningDatetime=datetime.utcnow(),
                offer__name="Test event name",
                offer__id=123456,
            ),
        )

        # When
        email_data = make_beneficiary_booking_cancellation_email_data(
            booking.individualBooking)

        # Then
        assert email_data == {
            "Mj-TemplateID": 1091464,
            "Mj-TemplateLanguage": True,
            "Vars": {
                "can_book_again": 1,
                "event_date": "26 novembre 2019",
                "event_hour": "19h29",
                "is_event": 1,
                "is_free_offer": 0,
                "offer_id": "AHREA",
                "offer_name": "Test event name",
                "offer_price": "10.20",
                "user_first_name": "Fabien",
            },
        }
def test_tag_user_had_completed_id_check():
    # given
    recieved_beneficiary = UserFactory(hasCompletedIdCheck=False)
    already_beneficiary = BeneficiaryGrant18Factory(hasCompletedIdCheck=True)
    initiated_beneficiary = UserFactory(hasCompletedIdCheck=False)

    get_all_application_ids = Mock(return_value=[123, 456, 789])

    get_details = Mock()
    get_details.side_effect = [
        make_new_beneficiary_application_details(123, "received"),
        make_new_beneficiary_application_details(456, "received"),
        make_new_beneficiary_application_details(789, "initiated"),
    ]

    already_existing_user = Mock()
    already_existing_user.side_effect = [recieved_beneficiary, already_beneficiary, initiated_beneficiary]

    # when
    remote_tag_has_completed.run(
        ONE_WEEK_AGO,
        procedure_id=6712558,
        get_all_applications_ids=get_all_application_ids,
        get_details=get_details,
        already_existing_user=already_existing_user,
    )

    assert User.query.filter(User.hasCompletedIdCheck.is_(True)).count() == 3
Beispiel #9
0
def test_format_sendinblue_user():
    user = BeneficiaryGrant18Factory(deposit__version=1)
    booking = IndividualBookingFactory(individualBooking__user=user)

    res = format_sendinblue_users([user])

    assert len(res) == 1
    assert res[0].email == user.email
    assert res[0].attributes == {
        "BOOKED_OFFER_CATEGORIES": "FILM",
        "BOOKED_OFFER_SUBCATEGORIES": "SUPPORT_PHYSIQUE_FILM",
        "BOOKING_COUNT": 1,
        "CREDIT": Decimal("490.00"),
        "DATE_CREATED": user.dateCreated,
        "DATE_OF_BIRTH": user.dateOfBirth,
        "DEPARTMENT_CODE": "75",
        "DEPOSIT_ACTIVATION_DATE": user.deposit_activation_date,
        "DEPOSIT_EXPIRATION_DATE": user.deposit_expiration_date,
        "ELIGIBILITY": user.eligibility,
        "FIRSTNAME": "Jeanne",
        "HAS_COMPLETED_ID_CHECK": None,
        "INITIAL_CREDIT": Decimal("500"),
        "IS_BENEFICIARY": True,
        "IS_ELIGIBLE": user.is_eligible,
        "IS_EMAIL_VALIDATED": user.isEmailValidated,
        "IS_PRO": False,
        "LASTNAME": "Doux",
        "LAST_BOOKING_DATE": booking.dateCreated,
        "LAST_FAVORITE_CREATION_DATE": None,
        "LAST_VISIT_DATE": None,
        "MARKETING_EMAIL_SUBSCRIPTION": True,
        "POSTAL_CODE": None,
        "PRODUCT_BRUT_X_USE_DATE": None,
        "USER_ID": user.id,
    }
def test_get_user_attributes():
    user = BeneficiaryGrant18Factory(deposit__version=1)
    offer = OfferFactory(product__id=list(TRACKED_PRODUCT_IDS.keys())[0])
    b1 = IndividualBookingFactory(individualBooking__user=user,
                                  amount=10,
                                  stock__offer=offer)
    b2 = IndividualBookingFactory(individualBooking__user=user,
                                  amount=10,
                                  dateUsed=datetime(2021, 5, 6),
                                  stock__offer=offer)
    IndividualBookingFactory(
        individualBooking__user=user,
        amount=100,
        status=BookingStatus.CANCELLED)  # should be ignored

    last_date_created = max(booking.dateCreated for booking in [b1, b2])

    n_query_get_user = 1
    n_query_get_bookings = 1
    n_query_get_deposit = 1
    n_query_is_pro = 1
    n_query_get_last_favorite = 1

    with assert_num_queries(n_query_get_user + n_query_get_bookings +
                            n_query_get_deposit + n_query_is_pro +
                            n_query_get_last_favorite):
        attributes = get_user_attributes(user)

    assert attributes == UserAttributes(
        domains_credit=DomainsCredit(
            all=Credit(initial=Decimal("500"), remaining=Decimal("480.00")),
            digital=Credit(initial=Decimal("200"), remaining=Decimal("200")),
            physical=Credit(initial=200, remaining=Decimal("180.00")),
        ),
        booking_categories=["FILM"],
        date_created=user.dateCreated,
        date_of_birth=user.dateOfBirth,
        departement_code="75",
        deposit_expiration_date=user.deposit_expiration_date,
        eligibility=EligibilityType.AGE18,
        first_name="Jeanne",
        is_beneficiary=True,
        is_pro=False,
        last_booking_date=last_date_created,
        last_name="Doux",
        marketing_push_subscription=True,
        postal_code=None,
        products_use_date={"product_brut_x_use": datetime(2021, 5, 6, 0, 0)},
        booking_count=2,
        booking_subcategories=["SUPPORT_PHYSIQUE_FILM"],
        deposit_activation_date=user.deposit_activation_date,
        has_completed_id_check=None,
        user_id=user.id,
        is_eligible=True,
        is_email_validated=True,
        last_favorite_creation_date=None,
        last_visit_date=None,
        marketing_email_subscription=True,
    )
Beispiel #11
0
def test_patch_beneficiary_tutorial_related_attributes(app):
    user = BeneficiaryGrant18Factory()

    client = TestClient(app.test_client()).with_session_auth(email=user.email)
    data = {"hasSeenTutorials": True}
    response = client.patch("/beneficiaries/current", json=data)

    assert response.status_code == 200
    def test_dont_suspend_users_not_in_given_user_ids_list(self):
        fraudulent_user_ids = [16]
        admin_user = AdminFactory()
        beneficiary = BeneficiaryGrant18Factory(id=15)

        suspend_fraudulent_beneficiary_users_by_ids(fraudulent_user_ids,
                                                    admin_user,
                                                    dry_run=False)

        assert beneficiary.isActive
    def when_user_has_bookings_and_qr_code_feature_is_active(
            self, qr_code_is_active, app):
        # Given
        user1 = BeneficiaryGrant18Factory(email="*****@*****.**")
        user2 = BeneficiaryGrant18Factory(email="*****@*****.**")
        venue = VenueFactory(latitude=None, longitude=None)
        offer = ThingOfferFactory(venue=venue)
        offer2 = ThingOfferFactory()
        stock = ThingStockFactory(offer=offer, price=0, quantity=None)
        stock2 = ThingStockFactory(offer=offer2, price=0)
        IndividualBookingFactory(individualBooking__user=user1,
                                 stock=stock,
                                 token="ABCDEF")
        IndividualBookingFactory(individualBooking__user=user2,
                                 stock=stock,
                                 token="GHIJK")
        IndividualBookingFactory(individualBooking__user=user1,
                                 stock=stock2,
                                 token="BBBBB")

        # When
        response = TestClient(app.test_client()).with_session_auth(
            user1.email).get("/bookings")

        # Then
        all_bookings = response.json
        assert len(all_bookings) == 2
        first_booking = all_bookings[0]
        assert response.status_code == 200
        assert "qrCode" in first_booking
        assert "completedUrl" in first_booking
        assert "isEventExpired" in first_booking
        assert "offer" in first_booking["stock"]
        assert "isEventExpired" in first_booking["stock"]
        assert "isDigital" in first_booking["stock"]["offer"]
        assert "isEvent" in first_booking["stock"]["offer"]
        assert "thumbUrl" in first_booking["stock"]["offer"]
        assert "stocks" in first_booking["stock"]["offer"]
        assert "venue" in first_booking["stock"]["offer"]
        assert "validationToken" not in first_booking["stock"]["offer"][
            "venue"]
    def test_report_inappropriate(self):
        # Given
        user = BeneficiaryGrant18Factory()
        offer = OfferFactory()
        reason = Reason.INAPPROPRIATE.value

        # When
        send_report_notification(user, offer, reason, "blabla")

        # Then
        assert mails_testing.outbox[0].sent_data[
            "To"] == settings.REPORT_OFFER_EMAIL_ADDRESS
    def test_report_other(self):
        # Given
        user = BeneficiaryGrant18Factory()
        offer = OfferFactory()
        reason = Reason.OTHER.value

        # When
        send_report_notification(user, offer, reason, "blabla")

        # Then
        assert mails_testing.outbox[0].sent_data[
            "To"] == settings.SUPPORT_EMAIL_ADDRESS
Beispiel #16
0
    def when_user_is_created_without_postal_code(self, app):
        # Given
        BeneficiaryGrant18Factory(email="*****@*****.**",
                                  postalCode=None,
                                  departementCode=None)

        # When
        response = (TestClient(app.test_client()).with_session_auth(
            "*****@*****.**").get("/beneficiaries/current"))

        # Then
        assert response.status_code == 200
def test_get_bookings_categories_and_subcategories():
    user = BeneficiaryGrant18Factory()
    offer = OfferFactory(product__id=list(TRACKED_PRODUCT_IDS.keys())[0])

    assert _get_bookings_categories_and_subcategories(
        _get_user_bookings(user)) == ([], [])

    IndividualBookingFactory(individualBooking__user=user, stock__offer=offer)
    IndividualBookingFactory(individualBooking__user=user, stock__offer=offer)
    IndividualBookingFactory(individualBooking__user=user, isCancelled=True)

    assert _get_bookings_categories_and_subcategories(
        _get_user_bookings(user)) == (["FILM"], ["SUPPORT_PHYSIQUE_FILM"])
Beispiel #18
0
    def should_return_deposit_version(self, app):
        # Given
        BeneficiaryGrant18Factory(email="*****@*****.**",
                                  postalCode="93020",
                                  deposit__version=1)

        # When
        response = (TestClient(app.test_client()).with_session_auth(
            "*****@*****.**").get("/beneficiaries/current"))

        # Then

        assert response.json["deposit_version"] == 1
    def test_suspend_users_by_ids_does_not_cancel_bookings_when_not_cancellable(
            self):
        fraudulent_user_ids = [15]
        admin_user = AdminFactory()
        fraudulent_user = BeneficiaryGrant18Factory(id=15)
        uncancellable_booking = booking_factories.UsedIndividualBookingFactory(
            individualBooking__user=fraudulent_user, stock__price=1)

        suspend_fraudulent_beneficiary_users_by_ids(fraudulent_user_ids,
                                                    admin_user,
                                                    dry_run=False)

        assert not fraudulent_user.isActive
        assert not uncancellable_booking.isCancelled
        assert uncancellable_booking.status is not BookingStatus.CANCELLED
Beispiel #20
0
    def test_suspend_users_by_ids(self, client):
        admin_user = AdminFactory()
        fraudulent_user_1 = BeneficiaryGrant18Factory(id=5)
        fraudulent_user_2 = BeneficiaryGrant18Factory(id=16)
        booking_factories.IndividualBookingFactory(
            individualBooking__user=fraudulent_user_1)
        booking_factories.UsedIndividualBookingFactory(
            individualBooking__user=fraudulent_user_2)
        user_ids_csv = (io.BytesIO(b"user_id\n5\n16"), "user_ids.csv")
        files = {"user_ids_csv": user_ids_csv}
        headers = {"content-type": "multipart/form-data"}

        client = client.with_session_auth(admin_user.email)
        response = client.post(
            "/pc/back-office/suspend_fraud_users_by_user_ids",
            files=files,
            headers=headers)

        assert response.status_code == 200
        content = response.data.decode(response.charset)
        assert not fraudulent_user_2.isActive
        assert not fraudulent_user_1.isActive
        assert "Nombre d'utilisateurs suspendus : 2" in content
        assert "Nombre de réservations annulées : 1" in content
    def test_dont_suspend_users_not_in_given_emails_providers_list(self):
        # Given
        fraudulent_emails_providers = ["gmoil.com"]
        admin_user = AdminFactory()
        non_fraudulent_user = BeneficiaryGrant18Factory(
            email="*****@*****.**")
        booking_factories.IndividualBookingFactory(
            individualBooking__user=non_fraudulent_user, stock__price=1)

        # When
        suspend_fraudulent_beneficiary_users_by_email_providers(
            fraudulent_emails_providers, admin_user, dry_run=False)

        # Then
        assert non_fraudulent_user.isActive
    def test_does_not_cancel_booking_when_not_cancellable(self):
        # Given
        fraudulent_emails_providers = ["example.com"]
        admin_user = AdminFactory()
        fraudulent_user = BeneficiaryGrant18Factory(
            email="*****@*****.**")
        uncancellable_booking = booking_factories.UsedIndividualBookingFactory(
            individualBooking__user=fraudulent_user, stock__price=1)

        # When
        suspend_fraudulent_beneficiary_users_by_email_providers(
            fraudulent_emails_providers, admin_user, dry_run=False)

        # Then
        assert not fraudulent_user.isActive
        assert not uncancellable_booking.isCancelled
        assert uncancellable_booking.status is not BookingStatus.CANCELLED
Beispiel #23
0
def test_patch_beneficiary_survey_related_attributes(app):
    user = BeneficiaryGrant18Factory()

    client = TestClient(app.test_client()).with_session_auth(email=user.email)
    survey_id = uuid.uuid4()
    data = {
        "needsToFillCulturalSurvey": False,
        "culturalSurveyId": str(survey_id),
        "culturalSurveyFilledDate": "2021-01-01T12:00:00Z",
    }
    response = client.patch("/beneficiaries/current", json=data)

    assert response.status_code == 200
    assert not user.needsToFillCulturalSurvey
    assert user.culturalSurveyId == survey_id
    assert user.culturalSurveyFilledDate == datetime.datetime(
        2021, 1, 1, 12, 0)
Beispiel #24
0
    def when_user_is_logged_in_and_has_a_deposit(self, app):
        # Given
        BeneficiaryGrant18Factory(
            email="*****@*****.**",
            postalCode="93020",
            deposit__dateCreated=datetime(2000, 1, 1, 2, 2),
            deposit__expirationDate=datetime(2002, 1, 1, 2, 2),
        )

        # When
        response = (TestClient(app.test_client()).with_session_auth(
            "*****@*****.**").get("/beneficiaries/current"))

        # Then
        assert response.json["wallet_is_activated"] == True
        assert response.json[
            "deposit_expiration_date"] == "2002-01-01T02:02:00Z"
def test_update_external_user():
    user = BeneficiaryGrant18Factory()
    IndividualBookingFactory(individualBooking__user=user)

    n_query_get_user = 1
    n_query_get_bookings = 1
    n_query_get_deposit = 1
    n_query_is_pro = 1
    n_query_get_last_favorite = 1

    with assert_num_queries(n_query_get_user + n_query_get_bookings +
                            n_query_get_deposit + n_query_is_pro +
                            n_query_get_last_favorite):
        update_external_user(user)

    assert len(batch_testing.requests) == 1
    assert len(sendinblue_testing.sendinblue_requests) == 1
Beispiel #26
0
    def when_user_is_logged_in_and_has_no_deposit(self, app):
        # Given
        user = BeneficiaryGrant18Factory(
            email="*****@*****.**",
            postalCode="93020",
        )
        repository.delete(*user.deposits)

        # When
        response = (TestClient(app.test_client()).with_session_auth(
            email="*****@*****.**").get("/beneficiaries/current"))

        # Then
        assert response.status_code == 200
        assert response.json == {
            "activity": user.activity,
            "address": user.address,
            "city": user.city,
            "civility": user.civility,
            "dateCreated": format_into_utc_date(user.dateCreated),
            "dateOfBirth": format_into_utc_date(user.dateOfBirth),
            "departementCode": user.departementCode,
            "deposit_expiration_date": None,
            "deposit_version": None,
            "domainsCredit": None,
            "email": "*****@*****.**",
            "firstName": user.firstName,
            "hasPhysicalVenues": user.hasPhysicalVenues,
            "id": humanize(user.id),
            "isActive": True,
            "isAdmin": False,
            "isBeneficiary": True,
            "isEmailValidated": True,
            "lastName": user.lastName,
            "needsToFillCulturalSurvey": True,
            "needsToSeeTutorials": True,
            "pk": user.id,
            "phoneNumber": user.phoneNumber,
            "postalCode": user.postalCode,
            "publicName": user.publicName,
            "roles": ["BENEFICIARY"],
            "suspensionReason": "",
            "wallet_balance": 0.0,
            "wallet_is_activated": False,
        }
    def test_suspend_users_by_ids_in_given_user_ids_list(self):
        fraudulent_user_ids = [23]
        admin_user = AdminFactory()
        fraudulent_user = BeneficiaryGrant18Factory(id=23)
        fraudulent_user_booking_1 = booking_factories.IndividualBookingFactory(
            individualBooking__user=fraudulent_user, stock__price=1)
        fraudulent_user_booking_2 = booking_factories.IndividualBookingFactory(
            individualBooking__user=fraudulent_user, stock__price=2)

        suspend_fraudulent_beneficiary_users_by_ids(fraudulent_user_ids,
                                                    admin_user,
                                                    dry_run=False)

        assert not fraudulent_user.isActive
        assert fraudulent_user_booking_1.isCancelled
        assert fraudulent_user_booking_1.status is BookingStatus.CANCELLED
        assert fraudulent_user_booking_2.isCancelled
        assert fraudulent_user_booking_2.status is BookingStatus.CANCELLED
Beispiel #28
0
    def test_should_not_return_activation_bookings(self, app):
        # Given
        beneficiary = BeneficiaryGrant18Factory()
        offer1 = EventOfferFactory(subcategoryId=subcategories.ACTIVATION_THING.id)
        offer2 = EventOfferFactory(subcategoryId=subcategories.ACTIVATION_THING.id)
        offer3 = EventOfferFactory(subcategoryId=subcategories.SUPPORT_PHYSIQUE_FILM.id)
        stock1 = EventStockFactory(offer=offer1)
        stock2 = EventStockFactory(offer=offer2)
        stock3 = EventStockFactory(offer=offer3)
        booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary, stock=stock1)
        booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary, stock=stock2)
        booking3 = booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary, stock=stock3)

        # When
        result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary.id)

        # Then
        assert len(result.bookings) == 1
        assert result.bookings[0].id == booking3.id
    def test_build_soon_to_be_expired_bookings_data(self, app):
        # Given
        beneficiary = BeneficiaryGrant18Factory(email="*****@*****.**",
                                                firstName="ASIMOV")
        bookings = [
            BookingFactory(
                stock__offer__name="offre 1",
                stock__offer__venue__name="venue 1",
            ),
            BookingFactory(
                stock__offer__name="offre 2",
                stock__offer__venue__name="venue 2",
            ),
        ]

        # When
        data = build_soon_to_be_expired_bookings_recap_email_data_for_beneficiary(
            beneficiary, bookings, days_before_cancel=7, days_from_booking=23)

        # Then
        assert data == {
            "Mj-TemplateID": 3095065,
            "Mj-TemplateLanguage": True,
            "Vars": {
                "user_firstName":
                "ASIMOV",
                "bookings": [
                    {
                        "offer_name": "offre 1",
                        "venue_name": "venue 1"
                    },
                    {
                        "offer_name": "offre 2",
                        "venue_name": "venue 2"
                    },
                ],
                "days_before_cancel":
                7,
                "days_from_booking":
                23,
            },
        }
Beispiel #30
0
    def test_should_return_beneficiary_bookings_with_expected_information(self, app):
        # Given
        beneficiary = BeneficiaryGrant18Factory()
        offer = ThingOfferFactory(isActive=True, url="http://url.com", product__thumbCount=1)
        stock = ThingStockFactory(offer=offer, price=0, quantity=10)
        booking = booking_factories.UsedIndividualBookingFactory(
            individualBooking__user=beneficiary,
            stock=stock,
            token="ABCDEF",
            dateCreated=datetime(2020, 4, 22, 0, 0),
            dateUsed=datetime(2020, 5, 5, 0, 0),
            quantity=2,
        )

        # When
        result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary.id)

        # Then
        assert isinstance(result, BeneficiaryBookingsWithStocks)
        assert len(result.bookings) == 1
        expected_booking = result.bookings[0]
        assert expected_booking.amount == 0.0
        assert expected_booking.cancellationDate is None
        assert expected_booking.dateCreated == datetime(2020, 4, 22, 0, 0)
        assert expected_booking.dateUsed == datetime(2020, 5, 5, 0, 0)
        assert expected_booking.id == booking.id
        assert expected_booking.isCancelled is False
        assert expected_booking.isUsed is True
        assert expected_booking.quantity == 2
        assert expected_booking.stockId == stock.id
        assert expected_booking.token == booking.token
        assert expected_booking.userId == beneficiary.id
        assert expected_booking.offerId == stock.offer.id
        assert expected_booking.name == stock.offer.name
        assert expected_booking.url == stock.offer.url
        assert expected_booking.email == beneficiary.email
        assert expected_booking.beginningDatetime == stock.beginningDatetime
        assert expected_booking.venueId == stock.offer.venue.id
        assert expected_booking.departementCode == stock.offer.venue.departementCode
        assert (
            expected_booking.thumb_url == f"http://localhost/storage/thumbs/products/{humanize(stock.offer.productId)}"
        )