def test_should_change_pro_users_to_beneficiary(app):
    # given
    offerer_1 = create_offerer(siren="987654321")
    offerer_2 = create_offerer(siren="567890342")
    offerer_3 = create_offerer(siren="345987987")
    AGE18_ELIGIBLE_BIRTH_DATE = datetime.now() - relativedelta(years=18, months=4)
    pro_1 = users_factories.ProFactory(
        dateOfBirth=AGE18_ELIGIBLE_BIRTH_DATE, email="*****@*****.**", needsToFillCulturalSurvey=False
    )
    pro_2 = users_factories.ProFactory(dateOfBirth=AGE18_ELIGIBLE_BIRTH_DATE, email="*****@*****.**")
    pro_3 = users_factories.ProFactory(dateOfBirth=AGE18_ELIGIBLE_BIRTH_DATE, email="*****@*****.**")
    user_offerer_1 = create_user_offerer(pro_1, offerer_1)
    user_offerer_2 = create_user_offerer(pro_1, offerer_2)
    user_offerer_3 = create_user_offerer(pro_3, offerer_3)
    repository.save(user_offerer_1, user_offerer_2, user_offerer_3)
    pro_users_list_to_change = [pro_1.id, pro_2.id]

    # when
    change_pro_users_to_beneficiary(pro_users_list_to_change)

    # then
    assert pro_1.has_beneficiary_role
    assert pro_1.has_beneficiary_role
    assert not pro_1.has_pro_role
    assert pro_1.needsToFillCulturalSurvey
    assert pro_1.wallet_balance == 300
    assert pro_2.has_beneficiary_role
    assert pro_2.has_beneficiary_role
    assert not pro_2.has_pro_role
    assert pro_2.needsToFillCulturalSurvey
    assert pro_2.wallet_balance == 300
    assert UserOfferer.query.count() == 1
    def test_should_return_all_user_emails(self, app):
        # Given
        first_day_after_quarantine = datetime(2020, 4, 16)
        today = datetime(2020, 4, 10)
        tomorrow = today + timedelta(days=1)

        pro = users_factories.ProFactory(email="*****@*****.**")
        pro1 = users_factories.ProFactory(email="*****@*****.**")

        offerer = create_offerer(siren="123456789")
        user_offerer = create_user_offerer(user=pro, offerer=offerer)
        venue = create_venue(offerer, siret="1234567899876")
        offer = create_offer_with_event_product(venue)
        stock = create_stock(beginning_datetime=tomorrow, offer=offer)

        offerer1 = create_offerer(siren="987654321")
        user_offerer1 = create_user_offerer(user=pro1, offerer=offerer1)
        venue1 = create_venue(offerer1, siret="9876543216543")
        offer1 = create_offer_with_event_product(venue1)
        stock1 = create_stock(beginning_datetime=tomorrow, offer=offer1)

        repository.save(stock1, stock, user_offerer, user_offerer1)

        # When
        pro_emails = fetch_user_emails_for_offers_with_max_stock_date_between_today_and_end_of_quarantine(
            first_day_after_quarantine, today)

        # Then
        assert len(pro_emails) == 2
        assert set(pro_emails) == {
            "*****@*****.**", "*****@*****.**"
        }
Ejemplo n.º 3
0
    def test_should_return_false_when_current_user_has_no_access(self, app):
        # Given
        current_user = users_factories.ProFactory(email="*****@*****.**", postalCode=None)
        user = users_factories.ProFactory(postalCode=None)
        offerer = create_offerer()
        user_offerer = create_user_offerer(user, offerer, validation_token=None)
        repository.save(user_offerer)

        # When
        offerer.append_user_has_access_attribute(user_id=current_user.id, is_admin=current_user.isAdmin)

        # Then
        assert offerer.userHasAccess is False
Ejemplo n.º 4
0
    def test_approve_last_pending_offer_and_go_to_the_next_offer_redirect_to_validation_page(
        self, mocked_get_offerer_legal_category, mocked_validate_csrf_token, app
    ):
        users_factories.AdminFactory(email="*****@*****.**")
        venue = VenueFactory()
        offerer = venue.managingOfferer

        pro_user = users_factories.ProFactory(email="*****@*****.**")
        offers_factories.UserOffererFactory(user=pro_user, offerer=offerer)

        offer = offers_factories.OfferFactory(
            validation=OfferValidationStatus.PENDING,
            isActive=True,
            venue__bookingEmail="*****@*****.**",
            venue=venue,
        )

        mocked_get_offerer_legal_category.return_value = {
            "legal_category_code": 5202,
            "legal_category_label": "Société en nom collectif",
        }

        data = dict(validation=OfferValidationStatus.APPROVED.value, action="save-and-go-next")
        client = TestClient(app.test_client()).with_session_auth("*****@*****.**")
        response = client.post(f"/pc/back-office/validation/edit?id={offer.id}", form=data)

        assert offer.validation == OfferValidationStatus.APPROVED
        assert response.status_code == 302
        assert response.headers["location"] == "http://localhost/pc/back-office/validation/"
Ejemplo n.º 5
0
    def test_approve_virtual_offer_and_send_mail_to_managing_offerer(
        self,
        mocked_send_offer_validation_status_update_email,
        mocked_get_offerer_legal_category,
        mocked_validate_csrf_token,
        app,
    ):
        # Given
        users_factories.AdminFactory(email="*****@*****.**")

        venue = VenueFactory()
        offerer = venue.managingOfferer
        pro_user = users_factories.ProFactory(email="*****@*****.**")
        offers_factories.UserOffererFactory(user=pro_user, offerer=offerer)

        offer = offers_factories.OfferFactory(validation=OfferValidationStatus.PENDING, isActive=True, venue=venue)

        mocked_get_offerer_legal_category.return_value = {
            "legal_category_code": 5202,
            "legal_category_label": "Société en nom collectif",
        }
        data = dict(validation=OfferValidationStatus.APPROVED.value, action="save-and-go-next")
        client = TestClient(app.test_client()).with_session_auth("*****@*****.**")

        # When
        client.post(f"/pc/back-office/validation/edit?id={offer.id}", form=data)

        # Then
        mocked_send_offer_validation_status_update_email.assert_called_once_with(
            offer, OfferValidationStatus.APPROVED, ["*****@*****.**"]
        )
    def test_get_list_with_valid_venue_id(self, app):
        # given
        user = users_factories.ProFactory()
        titelive_things_provider = get_provider_by_local_class("TiteLiveThings")
        venue_provider = offerers_factories.VenueProviderFactory(
            venue__name="Librairie Titelive", provider=titelive_things_provider, lastSyncDate=datetime(2021, 8, 16)
        )

        # test that nOffers only containe active offers
        offers_factories.OfferFactory(
            venue=venue_provider.venue,
            lastProviderId=venue_provider.provider.id,
            idAtProviders="testIdAtProviders1",
            isActive=True,
        )
        offers_factories.OfferFactory(
            venue=venue_provider.venue,
            lastProviderId=venue_provider.provider.id,
            idAtProviders="testIdAtProviders2",
            isActive=False,
        )

        # when
        auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)
        response = auth_request.get("/venueProviders?venueId=" + humanize(venue_provider.venue.id))

        # then
        assert response.status_code == 200
        assert response.json["venue_providers"][0].get("nOffers") == 1
        assert response.json["venue_providers"][0].get("id") == humanize(venue_provider.id)
        assert response.json["venue_providers"][0].get("venueId") == humanize(venue_provider.venue.id)
        assert response.json["venue_providers"][0].get("lastSyncDate") == "2021-08-16T00:00:00Z"
Ejemplo n.º 7
0
    def test_when_booking_is_educational_and_refused_by_principal(self, client):
        # Given
        redactor = educational_factories.EducationalRedactorFactory(
            civility="M.",
            firstName="Jean",
            lastName="Doudou",
            email="*****@*****.**",
        )
        refused_eac_booking = bookings_factories.EducationalBookingFactory(
            dateCreated=datetime.utcnow() - timedelta(days=5),
            educationalBooking__educationalRedactor=redactor,
            educationalBooking__status=EducationalBookingStatus.REFUSED,
        )
        pro_user = users_factories.ProFactory()
        offers_factories.UserOffererFactory(user=pro_user, offerer=refused_eac_booking.offerer)
        url = f"/v2/bookings/token/{refused_eac_booking.token}"

        # When
        response = client.with_basic_auth(pro_user.email).get(url)

        # Then
        assert response.status_code == 403
        assert (
            response.json["educationalBooking"]
            == "Cette réservation pour une offre éducationnelle a été refusée par le chef d'établissement"
        )
Ejemplo n.º 8
0
    def when_user_has_no_rights_and_creating_stock_from_offer_id(
            self, app, db_session):
        # Given
        user = users_factories.ProFactory(email="*****@*****.**")
        offer = offers_factories.ThingOfferFactory()
        offers_factories.UserOffererFactory(
            user__email="*****@*****.**",
            offerer=offer.venue.managingOfferer)
        booking_datetime = datetime.utcnow()

        # When
        stock_data = {
            "offerId":
            humanize(offer.id),
            "stocks": [
                {
                    "quantity": 10,
                    "price": 0,
                    "bookingLimitDatetime": serialize(booking_datetime),
                },
            ],
        }
        response = TestClient(app.test_client()).with_session_auth(
            user.email).post("/stocks/bulk/", json=stock_data)

        # Then
        assert response.status_code == 403
        assert response.json == {
            "global": [
                "Vous n'avez pas les droits d'accès suffisant pour accéder à cette information."
            ]
        }
Ejemplo n.º 9
0
    def test_get_eligible_users_created_between(self, app):
        ELIGIBLE_CONDTIONS = {
            "dateCreated": datetime.now(),
            "postalCode": "93000",
            "isBeneficiary": False,
        }
        # 19 yo
        factories.UserFactory(dateOfBirth=datetime(1999, 1, 1), **ELIGIBLE_CONDTIONS)
        user_just_18_in_eligible_area = factories.UserFactory(dateOfBirth=datetime(2000, 1, 1), **ELIGIBLE_CONDTIONS)
        # User just 18 but in an ineligible area
        factories.UserFactory(
            dateOfBirth=datetime(2000, 1, 1),
            dateCreated=datetime.now(),
            postalCode="98712",
        )
        # Beneficiary
        factories.BeneficiaryGrant18Factory(
            dateOfBirth=datetime(2000, 1, 1),
            dateCreated=datetime.now(),
            postalCode="93000",
        )
        # Admin
        factories.AdminFactory(dateOfBirth=datetime(2000, 1, 1), **ELIGIBLE_CONDTIONS)
        # Pro
        pro_user = factories.ProFactory(dateOfBirth=datetime(2000, 1, 1), **ELIGIBLE_CONDTIONS)
        offers_factories.UserOffererFactory(user=pro_user)
        # User not yet 18
        factories.UserFactory(dateOfBirth=datetime(2000, 1, 2), **ELIGIBLE_CONDTIONS)

        result = _get_eligible_users_created_between(
            datetime.now() - timedelta(days=1), datetime.now() + timedelta(minutes=1)
        )

        assert {u.id for u in result} == {user_just_18_in_eligible_area.id}
    def should_return_linked_offerers_with_matching_keywords_in_venue_name(self, app):
        # Given
        pro = users_factories.ProFactory()
        offerer1 = create_offerer(name="Theatre")
        offerer2 = create_offerer(name="Cinema", siren="912345678")
        venue1 = create_venue(name="Les fleurs", offerer=offerer1, siret=None, is_virtual=True)
        venue2 = create_venue(name="Les jardins du vide", offerer=offerer2, siret=None, is_virtual=True)
        user_offerer1 = create_user_offerer(user=pro, offerer=offerer1)
        user_offerer2 = create_user_offerer(user=pro, offerer=offerer2)
        repository.save(user_offerer1, user_offerer2, venue1, venue2)

        # When
        paginated_offerers = PaginatedOfferersSQLRepository().with_status_and_keywords(
            user_id=pro.id,
            user_is_admin=pro.isAdmin,
            is_filtered_by_offerer_status=False,
            only_validated_offerers=None,
            pagination_limit=10,
            keywords="jardins",
            page=0,
        )

        # Then
        assert isinstance(paginated_offerers, PaginatedOfferers)
        assert paginated_offerers.total == 1
        assert len(paginated_offerers.offerers) == 1
def test_filter_query_where_user_is_user_offerer_and_is_validated(app):
    # Given
    pro = users_factories.ProFactory(email="*****@*****.**")
    offerer1 = create_offerer(siren="123456789")
    offerer2 = create_offerer(siren="987654321")
    offerer3 = create_offerer(siren="123456780")
    user_offerer1 = create_user_offerer(pro, offerer1)
    user_offerer2 = create_user_offerer(pro, offerer2)

    event1 = create_product_with_event_subcategory(event_name="Rencontre avec Jacques Martin")
    event2 = create_product_with_event_subcategory(event_name="Concert de contrebasse")
    thing1 = create_product_with_thing_subcategory(thing_name="Jacques la fripouille")
    thing2 = create_product_with_thing_subcategory(thing_name="Belle du Seigneur")
    venue1 = create_venue(offerer1, name="Bataclan", city="Paris", siret=offerer1.siren + "12345")
    venue2 = create_venue(offerer2, name="Librairie la Rencontre", city="Saint Denis", siret=offerer2.siren + "54321")
    venue3 = create_venue(
        offerer3, name="Une librairie du méchant concurrent gripsou", city="Saint Denis", siret=offerer3.siren + "54321"
    )
    offer1 = create_offer_with_event_product(venue=venue1, product=event1)
    offer2 = create_offer_with_event_product(venue=venue1, product=event2)
    offer3 = create_offer_with_thing_product(venue=venue2, product=thing1)
    offer4 = create_offer_with_thing_product(venue=venue3, product=thing2)

    repository.save(user_offerer1, user_offerer2, offerer3, offer1, offer2, offer3, offer4)

    # When
    offers = filter_query_where_user_is_user_offerer_and_is_validated(Offer.query.join(Venue).join(Offerer), pro).all()

    # Then
    offer_ids = [offer.id for offer in offers]
    assert offer1.id in offer_ids
    assert offer2.id in offer_ids
    assert offer3.id in offer_ids
    assert offer4.id not in offer_ids
Ejemplo n.º 12
0
def create_industrial_pro_users(offerers_by_name: dict) -> dict:
    logger.info("create_industrial_pro_users")

    users_by_name = {}

    offerers = list(offerers_by_name.values())

    for index, departement_code in enumerate(departement_codes):

        for pro_count in range(PROS_COUNT):
            email = "pctest.pro{}.{}@example.com".format(departement_code, pro_count)
            user = users_factories.ProFactory(
                dateOfBirth=None,
                departementCode=str(departement_code),
                email=email,
                firstName="PC Test Pro",
                lastName="{} {}".format(departement_code, pro_count),
                postalCode="{}100".format(departement_code),
                publicName="PC Test Pro {} {}".format(departement_code, pro_count),
            )
            users_by_name["pro{} {}".format(departement_code, pro_count)] = user
            UserOffererFactory(offerer=offerers[index], user=user)

    repository.save(*users_by_name.values())

    logger.info("created %d users", len(users_by_name))

    return users_by_name
def test_with_user_linked_to_offerers(app):
    offerer1 = offers_factories.OffererFactory()
    offerer2 = offers_factories.OffererFactory(siren="123456788")
    venue1 = offers_factories.VenueFactory(managingOfferer=offerer1)
    venue2 = offers_factories.VenueFactory(managingOfferer=offerer1)
    venue3 = offers_factories.VenueFactory(managingOfferer=offerer1)
    venue4 = offers_factories.VenueFactory(managingOfferer=offerer2)
    for venue in (venue1, venue2, venue3, venue4):
        payments_factories.PaymentFactory(
            booking__stock__offer__venue=venue,
            transactionLabel=
            "pass Culture Pro - remboursement 1ère quinzaine 06-21")
    pro = users_factories.ProFactory(offerers=[offerer1, offerer2])

    # When
    client = TestClient(app.test_client()).with_session_auth(pro.email)
    response = client.get("/reimbursements/csv")

    # Then
    assert response.status_code == 200
    assert response.headers["Content-type"] == "text/csv; charset=utf-8;"
    assert response.headers[
        "Content-Disposition"] == "attachment; filename=remboursements_pass_culture.csv"
    rows = response.data.decode("utf-8").splitlines()
    assert len(rows) == 1 + 4  # header + payments
Ejemplo n.º 14
0
def test_invalid_offerer_id(mock_get_filtered_venues, app):
    pro_user = users_factories.ProFactory(email="*****@*****.**")
    offerer = offers_factories.OffererFactory()
    offers_factories.UserOffererFactory(user=pro_user, offerer=offerer)
    offers_factories.VenueFactory(managingOfferer=offerer)

    query_params = [
        f"offererId={humanize(666)}",
    ]

    # when
    response = TestClient(app.test_client()).with_session_auth(pro_user.email).get(f"/venues?{'&'.join(query_params)}")

    # then
    # then
    assert response.status_code == 200
    mock_get_filtered_venues.assert_called_once_with(
        active_offerers_only=None,
        offerer_id=666,
        pro_user_id=pro_user.id,
        user_is_admin=False,
        validated_offerer=None,
        validated_offerer_for_user=None,
    )

    assert "venues" in response.json
    assert len(response.json["venues"]) == 0
Ejemplo n.º 15
0
def test_full_valid_call_with_false(mock_get_filtered_venues, app):
    pro_user = users_factories.ProFactory(email="*****@*****.**")
    offerer = offers_factories.OffererFactory()
    offers_factories.UserOffererFactory(user=pro_user, offerer=offerer)

    query_params = [
        "validated=false",
        "validatedForUser=false",
        f"offererId={humanize(offerer.id)}",
        "activeOfferersOnly=false",
    ]

    # when
    response = TestClient(app.test_client()).with_session_auth(pro_user.email).get(f"/venues?{'&'.join(query_params)}")

    # then
    assert response.status_code == 200
    mock_get_filtered_venues.assert_called_once_with(
        active_offerers_only=False,
        offerer_id=offerer.id,
        pro_user_id=pro_user.id,
        user_is_admin=False,
        validated_offerer=False,
        validated_offerer_for_user=False,
    )
    def should_filter_offers_by_given_offerer_id(self, mocked_list_offers, app, db_session):
        # given
        pro = users_factories.ProFactory()
        offerer = offers_factories.OffererFactory()
        offers_factories.UserOffererFactory(user=pro, offerer=offerer)
        offers_factories.VenueFactory(managingOfferer=offerer)

        # when
        response = (
            TestClient(app.test_client())
            .with_session_auth(email=pro.email)
            .get("/offers?offererId=" + humanize(offerer.id))
        )

        # then
        assert response.status_code == 200
        mocked_list_offers.assert_called_once_with(
            user_id=pro.id,
            user_is_admin=pro.isAdmin,
            offerer_id=offerer.id,
            venue_id=None,
            category_id=None,
            name_keywords_or_isbn=None,
            period_beginning_date=None,
            period_ending_date=None,
            status=None,
            creation_mode=None,
        )
    def test_results_are_filtered_by_given_period_ending_date(self, mocked_list_offers, app, db_session):
        # given
        pro = users_factories.ProFactory()
        offerer = offers_factories.OffererFactory()
        offers_factories.UserOffererFactory(user=pro, offerer=offerer)

        # when
        response = (
            TestClient(app.test_client())
            .with_session_auth(email=pro.email)
            .get("/offers?periodEndingDate=2020-10-11T23:59:59Z")
        )

        # then
        assert response.status_code == 200
        mocked_list_offers.assert_called_once_with(
            user_id=pro.id,
            user_is_admin=pro.isAdmin,
            offerer_id=None,
            venue_id=None,
            category_id=None,
            name_keywords_or_isbn=None,
            period_beginning_date=None,
            period_ending_date="2020-10-11T23:59:59Z",
            status=None,
            creation_mode=None,
        )
    def test_user_has_right_on_venue(self, app):
        # Given
        user = user_factories.ProFactory()
        owner_offerer = offer_factories.UserOffererFactory()
        offerer = owner_offerer.offerer
        venue = offer_factories.VenueFactory(managingOfferer=offerer)
        provider = offerers_factories.AllocineProviderFactory()
        venue_provider = offerers_factories.AllocineVenueProviderFactory(
            venue=venue,
            provider=provider,
            isDuo=False,
            quantity=42,
        )
        offerers_factories.AllocineVenueProviderPriceRuleFactory(allocineVenueProvider=venue_provider, price=10)

        updated_venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "isDuo": True,
            "quantity": 77,
            "price": 64,
        }

        auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)

        # When
        response = auth_request.put("/venueProviders", json=updated_venue_provider_data)

        # Then
        assert response.status_code == 403
    def should_filter_out_non_validated_offerers(self, app):
        # Given
        pro = users_factories.ProFactory()
        offerer1 = create_offerer(validation_token="RTYUIO")
        offerer2 = create_offerer(siren="987654310")
        user_offerer1 = create_user_offerer(user=pro, offerer=offerer1)
        user_offerer2 = create_user_offerer(user=pro, offerer=offerer2)
        repository.save(user_offerer1, user_offerer2)

        # When
        paginated_offerers = PaginatedOfferersSQLRepository().with_status_and_keywords(
            user_id=pro.id,
            user_is_admin=pro.isAdmin,
            is_filtered_by_offerer_status=True,
            only_validated_offerers=True,
            pagination_limit=10,
            keywords=None,
            page=0,
        )

        # Then
        assert isinstance(paginated_offerers, PaginatedOfferers)
        assert paginated_offerers.total == 1
        assert len(paginated_offerers.offerers) == 1
        assert paginated_offerers.offerers[0].id == offerer2.id
    def when_requested_booking_period_dates_are_iso_format(self, app):
        booking_date = datetime(2020, 8, 12, 20, 00, tzinfo=timezone.utc)
        booking_period_beginning_date_iso = "2020-08-10"
        booking_period_ending_date_iso = "2020-08-12"
        booking = bookings_factories.BookingFactory(dateCreated=booking_date, token="AAAAAA")
        bookings_factories.BookingFactory(token="BBBBBB")
        pro_user = users_factories.ProFactory(email="*****@*****.**")
        offers_factories.UserOffererFactory(user=pro_user, offerer=booking.offerer)

        client = TestClient(app.test_client()).with_session_auth(pro_user.email)
        with assert_num_queries(
            testing.AUTHENTICATION_QUERIES
            + 2
            + 1  # TODO: query for feature flag, to be removed when IMPROVE_BOOKINGS_PERF is definitely adopted
        ):
            response = client.get(
                "/bookings/pro?bookingPeriodBeginningDate=%s&bookingPeriodEndingDate=%s"
                % (booking_period_beginning_date_iso, booking_period_ending_date_iso)
            )

        assert response.status_code == 200
        assert len(response.json["bookings_recap"]) == 1
        assert response.json["bookings_recap"][0]["booking_date"] == datetime.isoformat(
            utc_datetime_to_department_timezone(booking.dateCreated, booking.venue.departementCode)
        )
        assert response.json["page"] == 1
        assert response.json["pages"] == 1
        assert response.json["total"] == 1
def test_with_venue_filter(app):
    beginning_date_iso_format = (date.today() - timedelta(days=2)).isoformat()
    ending_date_iso_format = (date.today() + timedelta(days=2)).isoformat()
    offerer = offers_factories.OffererFactory()
    venue1 = offers_factories.VenueFactory(managingOfferer=offerer)
    venue2 = offers_factories.VenueFactory(managingOfferer=offerer)
    for venue in (venue1, venue2):
        payments_factories.PaymentStatusFactory(
            payment__booking__stock__offer__venue=venue,
            status=TransactionStatus.SENT,
            payment__transactionLabel=
            "pass Culture Pro - remboursement 1ère quinzaine 06-21",
        )
    pro = users_factories.ProFactory(offerers=[offerer])

    # When
    client = TestClient(app.test_client()).with_session_auth(pro.email)
    response = client.get(
        f"/reimbursements/csv?reimbursementPeriodBeginningDate={beginning_date_iso_format}&reimbursementPeriodEndingDate={ending_date_iso_format}&venueId={humanize(venue1.id)}"
    )

    # Then
    assert response.status_code == 200
    assert response.headers["Content-type"] == "text/csv; charset=utf-8;"
    assert response.headers[
        "Content-Disposition"] == "attachment; filename=remboursements_pass_culture.csv"
    rows = response.data.decode("utf-8").splitlines()
    assert len(rows) == 1 + 1  # header + payments
        def test_when_user_is_logged_in_and_offer_is_educational_but_has_been_refused_by_institution(
                self, client):
            # Given
            booking = bookings_factories.EducationalBookingFactory(
                token="ABCDEF",
                dateCreated=datetime.datetime.utcnow() -
                datetime.timedelta(days=3),
                educationalBooking__status=EducationalBookingStatus.REFUSED,
            )
            pro_user = users_factories.ProFactory(email="*****@*****.**")
            offers_factories.UserOffererFactory(user=pro_user,
                                                offerer=booking.offerer)

            # When
            url = f"/v2/bookings/use/token/{booking.token}"
            response = client.with_session_auth("*****@*****.**").patch(url)

            # Then
            assert response.status_code == 403
            assert (
                response.json["educationalBooking"] ==
                "Cette réservation pour une offre éducationnelle a été refusée par le chef d'établissement"
            )
            booking = Booking.query.get(booking.id)
            assert booking.isUsed is False
            assert booking.status is not BookingStatus.USED
 def test_unknown_token(self, client):
     pro_user = users_factories.ProFactory()
     response = client.with_basic_auth(
         pro_user.email).patch("/v2/bookings/use/token/UNKNOWN")
     assert response.status_code == 404
     assert response.json["global"] == [
         "Cette contremarque n'a pas été trouvée"
     ]
Ejemplo n.º 24
0
 def when_the_booking_does_not_exists(self, client):
     user = users_factories.ProFactory()
     url = "/v2/bookings/cancel/token/FAKETOKEN"
     response = client.with_basic_auth(user.email).patch(url)
     assert response.status_code == 404
     assert response.json["global"] == [
         "Cette contremarque n'a pas été trouvée"
     ]
Ejemplo n.º 25
0
    def test_returns_pro_users_with_matching_email_provider(self):
        pro_user_with_matching_email = users_factories.ProFactory(
            email="*****@*****.**", isActive=True)
        offerer = offers_factories.OffererFactory()
        offers_factories.UserOffererFactory(user=pro_user_with_matching_email,
                                            offerer=offerer)

        pro_user_with_not_matching_email = users_factories.ProFactory(
            email="*****@*****.**", isActive=True)
        offerer2 = offers_factories.OffererFactory()
        offers_factories.UserOffererFactory(
            user=pro_user_with_not_matching_email, offerer=offerer2)

        users = find_pro_users_by_email_provider("suspect.com")

        assert len(users) == 1
        assert users[0] == pro_user_with_matching_email
    def test_find_existing_email(self):
        offerer = offerers_factories.OffererFactory()
        pro_user = users_factories.ProFactory()
        offers_factories.UserOffererFactory(offerer=offerer, user=pro_user)

        result = find_new_offerer_user_email(offerer.id)

        assert result == pro_user.email
    def when_page_number_is_not_a_number(self, app):
        pro = users_factories.ProFactory()

        client = TestClient(app.test_client()).with_session_auth(pro.email)
        response = client.get("/bookings/pro?page=not-a-number")

        assert response.status_code == 400
        assert response.json["page"] == ["Saisissez un nombre valide"]
Ejemplo n.º 28
0
    def when_offerer_id_does_not_exist(self, app):
        # given
        user1 = users_factories.ProFactory(email="*****@*****.**")
        user2 = users_factories.ProFactory(email="*****@*****.**")
        offerer = create_offerer(siren="123456781")
        user_offerer1 = create_user_offerer(user1, offerer)
        user_offerer2 = create_user_offerer(user2, offerer)
        repository.save(user_offerer1, user_offerer2)
        non_existing_offerer_id = "B9"

        # when
        response = (TestClient(app.test_client()).with_session_auth(
            email=user1.email).get("/userOfferers/" + non_existing_offerer_id))

        # then
        assert response.status_code == 200
        assert response.json == []
    def when_booking_period_is_not_given(self, app):
        pro = users_factories.ProFactory()

        client = TestClient(app.test_client()).with_session_auth(pro.email)
        response = client.get("/bookings/pro")

        assert response.status_code == 400
        assert response.json["bookingPeriodBeginningDate"] == ["Ce champ est obligatoire"]
        assert response.json["bookingPeriodEndingDate"] == ["Ce champ est obligatoire"]
Ejemplo n.º 30
0
    def test_empty_return_value(self, app):
        # given
        pro_user = users_factories.ProFactory(email="*****@*****.**")

        # when
        venue_list = offerers_repository.get_filtered_venues(
            pro_user_id=pro_user.id, user_is_admin=False)

        # then
        assert len(venue_list) == 0