def when_mediation_is_edited(self, app): # given mediation = offers_factories.MediationFactory() offerer = mediation.offer.venue.managingOfferer offers_factories.UserOffererFactory( user__email="*****@*****.**", offerer=offerer, ) # when client = TestClient(app.test_client()).with_auth(email="*****@*****.**") data = {"isActive": False} response = client.patch(f"/mediations/{humanize(mediation.id)}", json=data) # then mediation = Mediation.query.one() assert not mediation.isActive assert response.status_code == 200 assert response.json["id"] == humanize(mediation.id) assert response.json["thumbUrl"] == mediation.thumbUrl assert response.json == { "authorId": None, "credit": None, "dateCreated": format_into_utc_date(mediation.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(mediation.dateModifiedAtLastProvider), "fieldsUpdated": [], "id": humanize(mediation.id), "idAtProviders": None, "isActive": data["isActive"], "lastProviderId": None, "offerId": humanize(mediation.offer.id), "thumbCount": 0, "thumbUrl": None, }
def when_user_is_logged_in_and_has_no_deposit(self, app): with freeze_time(datetime.datetime.utcnow() - relativedelta(years=3)): user = users_factories.BeneficiaryGrant18Factory( civility="M.", address=None, city=None, needsToFillCulturalSurvey=False, departementCode="93", email="*****@*****.**", firstName="Jean", lastName="Smisse", dateOfBirth=datetime.datetime.utcnow() - relativedelta(years=18), phoneNumber="0612345678", postalCode="93020", publicName="Toto", isEmailValidated=True, ) # When response = TestClient(app.test_client()).with_session_auth(email="*****@*****.**").get("/users/current") # Then assert response.status_code == 200 assert not any("password" in field.lower() for field in response.json) assert response.json == { "activity": None, "address": None, "city": None, "civility": "M.", "dateCreated": format_into_utc_date(user.dateCreated), "dateOfBirth": format_into_utc_date(user.dateOfBirth), "departementCode": "93", "email": "*****@*****.**", "externalIds": {}, "firstName": "Jean", "hasCompletedIdCheck": None, "hasPhysicalVenues": False, "hasSeenProTutorials": True, "id": humanize(user.id), "idPieceNumber": None, "isAdmin": False, "isBeneficiary": True, "isEmailValidated": True, "lastConnectionDate": None, "lastName": "Smisse", "needsToFillCulturalSurvey": False, "notificationSubscriptions": {"marketing_email": True, "marketing_push": True}, "phoneNumber": "0612345678", "phoneValidationStatus": None, "postalCode": "93020", "publicName": "Toto", "roles": ["BENEFICIARY"], }
def when_account_is_known(self, app): # given user = create_user( civility="M.", departement_code="93", email="*****@*****.**", first_name="Jean", last_name="Smisse", date_of_birth=datetime.datetime(2000, 1, 1), phone_number="0612345678", postal_code="93020", public_name="Toto", ) user.isEmailValidated = True repository.save(user) data = { "identifier": user.email, "password": user.clearTextPassword } # when response = TestClient(app.test_client()).post("/users/signin", json=data) # then assert response.status_code == 200 assert not any("password" in field.lower() for field in response.json) assert response.json == { "activity": None, "address": None, "city": None, "civility": "M.", "dateCreated": format_into_utc_date(user.dateCreated), "dateOfBirth": format_into_utc_date(user.dateOfBirth), "departementCode": "93", "email": "*****@*****.**", "firstName": "Jean", "hasAllowedRecommendations": False, "hasOffers": False, "hasPhysicalVenues": False, "id": humanize(user.id), "isAdmin": False, "isBeneficiary": True, "isEmailValidated": True, "lastConnectionDate": None, "lastName": "Smisse", "needsToFillCulturalSurvey": False, "phoneNumber": "0612345678", "postalCode": "93020", "publicName": "Toto", }
def when_changes_are_allowed(self, app): # given now = datetime.now() user = create_user(last_connection_date=now, date_of_birth=now) repository.save(user) user_id = user.id data = { "publicName": "plop", "email": "*****@*****.**", "postalCode": "93020", "phoneNumber": "0612345678", "departementCode": "97", "hasSeenTutorials": True, } # when response = TestClient(app.test_client()).with_auth( email=user.email).patch("/users/current", json=data) # then user = User.query.get(user_id) assert user.publicName == "plop" assert user.email == "*****@*****.**" assert user.postalCode == "93020" assert user.departementCode == "97" assert user.phoneNumber == "0612345678" assert user.hasSeenTutorials assert response.json == { "activity": None, "address": None, "isBeneficiary": True, "city": None, "civility": None, "dateCreated": format_into_utc_date(user.dateCreated), "dateOfBirth": format_into_utc_date(now), "departementCode": "97", "email": "*****@*****.**", "firstName": None, "hasOffers": False, "hasPhysicalVenues": False, "id": humanize(user.id), "isAdmin": False, "lastConnectionDate": format_into_utc_date(now), "lastName": None, "needsToFillCulturalSurvey": False, "phoneNumber": "0612345678", "postalCode": "93020", "publicName": "plop", }
def when_account_is_known(self, app): # given user = users_factories.BeneficiaryGrant18Factory( civility="M.", departementCode="93", city=None, address=None, needsToFillCulturalSurvey=False, email="*****@*****.**", firstName="Jean", lastName="Smisse", phoneNumber="0612345678", postalCode="93020", publicName="Toto", lastConnectionDate=datetime.datetime(2019, 1, 1), ) data = {"identifier": user.email, "password": user.clearTextPassword} # when response = TestClient(app.test_client()).post("/users/signin", json=data) # then assert response.status_code == 200 assert not any("password" in field.lower() for field in response.json) assert response.json == { "activity": None, "address": None, "city": None, "civility": "M.", "dateCreated": format_into_utc_date(user.dateCreated), "dateOfBirth": format_into_utc_date(user.dateOfBirth), "departementCode": "93", "email": "*****@*****.**", "firstName": "Jean", "hasPhysicalVenues": False, "hasSeenProTutorials": True, "id": humanize(user.id), "isAdmin": False, "isBeneficiary": True, "isEmailValidated": True, "lastConnectionDate": format_into_utc_date(user.lastConnectionDate), "lastName": "Smisse", "needsToFillCulturalSurvey": False, "phoneNumber": "0612345678", "postalCode": "93020", "publicName": "Toto", "roles": ["BENEFICIARY"], }
def when_user_is_logged_in_and_has_no_deposit(self, app): # Given user = create_user( civility="M.", departement_code="93", email="*****@*****.**", first_name="Jean", last_name="Smisse", date_of_birth=datetime.datetime(2000, 1, 1), phone_number="0612345678", postal_code="93020", public_name="Toto", ) user.isEmailValidated = True repository.save(user) # When response = TestClient(app.test_client()).with_auth( email="*****@*****.**").get("/users/current") # Then assert response.status_code == 200 assert not any("password" in field.lower() for field in response.json) assert response.json == { "activity": None, "address": None, "city": None, "civility": "M.", "dateCreated": format_into_utc_date(user.dateCreated), "dateOfBirth": format_into_utc_date(user.dateOfBirth), "departementCode": "93", "email": "*****@*****.**", "firstName": "Jean", "hasAllowedRecommendations": False, "hasOffers": False, "hasPhysicalVenues": False, "hasSeenProTutorials": False, "id": humanize(user.id), "isAdmin": False, "isBeneficiary": True, "isEmailValidated": True, "lastConnectionDate": None, "lastName": "Smisse", "needsToFillCulturalSurvey": False, "phoneNumber": "0612345678", "postalCode": "93020", "publicName": "Toto", }
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 when_user_has_rights_and_regular_offer(self, app): # Given user = create_user(email="*****@*****.**", public_name="John Doe") create_deposit(user) admin_user = create_user(email="*****@*****.**") offerer = create_offerer() create_user_offerer(admin_user, offerer) venue = create_venue(offerer, name="Venue name", address="Venue address") offer = create_offer_with_event_product( venue=venue, event_name="Event Name", event_type=EventType.CINEMA) four_days_from_now = datetime.utcnow() + timedelta(days=4) event_occurrence = create_event_occurrence( offer, beginning_datetime=four_days_from_now) stock = create_stock_from_event_occurrence(event_occurrence, price=12) unconfirmed_booking = create_booking( user=user, quantity=3, stock=stock, venue=venue, date_created=datetime.utcnow() - timedelta(hours=48)) repository.save(unconfirmed_booking) url = f"/v2/bookings/token/{unconfirmed_booking.token}" # When response = TestClient( app.test_client()).with_auth("*****@*****.**").get(url) # Then assert response.headers["Content-type"] == "application/json" assert response.status_code == 200 assert response.json == { "bookingId": humanize(unconfirmed_booking.id), "dateOfBirth": "", "datetime": format_into_utc_date(stock.beginningDatetime), "ean13": "", "email": "*****@*****.**", "formula": "PLACE", "isUsed": False, "offerId": offer.id, "offerName": "Event Name", "offerType": "EVENEMENT", "phoneNumber": "", "price": 12.0, "publicOfferId": humanize(offer.id), "quantity": 3, "userName": "******", "venueAddress": "Venue address", "venueDepartementCode": "93", "venueName": "Venue name", }
def test_when_user_has_rights_and_regular_offer(self, client): # Given past = datetime.now() - timedelta(days=2) booking = bookings_factories.IndividualBookingFactory( individualBooking__user__email="*****@*****.**", stock__beginningDatetime=past, stock__offer=offers_factories.EventOfferFactory( extraData={ "theater": { "allocine_movie_id": 165, "allocine_room_id": 987, }, }, subcategoryId=subcategories.CARTE_CINE_MULTISEANCES.id, product__name="An offer you cannot refuse", venue__name="Le Petit Rintintin", ), ) user_offerer = offers_factories.UserOffererFactory(offerer=booking.offerer) pro_user = user_offerer.user # When client = client.with_basic_auth(pro_user.email) response = client.get(f"/v2/bookings/token/{booking.token}") # Then assert response.headers["Content-type"] == "application/json" assert response.status_code == 200 assert response.json == { "bookingId": humanize(booking.id), "dateOfBirth": "", "datetime": format_into_utc_date(booking.stock.beginningDatetime), "ean13": None, "email": "*****@*****.**", "formula": "ABO", "isUsed": False, "offerId": booking.stock.offerId, "offerName": "An offer you cannot refuse", "offerType": "EVENEMENT", "phoneNumber": "", "price": 10.0, "publicOfferId": humanize(booking.stock.offerId), "quantity": 1, "theater": { "allocine_movie_id": 165, "allocine_room_id": 987, }, "userName": "******", "venueAddress": "1 boulevard Poissonnière", "venueDepartmentCode": "75", "venueName": "Le Petit Rintintin", }
def test_when_user_has_rights_and_booking_is_educational_validated_by_principal(self, client): # Given redactor = educational_factories.EducationalRedactorFactory( civility="M.", firstName="Jean", lastName="Doudou", email="*****@*****.**", ) validated_eac_booking = bookings_factories.EducationalBookingFactory( dateCreated=datetime.utcnow() - timedelta(days=5), educationalBooking__educationalRedactor=redactor, educationalBooking__status=EducationalBookingStatus.USED_BY_INSTITUTE, ) pro_user = users_factories.ProFactory() offers_factories.UserOffererFactory(user=pro_user, offerer=validated_eac_booking.offerer) # When client = client.with_basic_auth(pro_user.email) response = client.get(f"/v2/bookings/token/{validated_eac_booking.token}") # Then assert response.headers["Content-type"] == "application/json" assert response.status_code == 200 assert response.json == { "bookingId": humanize(validated_eac_booking.id), "dateOfBirth": "", "datetime": format_into_utc_date(validated_eac_booking.stock.beginningDatetime), "ean13": None, "email": redactor.email, "formula": "PLACE", "isUsed": False, "offerId": validated_eac_booking.stock.offer.id, "offerName": validated_eac_booking.stock.offer.name, "offerType": "EVENEMENT", "phoneNumber": "", "price": float(validated_eac_booking.stock.price), "publicOfferId": humanize(validated_eac_booking.stock.offer.id), "quantity": validated_eac_booking.quantity, "theater": {}, "userName": f"{redactor.firstName} {redactor.lastName}", "venueAddress": validated_eac_booking.venue.address, "venueDepartmentCode": validated_eac_booking.venue.departementCode, "venueName": validated_eac_booking.venue.name, }
def get_booking_response(booking: Booking) -> GetBookingResponse: if booking.stock.offer.subcategoryId == subcategories.SEANCE_CINE.id: formula = BookingFormula.PLACE elif booking.stock.offer.subcategoryId in ( subcategories.CARTE_CINE_ILLIMITE.id, subcategories.CARTE_CINE_MULTISEANCES.id, ): formula = BookingFormula.ABO else: formula = BookingFormula.VOID extra_data = booking.stock.offer.extraData or {} return GetBookingResponse( bookingId=humanize(booking.id), dateOfBirth="", datetime=(format_into_utc_date(booking.stock.beginningDatetime) if booking.stock.beginningDatetime else ""), ean13=(extra_data.get("isbn", "") if booking.stock.offer.subcategoryId in subcategories.BOOK_WITH_ISBN else None), email=booking.email, formula=formula, isUsed=booking.isUsed, offerId=booking.stock.offer.id, publicOfferId=humanize(booking.stock.offer.id), offerName=booking.stock.offer.product.name, offerType=BookingOfferType.EVENEMENT if booking.stock.offer.isEvent else BookingOfferType.EVENEMENT, phoneNumber="", price=booking.amount, quantity=booking.quantity, theater=extra_data.get("theater", ""), userName=booking.publicName, venueAddress=booking.venue.address, venueDepartmentCode=booking.venue.departementCode, venueName=booking.venue.name, )
def test_patch_beneficiary(app): user = BeneficiaryGrant18Factory(deposit__version=1) data = { "publicName": "Anne", } client = TestClient(app.test_client()).with_session_auth(email=user.email) response = client.patch("/beneficiaries/current", json=data) assert user.publicName == data["publicName"] assert response.status_code == 200 assert response.json == { "pk": user.id, "activity": None, "address": user.address, "city": "Paris", "civility": None, "domainsCredit": { "all": { "initial": 500.0, "remaining": 500.0 }, "digital": { "initial": 200.0, "remaining": 200.0 }, "physical": { "initial": 200.0, "remaining": 200.0 }, }, "dateCreated": format_into_utc_date(user.dateCreated), "dateOfBirth": format_into_utc_date(user.dateOfBirth), "departementCode": user.departementCode, "deposit_version": 1, "email": user.email, "firstName": "Jeanne", "hasPhysicalVenues": False, "id": humanize(user.id), "isActive": True, "isAdmin": False, "isBeneficiary": True, "isEmailValidated": True, "lastName": "Doux", "needsToFillCulturalSurvey": True, "needsToSeeTutorials": True, "phoneNumber": user.phoneNumber, "postalCode": user.postalCode, "publicName": "Anne", "roles": ["BENEFICIARY"], "suspensionReason": "", "wallet_balance": 500.0, "deposit_expiration_date": format_into_utc_date(user.deposit_expiration_date), "wallet_is_activated": True, }
def test_when_user_has_bookings_and_qr_code_feature_is_inactive_does_not_return_qr_code( 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) booking1 = IndividualBookingFactory(individualBooking__user=user1, stock=stock, token="ABCDEF") IndividualBookingFactory(individualBooking__user=user2, stock=stock, token="GHIJK") booking3 = IndividualBookingFactory(individualBooking__user=user1, stock=stock2, token="BBBBB") # When response = TestClient(app.test_client()).with_session_auth( user1.email).get("/bookings") # Then assert response.status_code == 200 bookings = response.json assert len(bookings) == 2 assert {b["id"] for b in bookings } == set(humanize(b.id) for b in {booking1, booking3}) assert "qrCode" not in bookings[0] assert "validationToken" not in bookings[0]["stock"]["offer"]["venue"] assert bookings[0]["id"] == humanize(booking1.id) assert bookings[0] == { "activationCode": None, "amount": 0.0, "cancellationDate": None, "completedUrl": None, "dateCreated": format_into_utc_date(booking1.dateCreated), "dateUsed": None, "displayAsEnded": None, "id": humanize(booking1.id), "isCancelled": False, "isEventExpired": False, "isUsed": False, "quantity": 1, "stock": { "beginningDatetime": None, "id": humanize(stock.id), "isEventExpired": False, "offer": { "description": offer.description, "durationMinutes": None, "extraData": offer.extraData, "id": humanize(offer.id), "isBookable": True, "isDigital": False, "isDuo": False, "isEvent": False, "isNational": False, "name": offer.product.name, "stocks": [{ "beginningDatetime": None, "bookingLimitDatetime": None, "dateCreated": format_into_utc_date(stock.dateCreated), "dateModified": format_into_utc_date(stock.dateModified), "id": humanize(stock.id), "isBookable": True, "offerId": humanize(offer.id), "price": 0.0, "quantity": None, "remainingQuantity": "unlimited", }], "thumbUrl": None, "venue": { "address": venue.address, "city": venue.city, "departementCode": venue.departementCode, "id": humanize(venue.id), "latitude": None, "longitude": None, "name": venue.name, "postalCode": venue.postalCode, }, "venueId": humanize(venue.id), "withdrawalDetails": None, }, "offerId": humanize(offer.id), "price": 0.0, }, "stockId": humanize(stock.id), "token": "ABCDEF", "userId": humanize(booking1.individualBooking.userId), }
def test_get_educational_institution(self, app) -> None: redactor = EducationalRedactorFactory( civility="M.", firstName="Jean", lastName="Doudou", email="*****@*****.**", ) educational_year = EducationalYearFactory() educational_institution = EducationalInstitutionFactory() EducationalDepositFactory( educationalInstitution=educational_institution, educationalYear=educational_year, amount=2000, isFinal=True, ) EducationalInstitutionFactory() booking = EducationalBookingFactory( educationalBooking__educationalRedactor=redactor, educationalBooking__educationalYear=educational_year, educationalBooking__educationalInstitution=educational_institution, ) other_educational_year = EducationalYearFactory(adageId="toto") other_educational_institution = EducationalInstitutionFactory( institutionId="tata") EducationalBookingFactory( educationalBooking__educationalYear=other_educational_year) EducationalBookingFactory(educationalBooking__educationalInstitution= other_educational_institution) EducationalDepositFactory( educationalInstitution=educational_institution, educationalYear=other_educational_year, amount=2000, isFinal=False, ) EducationalDepositFactory( educationalInstitution=other_educational_institution, educationalYear=educational_year, amount=2000, isFinal=False, ) client = TestClient(app.test_client()).with_eac_token() response = client.get( f"/adage/v1/years/{educational_year.adageId}/educational_institution/{educational_institution.institutionId}" ) assert response.status_code == 200 stock = booking.stock offer = stock.offer venue = offer.venue educational_booking = booking.educationalBooking assert response.json == { "credit": 2000, "isFinal": True, "prebookings": [{ "address": venue.address, "beginningDatetime": format_into_utc_date(stock.beginningDatetime), "cancellationDate": None, "cancellationLimitDate": format_into_utc_date(booking.cancellationLimitDate), "city": venue.city, "confirmationDate": format_into_utc_date(educational_booking.confirmationDate) if educational_booking.confirmationDate else None, "confirmationLimitDate": format_into_utc_date( educational_booking.confirmationLimitDate), "coordinates": { "latitude": float(venue.latitude), "longitude": float(venue.longitude), }, "creationDate": format_into_utc_date(booking.dateCreated), "description": offer.description, "durationMinutes": offer.durationMinutes, "expirationDate": booking.expirationDate, "id": educational_booking.id, "image": { "url": offer.image.url, "credit": offer.image.credit } if offer.image else None, "isDigital": offer.isDigital, "venueName": venue.name, "name": offer.name, "postalCode": venue.postalCode, "price": booking.amount, "quantity": booking.quantity, "redactor": { "email": "*****@*****.**", "redactorFirstName": "Jean", "redactorLastName": "Doudou", "redactorCivility": "M.", }, "UAICode": educational_booking.educationalInstitution.institutionId, "yearId": int(educational_booking.educationalYearId), "status": "CONFIRMED", "venueTimezone": venue.timezone, "totalAmount": booking.amount * booking.quantity, "url": offer_webapp_link(offer), "withdrawalDetails": offer.withdrawalDetails, }], }
def when_user_has_rights_on_managing_offerer(self, app): # given user_offerer = offers_factories.UserOffererFactory( user__email="*****@*****.**") venue = offers_factories.VenueFactory( name="L'encre et la plume", managingOfferer=user_offerer.offerer) bank_information = offers_factories.BankInformationFactory(venue=venue) expected_serialized_venue = { "address": venue.address, "audioDisabilityCompliant": venue.audioDisabilityCompliant, "bic": bank_information.bic, "bookingEmail": venue.bookingEmail, "city": venue.city, "contact": { "email": venue.contact.email, "website": venue.contact.website, "phoneNumber": venue.contact.phone_number, "socialMedias": venue.contact.social_medias, }, "comment": venue.comment, "dateCreated": format_into_utc_date(venue.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(venue.dateModifiedAtLastProvider), "demarchesSimplifieesApplicationId": str(venue.demarchesSimplifieesApplicationId), "departementCode": venue.departementCode, "description": venue.description, "fieldsUpdated": venue.fieldsUpdated, "iban": bank_information.iban, "id": humanize(venue.id), "idAtProviders": venue.idAtProviders, "isValidated": venue.isValidated, "isVirtual": venue.isVirtual, "latitude": float(venue.latitude), "lastProviderId": venue.lastProviderId, "longitude": float(venue.longitude), "managingOfferer": { "address": venue.managingOfferer.address, "bic": venue.managingOfferer.bic, "city": venue.managingOfferer.city, "dateCreated": format_into_utc_date(venue.managingOfferer.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date( venue.managingOfferer.dateModifiedAtLastProvider), "demarchesSimplifieesApplicationId": venue.managingOfferer.demarchesSimplifieesApplicationId, "fieldsUpdated": venue.managingOfferer.fieldsUpdated, "iban": venue.managingOfferer.iban, "id": humanize(venue.managingOfferer.id), "idAtProviders": venue.managingOfferer.idAtProviders, "isValidated": venue.managingOfferer.isValidated, "lastProviderId": venue.managingOfferer.lastProviderId, "name": venue.managingOfferer.name, "postalCode": venue.managingOfferer.postalCode, "siren": venue.managingOfferer.siren, }, "managingOffererId": humanize(venue.managingOffererId), "mentalDisabilityCompliant": venue.mentalDisabilityCompliant, "motorDisabilityCompliant": venue.motorDisabilityCompliant, "name": venue.name, "postalCode": venue.postalCode, "publicName": venue.publicName, "siret": venue.siret, "venueLabelId": humanize(venue.venueLabelId), "venueTypeId": humanize(venue.venueTypeId), "visualDisabilityCompliant": venue.visualDisabilityCompliant, "withdrawalDetails": None, } # when auth_request = TestClient( app.test_client()).with_session_auth(email=user_offerer.user.email) response = auth_request.get("/venues/%s" % humanize(venue.id)) # then assert response.status_code == 200 assert response.json == expected_serialized_venue
def test_mark_prebooking_as_used(self, app) -> None: redactor = EducationalRedactorFactory( civility="M.", firstName="Jean", lastName="Doudou", email="*****@*****.**", ) booking = EducationalBookingFactory( educationalBooking__educationalRedactor=redactor, status=BookingStatus.CONFIRMED, ) client = TestClient(app.test_client()).with_eac_token() response = client.post( f"/adage/v1/prebookings/{booking.educationalBooking.id}/mark_as_used" ) assert response.status_code == 200 stock = booking.stock offer = stock.offer venue = offer.venue educational_booking = booking.educationalBooking assert response.json == { "address": venue.address, "beginningDatetime": format_into_utc_date(stock.beginningDatetime), "cancellationDate": None, "cancellationLimitDate": format_into_utc_date(booking.cancellationLimitDate), "city": venue.city, "confirmationDate": None, "confirmationLimitDate": format_into_utc_date(educational_booking.confirmationLimitDate), "coordinates": { "latitude": float(venue.latitude), "longitude": float(venue.longitude), }, "creationDate": format_into_utc_date(booking.dateCreated), "description": offer.description, "durationMinutes": offer.durationMinutes, "expirationDate": booking.expirationDate, "id": educational_booking.id, "image": None, "isDigital": offer.isDigital, "venueName": venue.name, "name": offer.name, "postalCode": venue.postalCode, "price": booking.amount, "quantity": booking.quantity, "redactor": { "email": "*****@*****.**", "redactorFirstName": "Jean", "redactorLastName": "Doudou", "redactorCivility": "M.", }, "UAICode": educational_booking.educationalInstitution.institutionId, "yearId": int(educational_booking.educationalYearId), "status": "USED_BY_INSTITUTE", "venueTimezone": venue.timezone, "totalAmount": booking.total_amount, "url": offer_webapp_link(offer), "withdrawalDetails": offer.withdrawalDetails, }
def expect_booking_to_have_completed_url(self, app): # Given user = create_user(email="*****@*****.**") offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_thing_product( venue, url="https://host/path/{token}?offerId={offerId}&email={email}" ) stock = create_stock(offer=offer, price=0) booking = create_booking(user=user, stock=stock, token="ABCDEF", venue=venue) repository.save(booking) # When response = TestClient(app.test_client()).with_auth( user.email).get("/bookings/" + humanize(booking.id)) # Then assert response.status_code == 200 completed_url = "https://host/path/ABCDEF?offerId={}&[email protected]".format( humanize(offer.id)) assert "validationToken" not in response.json["stock"]["offer"] assert response.json == { "amount": 0.0, "cancellationDate": None, "cancellationReason": None, "completedUrl": completed_url, "confirmationDate": None, "dateCreated": format_into_utc_date(booking.dateCreated), "dateUsed": None, "id": humanize(booking.id), "isCancelled": False, "isEventExpired": False, "isUsed": False, "mediation": None, "quantity": 1, "stock": { "beginningDatetime": None, "bookingLimitDatetime": None, "dateCreated": format_into_utc_date(stock.dateCreated), "dateModified": format_into_utc_date(stock.dateModified), "dateModifiedAtLastProvider": format_into_utc_date(stock.dateModifiedAtLastProvider), "fieldsUpdated": [], "id": humanize(stock.id), "idAtProviders": None, "isBookable": True, "isEventExpired": False, "isSoftDeleted": False, "lastProviderId": None, "offer": { "ageMax": None, "ageMin": None, "audioDisabilityCompliant": None, "bookingEmail": "*****@*****.**", "conditions": None, "dateCreated": format_into_utc_date(offer.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(offer.dateModifiedAtLastProvider), "description": None, "durationMinutes": None, "externalTicketOfficeUrl": None, "extraData": { "author": "Test Author" }, "fieldsUpdated": [], "hasBookingLimitDatetimesPassed": False, "id": humanize(offer.id), "idAtProviders": offer.idAtProviders, "isActive": True, "isBookable": True, "isDigital": True, "isDuo": False, "isEvent": False, "isNational": False, "lastProviderId": None, "mediaUrls": ["test/urls"], "mentalDisabilityCompliant": None, "motorDisabilityCompliant": None, "name": "Test Book", "offerType": { "appLabel": "Film", "canExpire": True, "conditionalFields": [], "description": ("Action, science-fiction, documentaire ou comédie " "sentimentale ? En salle, en plein air ou bien au chaud " "chez soi ? Et si c’était plutôt cette exposition qui " "allait faire son cinéma ?"), "isActive": True, "offlineOnly": False, "onlineOnly": False, "proLabel": "Audiovisuel - films sur supports physiques et VOD", "sublabel": "Regarder", "type": "Thing", "value": "ThingType.AUDIOVISUEL", }, "productId": humanize(offer.product.id), "stocks": [{ "beginningDatetime": None, "bookingLimitDatetime": None, "dateCreated": format_into_utc_date(stock.dateCreated), "dateModified": format_into_utc_date(stock.dateModified), "dateModifiedAtLastProvider": format_into_utc_date( stock.dateModifiedAtLastProvider), "fieldsUpdated": [], "id": humanize(stock.id), "idAtProviders": None, "isBookable": True, "isEventExpired": False, "isSoftDeleted": False, "lastProviderId": None, "offerId": humanize(offer.id), "price": 0.0, "quantity": None, "remainingQuantity": "unlimited", }], "thumbUrl": None, "type": "ThingType.AUDIOVISUEL", "url": "https://host/path/{token}?offerId={offerId}&email={email}", "venue": { "address": "123 rue de Paris", "bookingEmail": None, "city": "Montreuil", "comment": None, "dateCreated": format_into_utc_date(venue.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date( venue.dateModifiedAtLastProvider), "departementCode": "93", "fieldsUpdated": [], "id": humanize(venue.id), "idAtProviders": None, "isVirtual": False, "lastProviderId": None, "latitude": None, "longitude": None, "managingOffererId": humanize(offerer.id), "name": "La petite librairie", "postalCode": "93100", "publicName": None, "siret": "12345678912345", "thumbCount": 0, "venueLabelId": None, "venueTypeId": None, }, "venueId": humanize(venue.id), "visualDisabilityCompliant": None, "withdrawalDetails": None, }, "offerId": humanize(offer.id), "price": 0.0, "quantity": None, "remainingQuantity": "unlimited", }, "stockId": humanize(stock.id), "token": booking.token, "userId": humanize(user.id), }
def _(value, column=None): return format_into_utc_date(value)
def when_returning_serialized_beneficiary(self, app): # given user = UserFactory(address="1 rue des machines") data = { "publicName": "Anne", "email": "*****@*****.**", "postalCode": "93020", "phoneNumber": "1234567890", "departementCode": "97", "hasSeenTutorials": True, } # when response = (TestClient(app.test_client()).with_auth( email=user.email).patch("/beneficiaries/current", json=data)) # then assert response.json == { "activity": None, "address": "1 rue des machines", "city": "Paris", "civility": None, "dateCreated": format_into_utc_date(user.dateCreated), "dateOfBirth": "2000-01-01T00:00:00Z", "departementCode": "97", "deposit_version": 1, "email": "*****@*****.**", "expenses": [ { "current": 0.0, "domain": "all", "limit": 500.0 }, { "current": 0.0, "domain": "digital", "limit": 200.0 }, { "current": 0.0, "domain": "physical", "limit": 200.0 }, ], "firstName": "Jeanne", "hasAllowedRecommendations": False, "hasPhysicalVenues": False, "id": humanize(user.id), "isActive": True, "isAdmin": False, "isBeneficiary": True, "isEmailValidated": True, "lastName": "Doux", "needsToFillCulturalSurvey": True, "needsToSeeTutorials": False, "phoneNumber": "1234567890", "postalCode": "93020", "publicName": "Anne", "suspensionReason": "", "wallet_balance": 500.0, "deposit_expiration_date": format_into_utc_date(user.deposit_expiration_date), "wallet_is_activated": True, }
def test_refuse_prebooking(self, app) -> None: redactor = EducationalRedactorFactory( civility="M.", firstName="Jean", lastName="Doudou", email="*****@*****.**", ) stock: Stock = EventStockFactory(quantity=200, dnBookedQuantity=0) booking = EducationalBookingFactory( educationalBooking__educationalRedactor=redactor, status=BookingStatus.CONFIRMED, stock=stock, quantity=20, ) client = TestClient(app.test_client()).with_eac_token() response = client.post( f"/adage/v1/prebookings/{booking.educationalBookingId}/refuse") assert response.status_code == 200 booking = Booking.query.one() stock = booking.stock offer = stock.offer venue = offer.venue educational_booking = booking.educationalBooking assert response.json == { "address": venue.address, "beginningDatetime": format_into_utc_date(stock.beginningDatetime), "cancellationDate": "2022-11-17T15:00:00Z", "cancellationLimitDate": format_into_utc_date(booking.cancellationLimitDate), "city": venue.city, "confirmationDate": None, "confirmationLimitDate": format_into_utc_date(educational_booking.confirmationLimitDate), "coordinates": { "latitude": float(venue.latitude), "longitude": float(venue.longitude), }, "creationDate": format_into_utc_date(booking.dateCreated), "description": offer.description, "durationMinutes": offer.durationMinutes, "expirationDate": booking.expirationDate, "id": educational_booking.id, "image": None, "isDigital": offer.isDigital, "venueName": venue.name, "name": offer.name, "postalCode": venue.postalCode, "price": booking.amount, "quantity": booking.quantity, "redactor": { "email": "*****@*****.**", "redactorFirstName": "Jean", "redactorLastName": "Doudou", "redactorCivility": "M.", }, "UAICode": educational_booking.educationalInstitution.institutionId, "yearId": int(educational_booking.educationalYearId), "status": "REFUSED", "venueTimezone": venue.timezone, "totalAmount": booking.total_amount, "url": offer_webapp_link(offer), "withdrawalDetails": offer.withdrawalDetails, } # It should be 0 because on booking factory creation it goes to 20, then on cancellation it goes 20-20 assert stock.dnBookedQuantity == 0 assert booking.status == BookingStatus.CANCELLED assert booking.cancellationReason == BookingCancellationReasons.REFUSED_BY_INSTITUTE
def test_when_user_has_rights_on_offerer(self, app): pro = users_factories.ProFactory() offerer = offers_factories.OffererFactory() offers_factories.UserOffererFactory(user=pro, offerer=offerer) venue_1 = offers_factories.VenueFactory( managingOfferer=offerer, withdrawalDetails="Venue withdrawal details") offers_factories.OfferFactory(venue=venue_1) venue_2 = offers_factories.VenueFactory( managingOfferer=offerer, withdrawalDetails="Other venue withdrawal details") offers_factories.VenueFactory( managingOfferer=offerer, withdrawalDetails="More venue withdrawal details") ApiKeyFactory(offerer=offerer, prefix="testenv_prefix") ApiKeyFactory(offerer=offerer, prefix="testenv_prefix2") offers_factories.BankInformationFactory(venue=venue_1, applicationId=2, status="REJECTED") offers_factories.BankInformationFactory(venue=venue_1, applicationId=3) offers_factories.BankInformationFactory(venue=venue_2, applicationId=4) client = TestClient(app.test_client()).with_session_auth(pro.email) n_queries = ( testing.AUTHENTICATION_QUERIES + 1 # check_user_has_access_to_offerer + 1 # Offerer api_key prefix + 1 # Offerer hasDigitalVenueAtLeastOneOffer + 1 # Offerer BankInformation + 1 # Offerer hasMissingBankInformation ) with testing.assert_num_queries(n_queries): response = client.get(f"/offerers/{humanize(offerer.id)}") expected_serialized_offerer = { "address": offerer.address, "apiKey": { "maxAllowed": 5, "prefixes": ["testenv_prefix", "testenv_prefix2"] }, "bic": None, "iban": None, "city": offerer.city, "dateCreated": format_into_utc_date(offerer.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(offerer.dateModifiedAtLastProvider), "demarchesSimplifieesApplicationId": None, "hasDigitalVenueAtLeastOneOffer": False, "fieldsUpdated": offerer.fieldsUpdated, "hasMissingBankInformation": True, "id": humanize(offerer.id), "idAtProviders": offerer.idAtProviders, "isValidated": offerer.isValidated, "lastProviderId": offerer.lastProviderId, "managedVenues": [{ "audioDisabilityCompliant": False, "address": offererVenue.address, "bookingEmail": offererVenue.bookingEmail, "city": offererVenue.city, "comment": offererVenue.comment, "departementCode": offererVenue.departementCode, "id": humanize(offererVenue.id), "isValidated": offererVenue.isValidated, "isVirtual": offererVenue.isVirtual, "managingOffererId": humanize(offererVenue.managingOffererId), "mentalDisabilityCompliant": False, "motorDisabilityCompliant": False, "name": offererVenue.name, "postalCode": offererVenue.postalCode, "publicName": offererVenue.publicName, "venueLabelId": humanize(offererVenue.venueLabelId), "venueTypeId": humanize(offererVenue.venueTypeId), "visualDisabilityCompliant": False, "withdrawalDetails": offererVenue.withdrawalDetails, } for offererVenue in offerer.managedVenues], "name": offerer.name, "postalCode": offerer.postalCode, "siren": offerer.siren, } assert response.status_code == 200 assert response.json == expected_serialized_offerer
def _(value, column=None): return [format_into_utc_date(v) for v in value.datetimes]
def test_confirm_prebooking(self, app, db_session) -> None: redactor = EducationalRedactorFactory( civility="Mme", firstName="Jeanne", lastName="Dodu", email="*****@*****.**", ) educational_institution = EducationalInstitutionFactory() educational_year = EducationalYearFactory(adageId="1") EducationalDeposit( educationalInstitution=educational_institution, educationalYear=educational_year, amount=Decimal(1400.00), isFinal=True, ) EducationalBookingFactory( amount=Decimal(20.00), quantity=20, educationalBooking__educationalInstitution=educational_institution, educationalBooking__educationalYear=educational_year, status=BookingStatus.CONFIRMED, ) booking = EducationalBookingFactory( amount=Decimal(20.00), quantity=20, educationalBooking__educationalInstitution=educational_institution, educationalBooking__educationalYear=educational_year, educationalBooking__educationalRedactor=redactor, status=BookingStatus.PENDING, educationalBooking__confirmationLimitDate=datetime( 2021, 10, 15, 10), ) client = TestClient(app.test_client()).with_eac_token() response = client.post( f"/adage/v1/prebookings/{booking.educationalBookingId}/confirm") assert response.status_code == 200 stock = booking.stock offer = stock.offer venue = offer.venue educational_booking = booking.educationalBooking assert response.json == { "address": venue.address, "beginningDatetime": format_into_utc_date(stock.beginningDatetime), "cancellationDate": None, "cancellationLimitDate": format_into_utc_date(booking.cancellationLimitDate), "city": venue.city, "confirmationDate": "2021-10-15T09:00:00Z", "confirmationLimitDate": format_into_utc_date(educational_booking.confirmationLimitDate), "coordinates": { "latitude": float(venue.latitude), "longitude": float(venue.longitude), }, "creationDate": format_into_utc_date(booking.dateCreated), "description": offer.description, "durationMinutes": offer.durationMinutes, "expirationDate": booking.expirationDate, "id": educational_booking.id, "image": None, "isDigital": offer.isDigital, "venueName": venue.name, "name": offer.name, "postalCode": venue.postalCode, "price": booking.amount, "quantity": booking.quantity, "redactor": { "email": "*****@*****.**", "redactorFirstName": "Jeanne", "redactorLastName": "Dodu", "redactorCivility": "Mme", }, "UAICode": educational_booking.educationalInstitution.institutionId, "yearId": int(educational_booking.educationalYearId), "status": "CONFIRMED", "venueTimezone": venue.timezone, "totalAmount": booking.total_amount, "url": offer_webapp_link(offer), "withdrawalDetails": offer.withdrawalDetails, } assert Booking.query.filter( Booking.id == booking.id).one().status == BookingStatus.CONFIRMED
def when_user_has_rights_on_offerer(self, app): # given pro = users_factories.UserFactory(isBeneficiary=False) offerer = offers_factories.OffererFactory() offers_factories.UserOffererFactory(user=pro, offerer=offerer) venue = offers_factories.VenueFactory(managingOfferer=offerer) offerer_bank_information = create_bank_information(offerer=offerer) venue_bank_information = create_bank_information(venue=venue, application_id=2) offerer = offerer_models.Offerer.query.filter_by(id=offerer.id).first() # when response = TestClient(app.test_client()).with_auth(pro.email).get(f"/offerers/{humanize(offerer.id)}") expected_serialized_offerer = { "address": offerer.address, "bic": offerer_bank_information.bic, "iban": offerer_bank_information.iban, "city": offerer.city, "dateCreated": format_into_utc_date(offerer.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(offerer.dateModifiedAtLastProvider), "demarchesSimplifieesApplicationId": str(offerer.demarchesSimplifieesApplicationId), "fieldsUpdated": offerer.fieldsUpdated, "id": humanize(offerer.id), "idAtProviders": offerer.idAtProviders, "isValidated": offerer.isValidated, "lastProviderId": offerer.lastProviderId, "managedVenues": [ { "bic": venue_bank_information.bic, "iban": venue_bank_information.iban, "address": offererVenue.address, "bookingEmail": offererVenue.bookingEmail, "city": offererVenue.city, "comment": offererVenue.comment, "dateCreated": format_into_utc_date(offererVenue.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(offererVenue.dateModifiedAtLastProvider), "departementCode": offererVenue.departementCode, "id": humanize(offererVenue.id), "idAtProviders": offererVenue.idAtProviders, "isValidated": offererVenue.isValidated, "isVirtual": offererVenue.isVirtual, "lastProviderId": offererVenue.lastProviderId, "latitude": float(offererVenue.latitude), "longitude": float(offererVenue.longitude), "managingOffererId": humanize(offererVenue.managingOffererId), "name": offererVenue.name, "nOffers": offererVenue.nOffers, "postalCode": offererVenue.postalCode, "publicName": offererVenue.publicName, "siret": offererVenue.siret, "venueLabelId": humanize(offererVenue.venueLabelId), "venueTypeId": humanize(offererVenue.venueTypeId), } for offererVenue in offerer.managedVenues ], "name": offerer.name, "nOffers": offerer.nOffers, "postalCode": offerer.postalCode, "siren": offerer.siren, } # then assert response.status_code == 200 assert response.json == expected_serialized_offerer
def save(content: dict, status: EmailStatus): email = Email() email.content = content email.status = status email.datetime = format_into_utc_date(datetime.utcnow()) repository.save(email)
def when_user_has_bookings_and_qr_code_feature_is_inactive_does_not_return_qr_code( self, qr_code_is_active, app ): # Given user1 = create_user(email="*****@*****.**") user2 = create_user(email="*****@*****.**") offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_thing_product(venue) stock = create_stock(offer=offer, price=0) offer2 = create_offer_with_thing_product(venue) stock2 = create_stock(offer=offer2, price=0) booking1 = create_booking(user=user1, stock=stock, token="ABCDEF", venue=venue) booking2 = create_booking(user=user2, stock=stock, token="GHIJK", venue=venue) booking3 = create_booking(user=user1, stock=stock2, token="BBBBB", venue=venue) repository.save(booking1, booking2, booking3) # When response = TestClient(app.test_client()).with_auth(user1.email).get("/bookings") # Then assert response.status_code == 200 bookings = response.json assert len(bookings) == 2 assert {b["id"] for b in bookings} == set(humanize(b.id) for b in {booking1, booking3}) assert "qrCode" not in bookings[0] assert "validationToken" not in bookings[0]["stock"]["offer"]["venue"] assert bookings[0]["id"] == humanize(booking1.id) assert bookings[0] == { "amount": 0.0, "cancellationDate": None, "completedUrl": None, "dateCreated": format_into_utc_date(booking1.dateCreated), "dateUsed": None, "id": humanize(booking1.id), "isCancelled": False, "isEventExpired": False, "isUsed": False, "quantity": 1, "stock": { "beginningDatetime": None, "id": humanize(stock.id), "isEventExpired": False, "offer": { "description": None, "durationMinutes": None, "extraData": {"author": "Test Author"}, "id": humanize(offer.id), "isBookable": True, "isDigital": False, "isDuo": False, "isEvent": False, "isNational": False, "name": "Test Book", "offerType": { "appLabel": "Film", "canExpire": True, "conditionalFields": [], "description": ( "Action, science-fiction, documentaire ou comédie " "sentimentale ? En salle, en plein air ou bien au chaud " "chez soi ? Et si c’était plutôt cette exposition qui " "allait faire son cinéma ?" ), "isActive": True, "offlineOnly": False, "onlineOnly": False, "proLabel": "Audiovisuel - films sur " "supports physiques et VOD", "sublabel": "Regarder", "type": "Thing", "value": "ThingType.AUDIOVISUEL", }, "stocks": [ { "beginningDatetime": None, "bookingLimitDatetime": None, "dateCreated": format_into_utc_date(stock.dateCreated), "dateModified": format_into_utc_date(stock.dateModified), "id": humanize(stock.id), "isBookable": True, "offerId": humanize(offer.id), "price": 0.0, "quantity": None, "remainingQuantity": "unlimited", } ], "thumbUrl": None, "venue": { "address": "123 rue de Paris", "city": "Montreuil", "departementCode": "93", "id": humanize(venue.id), "latitude": None, "longitude": None, "name": "La petite librairie", "postalCode": "93100", }, "venueId": humanize(venue.id), "withdrawalDetails": None, }, "offerId": humanize(offer.id), "price": 0.0, }, "stockId": humanize(stock.id), "token": "ABCDEF", "userId": humanize(booking1.userId), }
def test_should_return_expected_payload_for_bookable_offer(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) product = create_product_with_event_subcategory() offer = create_offer_with_event_product(venue, product=product) stock = create_stock(offer=offer) mediation = create_mediation(offer) repository.save(mediation, stock) # When offer_json_response = get_non_free_event_offer() # Then assert offer_json_response == { "mediationId": humanize(mediation.id), "offer": { "ageMax": None, "ageMin": None, "authorId": None, "audioDisabilityCompliant": None, "bookingEmail": "*****@*****.**", "conditions": None, "dateCreated": format_into_utc_date(offer.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(offer.dateModifiedAtLastProvider), "description": None, "durationMinutes": 60, "externalTicketOfficeUrl": None, "extraData": None, "fieldsUpdated": [], "id": humanize(offer.id), "idAtProvider": None, "idAtProviders": offer.idAtProviders, "isActive": True, "isDuo": False, "isEducational": False, "isNational": False, "dateUpdated": format_into_utc_date(offer.dateUpdated), "lastProviderId": None, "lastValidationDate": None, "mediaUrls": [], "mentalDisabilityCompliant": None, "motorDisabilityCompliant": None, "name": "Test event", "productId": humanize(product.id), "rankingWeight": None, "status": "ACTIVE", "subcategoryId": "SPECTACLE_REPRESENTATION", "thingName": "Test event", "url": None, "validation": "APPROVED", "venueCity": "Montreuil", "venueId": humanize(venue.id), "venueName": "La petite librairie", "visualDisabilityCompliant": None, "withdrawalDetails": None, }, "stockCount": 1, }
def test_should_return_expected_payload_for_bookable_offer(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) product = create_product_with_thing_type() offer = create_offer_with_thing_product(venue, product=product) stock = create_stock(offer=offer) mediation = create_mediation(offer) repository.save(mediation, stock) # When offer_json_response = get_non_free_thing_offer_with_active_mediation() # Then assert offer_json_response == { "mediationId": humanize(mediation.id), "offer": { "ageMax": None, "ageMin": None, "audioDisabilityCompliant": None, "bookingEmail": "*****@*****.**", "conditions": None, "dateCreated": format_into_utc_date(offer.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(offer.dateModifiedAtLastProvider), "description": None, "durationMinutes": None, "externalTicketOfficeUrl": None, "extraData": { "author": "Test Author" }, "fieldsUpdated": [], "id": humanize(offer.id), "idAtProviders": offer.idAtProviders, "isActive": True, "isDuo": False, "isNational": False, "lastProviderId": None, "mediaUrls": ["test/urls"], "mentalDisabilityCompliant": None, "motorDisabilityCompliant": None, "name": "Test Book", "productId": humanize(product.id), "thingName": "Test Book", "type": "ThingType.LIVRE_EDITION", "url": None, "venueCity": "Montreuil", "venueId": humanize(venue.id), "venueName": "La petite librairie", "visualDisabilityCompliant": None, "withdrawalDetails": None, }, }
def test_expect_booking_to_have_completed_url(self, app): # Given user = BeneficiaryGrant18Factory(email="*****@*****.**") offerer = OffererFactory() product = ThingProductFactory() offer = ThingOfferFactory( url="https://host/path/{token}?offerId={offerId}&email={email}", audioDisabilityCompliant=None, bookingEmail="*****@*****.**", extraData={"author": "Test Author"}, mediaUrls=["test/urls"], mentalDisabilityCompliant=None, motorDisabilityCompliant=None, name="Test Book", venue__managingOfferer=offerer, product=product, ) stock = ThingStockFactory(offer=offer, price=0, quantity=None) booking = IndividualBookingFactory(individualBooking__user=user, stock=stock, token="ABCDEF") # When response = TestClient(app.test_client()).with_session_auth( user.email).get("/bookings/" + humanize(booking.id)) # Then assert response.status_code == 200 completed_url = "https://host/path/ABCDEF?offerId={}&[email protected]".format( humanize(offer.id)) assert "validationToken" not in response.json["stock"]["offer"] assert response.json == { "amount": 0.0, "cancellationDate": None, "cancellationReason": None, "completedUrl": completed_url, "cancellationLimitDate": None, "dateCreated": format_into_utc_date(booking.dateCreated), "dateUsed": None, "id": humanize(booking.id), "isCancelled": False, "isEventExpired": False, "isUsed": False, "mediation": None, "offererId": humanize(offer.venue.managingOffererId), "quantity": 1, "reimbursementDate": None, "stock": { "beginningDatetime": None, "bookingLimitDatetime": None, "dateCreated": format_into_utc_date(stock.dateCreated), "dateModified": format_into_utc_date(stock.dateModified), "dateModifiedAtLastProvider": format_into_utc_date(stock.dateModifiedAtLastProvider), "fieldsUpdated": [], "id": humanize(stock.id), "idAtProviders": None, "isBookable": True, "isEventExpired": False, "isSoftDeleted": False, "lastProviderId": None, "offer": { "ageMax": None, "ageMin": None, "audioDisabilityCompliant": None, "bookingEmail": "*****@*****.**", "conditions": None, "dateCreated": format_into_utc_date(offer.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date(offer.dateModifiedAtLastProvider), "description": product.description, "durationMinutes": None, "externalTicketOfficeUrl": None, "extraData": { "author": "Test Author" }, "fieldsUpdated": [], "hasBookingLimitDatetimesPassed": False, "id": humanize(offer.id), "idAtProviders": offer.idAtProviders, "isActive": True, "isBookable": True, "isDigital": True, "isDuo": False, "isEducational": False, "isEvent": False, "isNational": False, "lastProviderId": None, "mediaUrls": ["test/urls"], "mentalDisabilityCompliant": None, "motorDisabilityCompliant": None, "name": "Test Book", "productId": humanize(offer.product.id), "stocks": [{ "beginningDatetime": None, "bookingLimitDatetime": None, "dateCreated": format_into_utc_date(stock.dateCreated), "dateModified": format_into_utc_date(stock.dateModified), "dateModifiedAtLastProvider": format_into_utc_date(stock.dateModifiedAtLastProvider), "fieldsUpdated": [], "id": humanize(stock.id), "idAtProviders": None, "isBookable": True, "isEventExpired": False, "isSoftDeleted": False, "lastProviderId": None, "offerId": humanize(offer.id), "price": 0.0, "quantity": None, "remainingQuantity": "unlimited", }], "subcategoryId": "SUPPORT_PHYSIQUE_FILM", "thumbUrl": None, "url": "https://host/path/{token}?offerId={offerId}&email={email}", "validation": "APPROVED", "venue": { "address": "1 boulevard Poissonnière", "audioDisabilityCompliant": False, "bannerMeta": None, "bannerUrl": None, "bookingEmail": None, "city": "Paris", "comment": None, "dateCreated": format_into_utc_date(offer.venue.dateCreated), "dateModifiedAtLastProvider": format_into_utc_date( offer.venue.dateModifiedAtLastProvider), "departementCode": "75", "description": offer.venue.description, "fieldsUpdated": [], "id": humanize(offer.venue.id), "idAtProviders": None, "isPermanent": False, "isVirtual": False, "lastProviderId": None, "latitude": 48.87004, "longitude": 2.3785, "managingOffererId": humanize(offer.venue.managingOffererId), "mentalDisabilityCompliant": False, "motorDisabilityCompliant": False, "name": offer.venue.name, "postalCode": "75000", "publicName": offer.venue.publicName, "siret": offer.venue.siret, "thumbCount": 0, "venueLabelId": None, "venueTypeId": None, "visualDisabilityCompliant": False, "venueTypeCode": offer.venue.venueTypeCode.value, "withdrawalDetails": None, }, "venueId": humanize(offer.venue.id), "visualDisabilityCompliant": False, "withdrawalDetails": None, }, "offerId": humanize(offer.id), "price": 0.0, "quantity": None, "remainingQuantity": "unlimited", }, "stockId": humanize(stock.id), "token": booking.token, "userId": humanize(user.id), "venueId": humanize(offer.venue.id), }