def _setup_venues_for_users(self): offerer = offers_factories.OffererFactory() user_offerer = offers_factories.UserOffererFactory(offerer=offerer) venue = offers_factories.VenueFactory(name="venue", managingOfferer=offerer) offerer_not_validated = offers_factories.OffererFactory( validationToken="token") offers_factories.UserOffererFactory(user=user_offerer.user, offerer=offerer_not_validated) venue_not_validated = offers_factories.VenueFactory( name="venue_not_validated", managingOfferer=offerer_not_validated) other_offerer = offers_factories.OffererFactory() other_user_offerer = offers_factories.UserOffererFactory( offerer=other_offerer) other_venue = offers_factories.VenueFactory( name="other_venue", managingOfferer=other_offerer) other_offerer_not_validated = offers_factories.OffererFactory( validationToken="other_token") offers_factories.UserOffererFactory( user=other_user_offerer.user, offerer=other_offerer_not_validated) other_venue_not_validated = offers_factories.VenueFactory( name="other_venue_not_validated", managingOfferer=other_offerer_not_validated, ) return { "venue": venue, "venue_not_validated": venue_not_validated, "other_venue": other_venue, "other_venue_not_validated": other_venue_not_validated, }
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
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_reimburses_95_percent_for_book_product_when_bookings_exceed_100000_euros( self): # Given cutoff = datetime.datetime.now() before_cutoff = cutoff - datetime.timedelta(days=1) beneficiary = users_factories.BeneficiaryGrant18Factory( email="*****@*****.**") offerer1 = offers_factories.OffererFactory(siren="123456789") offers_factories.BankInformationFactory( bic="BDFEFR2LCCB", iban="FR7630006000011234567890189", offerer=offerer1) venue1 = offers_factories.VenueFactory(managingOfferer=offerer1, siret="12345678912345") venue2 = offers_factories.VenueFactory(managingOfferer=offerer1, siret="98765432154321") venue3 = offers_factories.VenueFactory(managingOfferer=offerer1, siret="98123432154321") product = offers_factories.ThingProductFactory( subcategoryId=subcategories.LIVRE_PAPIER.id) offer1 = offers_factories.ThingOfferFactory(venue=venue1, product=product) offer2 = offers_factories.ThingOfferFactory(venue=venue2, product=product) offer3 = offers_factories.ThingOfferFactory(venue=venue3, product=product) paying_stock1 = offers_factories.ThingStockFactory(offer=offer1, price=10000) paying_stock2 = offers_factories.ThingStockFactory(offer=offer2, price=10000) paying_stock3 = offers_factories.ThingStockFactory(offer=offer3, price=100000) offers_factories.ThingStockFactory(offer=offer1, price=0) beneficiary.deposit.amount = 120000 repository.save(beneficiary.deposit) bookings_factories.UsedBookingFactory(user=beneficiary, stock=paying_stock1, dateUsed=before_cutoff, quantity=1) bookings_factories.UsedBookingFactory(user=beneficiary, stock=paying_stock2, dateUsed=before_cutoff, quantity=1) bookings_factories.UsedBookingFactory(user=beneficiary, stock=paying_stock3, dateUsed=before_cutoff, quantity=1) # When generate_new_payments(cutoff, batch_date=datetime.datetime.now()) # Then pending = get_pending_payments() assert pending.count() == 3 assert total_amount(pending) == 115000 assert get_not_processable_payments().count() == 0
def test_venues_with_missing_and_accepted_bank_information(self): offerer = offerers_factories.OffererFactory() offers_factories.VirtualVenueFactory(managingOfferer=offerer) offers_factories.VenueFactory(managingOfferer=offerer) venue_with_rejected_bank_information = offers_factories.VenueFactory(managingOfferer=offerer) offers_factories.BankInformationFactory( venue=venue_with_rejected_bank_information, status=BankInformationStatus.ACCEPTED ) assert has_physical_venue_without_draft_or_accepted_bank_information(offerer_id=offerer.id)
def test_delete_cascade_venue_should_remove_synchronization_to_provider(): # Given venue = offers_factories.VenueFactory() venue_to_delete = offers_factories.VenueFactory() offerers_factories.VenueProviderFactory(venue=venue_to_delete) offerers_factories.VenueProviderFactory(venue=venue) # When delete_cascade_venue_by_id(venue_to_delete.id) # Then assert Offerer.query.count() == 2 assert Venue.query.count() == 1 assert VenueProvider.query.count() == 1 assert Provider.query.count() > 0
def test_delete_cascade_venue_should_remove_mediations_of_managed_offers(): # Given venue = offers_factories.VenueFactory() venue_to_delete = offers_factories.VenueFactory() offers_factories.MediationFactory(offer__venue=venue_to_delete) offers_factories.MediationFactory(offer__venue=venue) # When delete_cascade_venue_by_id(venue_to_delete.id) # Then assert Offerer.query.count() == 2 assert Venue.query.count() == 1 assert Offer.query.count() == 1 assert Mediation.query.count() == 1
def test_upload_image(self, mock_local_dir, app, client): """ Check that the image upload works for a legit file (size and type): * API returns a 204 status code * the file has been saved to disk * venue's banner information have been updated """ user_offerer = offers_factories.UserOffererFactory() venue = offers_factories.VenueFactory(managingOfferer=user_offerer.offerer) image_content = (IMAGES_DIR / "mouette_landscape.jpg").read_bytes() file = {"banner": (io.BytesIO(image_content), "jerome_le_banner.jpg")} client = client.with_session_auth(email=user_offerer.user.email) url = f"/venues/{humanize(venue.id)}/banner" with tempfile.TemporaryDirectory() as tmpdirname: with override_settings(OBJECT_STORAGE_URL=tmpdirname): settings.OBJECT_STORAGE_URL = tmpdirname mock_local_dir.return_value = pathlib.Path(tmpdirname) / settings.BASE_BUCKET_NAME response = client.post(url, files=file) assert response.status_code == 204 venue = Venue.query.get(venue.id) with open(venue.bannerUrl, mode="rb") as f: assert f.read() == image_content assert venue.bannerMeta == { "content_type": "jpeg", "file_name": "jerome_le_banner.jpg", "author_id": user_offerer.user.id, }
def test_accepts_request_with_price(price, expected_price, app): ProviderFactory(name="Pass Culture API Stocks", localClass="PCAPIStocks") offerer = offers_factories.OffererFactory(siren=123456789) venue = offers_factories.VenueFactory(managingOfferer=offerer) offer_to_update = offers_factories.OfferFactory( product__idAtProviders="123456789", product__subcategoryId="LIVRE_PAPIER", idAtProviders=f"123456789@{venue.id}", product__extraData={"prix_livre": expected_price}, venue=venue, ) ApiKeyFactory(offerer=offerer) test_client = TestClient(app.test_client()) test_client.auth_header = { "Authorization": f"Bearer {DEFAULT_CLEAR_API_KEY}" } response = test_client.post(f"/v2/venue/{venue.id}/stocks", json={ "stocks": [{ "ref": "123456789", "available": 4, "price": price }] }) assert response.status_code == 204 assert offer_to_update.stocks[0].price == expected_price
def test_returns_404_if_api_key_cant_access_venue(mock_synchronize_stocks, app): offerer = offers_factories.OffererFactory(siren=123456789) offers_factories.VenueFactory(managingOfferer=offerer, id=3) offerer2 = offers_factories.OffererFactory(siren=123456780) ApiKeyFactory(offerer=offerer2) mock_synchronize_stocks.return_value = {} test_client = TestClient(app.test_client()) test_client.auth_header = { "Authorization": f"Bearer {DEFAULT_CLEAR_API_KEY}" } response1 = test_client.post( "/v2/venue/3/stocks", json={"stocks": [{ "ref": "123456789", "available": 4 }]}) response2 = test_client.post( "/v2/venue/123/stocks", json={"stocks": [{ "ref": "123456789", "available": 4 }]}) assert response1.status_code == 404 assert response2.status_code == 404 mock_synchronize_stocks.assert_not_called()
def test_response_serialization(app): user_offerer = offers_factories.UserOffererFactory( user__email="*****@*****.**", ) venue = offers_factories.VenueFactory(managingOfferer=user_offerer.offerer) # when response = TestClient(app.test_client()).with_session_auth(user_offerer.user.email).get("/venues") # then assert response.status_code == 200 assert "venues" in response.json assert len(response.json["venues"]) == 1 assert response.json["venues"][0] == { "id": humanize(venue.id), "managingOffererId": humanize(venue.managingOffererId), "name": venue.name, "offererName": user_offerer.offerer.name, "publicName": venue.publicName, "isVirtual": venue.isVirtual, "bookingEmail": venue.bookingEmail, "withdrawalDetails": venue.withdrawalDetails, "audioDisabilityCompliant": venue.audioDisabilityCompliant, "mentalDisabilityCompliant": venue.mentalDisabilityCompliant, "motorDisabilityCompliant": venue.motorDisabilityCompliant, "visualDisabilityCompliant": venue.visualDisabilityCompliant, }
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
def test_serialize_venue(): venue = offers_factories.VenueFactory( venueTypeCode="VISUAL_ARTS", contact__email="*****@*****.**", contact__website=None, contact__phone_number=None, contact__social_medias={ "facebook": None, "instagram": None, "snapchat": None, "twitter": "https://twitter.com/my.venue", }, ) serialized = appsearch.AppSearchBackend().serialize_venue(venue) assert serialized == { "id": venue.id, "name": venue.name, "offerer_name": venue.managingOfferer.name, "venue_type": venue.venueTypeCode.name, "position": f"{venue.latitude},{venue.longitude}", "description": venue.description, "email": "*****@*****.**", "twitter": "https://twitter.com/my.venue", "audio_disability": 0, "mental_disability": 0, "motor_disability": 0, "visual_disability": 0, }
def test_create_offer_from_existing_product( self, mocked_offer_creation_notification_to_admin): product = factories.ProductFactory( name="An excellent offer", type=str(offer_type.EventType.CINEMA), ) venue = factories.VenueFactory() offerer = venue.managingOfferer user_offerer = factories.UserOffererFactory(offerer=offerer) user = user_offerer.user data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), productId=humanize(product.id), externalTicketOfficeUrl="http://example.net", audioDisabilityCompliant=True, mentalDisabilityCompliant=True, motorDisabilityCompliant=True, visualDisabilityCompliant=True, ) offer = api.create_offer(data, user) assert offer.name == "An excellent offer" assert offer.type == str(offer_type.EventType.CINEMA) assert offer.product == product assert offer.externalTicketOfficeUrl == "http://example.net" assert offer.audioDisabilityCompliant assert offer.mentalDisabilityCompliant assert offer.motorDisabilityCompliant assert offer.visualDisabilityCompliant assert Offer.query.count() == 1 mocked_offer_creation_notification_to_admin.assert_called_once_with( offer, user)
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 test_venue_with_draft_bank_information(self): offerer = offerers_factories.OffererFactory() offers_factories.VirtualVenueFactory(managingOfferer=offerer) venue = offers_factories.VenueFactory(managingOfferer=offerer) offers_factories.BankInformationFactory(venue=venue, status=BankInformationStatus.DRAFT) assert not has_physical_venue_without_draft_or_accepted_bank_information(offerer_id=offerer.id)
def when_provider_api_not_available(self, mock_siret_can_be_synchronized, app): # Given user = user_factories.AdminFactory() venue = offer_factories.VenueFactory(siret="12345678912345") provider = offerers_factories.APIProviderFactory() venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) errors = ApiErrors() errors.status_code = 422 errors.add_error( "provider", "L’importation d’offres avec LesLibraires n’est pas disponible " "pour le SIRET 12345678912345", ) mock_siret_can_be_synchronized.side_effect = [errors] # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 422 assert response.json["provider"] == [ "L’importation d’offres avec LesLibraires n’est pas disponible pour le SIRET 12345678912345" ] assert VenueProvider.query.count() == 0
def when_add_allocine_pivot_is_missing(self, app): # Given venue = offer_factories.VenueFactory( managingOfferer__siren="775671464") user = user_factories.AdminFactory() provider = activate_provider("AllocineStocks") venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 404 assert response.json == { "allocine": [ "Ce lieu n'est pas autorisé à être synchronisé avec Allociné. Veuillez contacter le support si vous souhaitez le faire." ] } assert VenueProvider.query.count() == 0
def when_add_allocine_stocks_provider_with_no_price(self, app): # Given venue = offer_factories.VenueFactory( managingOfferer__siren="775671464") user = user_factories.AdminFactory() AllocinePivotFactory(siret=venue.siret) provider = activate_provider("AllocineStocks") venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 400 assert response.json["price"] == [ "Il est obligatoire de saisir un prix." ] assert VenueProvider.query.count() == 0
def when_venue_provider_is_successfully_created( self, mock_siret_can_be_synchronized, mock_synchronize_venue_provider, app): # Given user = user_factories.AdminFactory() venue = offer_factories.VenueFactory(siret="12345678912345") provider = offerers_factories.APIProviderFactory() venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } mock_siret_can_be_synchronized.return_value = True auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 201 venue_provider = VenueProvider.query.one() assert venue_provider.venueId == venue.id assert venue_provider.providerId == provider.id assert venue_provider.venueIdAtOfferProvider == "12345678912345" assert "id" in response.json venue_provider_id = response.json["id"] mock_synchronize_venue_provider.assert_called_once_with( dehumanize(venue_provider_id))
def test_when_add_same_provider(self, mock_siret_can_be_synchronized, mock_synchronize_venue_provider, app): # Given user = user_factories.AdminFactory() venue = offer_factories.VenueFactory(siret="12345678912345") provider = offerers_factories.APIProviderFactory() venue_provider = create_venue_provider( venue, provider, venue_id_at_offer_provider="12345678912345") repository.save(venue_provider) auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } mock_siret_can_be_synchronized.return_value = True # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 400 assert response.json == { "global": ["Votre lieu est déjà lié à cette source"] } assert venue.venueProviders[0].provider.id == provider.id
def test_create_valid_educational_offer(self, app): # Given venue = offers_factories.VenueFactory() offerer = venue.managingOfferer offers_factories.UserOffererFactory(offerer=offerer, user__email="*****@*****.**") # When data = { "venueId": humanize(venue.id), "bookingEmail": "*****@*****.**", "durationMinutes": 60, "name": "La pièce de théâtre", "subcategoryId": subcategories.SPECTACLE_REPRESENTATION.id, "extraData": {"toto": "text"}, "externalTicketOfficeUrl": "http://example.net", "audioDisabilityCompliant": False, "mentalDisabilityCompliant": True, "motorDisabilityCompliant": False, "visualDisabilityCompliant": False, "isEducational": True, } client = TestClient(app.test_client()).with_session_auth("*****@*****.**") response = client.post("/offers", json=data) # Then assert response.status_code == 201 offer_id = dehumanize(response.json["id"]) offer = Offer.query.get(offer_id) assert offer.isEducational
def test_create_offer_from_scratch( self, mocked_offer_creation_notification_to_admin): venue = factories.VenueFactory() offerer = venue.managingOfferer user_offerer = factories.UserOffererFactory(offerer=offerer) user = user_offerer.user data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), name="A pretty good offer", type=str(offer_type.EventType.CINEMA), externalTicketOfficeUrl="http://example.net", audioDisabilityCompliant=True, mentalDisabilityCompliant=True, motorDisabilityCompliant=True, visualDisabilityCompliant=True, ) offer = api.create_offer(data, user) assert offer.name == "A pretty good offer" assert offer.venue == venue assert offer.type == str(offer_type.EventType.CINEMA) assert offer.product.owningOfferer == offerer assert offer.externalTicketOfficeUrl == "http://example.net" assert offer.audioDisabilityCompliant assert offer.mentalDisabilityCompliant assert offer.motorDisabilityCompliant assert offer.visualDisabilityCompliant assert not offer.bookingEmail assert Offer.query.count() == 1 mocked_offer_creation_notification_to_admin.assert_called_once_with( offer, user)
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 should_connect_to_allocine( self, app, ): # Given user = user_factories.AdminFactory() venue = offer_factories.VenueFactory(siret="12345678912345") AllocinePivotFactory(siret=venue.siret) provider = activate_provider("AllocineStocks") venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), "price": "33.33" } auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) # When auth_request.post("/venueProviders", json=venue_provider_data) # Then assert len(venue.venueProviders) == 1 assert venue.venueProviders[0].provider == provider
def test_create_event_offer(self, app): # Given venue = offers_factories.VenueFactory() offerer = venue.managingOfferer offers_factories.UserOffererFactory(offerer=offerer, user__email="*****@*****.**") # When data = { "venueId": humanize(venue.id), "bookingEmail": "*****@*****.**", "durationMinutes": 60, "name": "La pièce de théâtre", "type": str(EventType.SPECTACLE_VIVANT), "extraData": {"toto": "text"}, } client = TestClient(app.test_client()).with_auth("*****@*****.**") response = client.post("/offers", json=data) # Then assert response.status_code == 201 offer_id = dehumanize(response.json["id"]) offer = Offer.query.get(offer_id) assert offer.bookingEmail == "*****@*****.**" assert offer.type == str(EventType.SPECTACLE_VIVANT) assert offer.extraData == {"toto": "text"} assert offer.venue == venue assert offer.product.durationMinutes == 60 assert offer.product.owningOfferer == offerer
def test_allocine_venue_provider_is_successfully_updated(self, app): # Given user_offerer = offer_factories.UserOffererFactory() user = user_offerer.user offerer = user_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 == 200 assert response.json["provider"]["id"] == humanize(provider.id) assert response.json["venueId"] == humanize(venue.id) assert response.json["quantity"] == updated_venue_provider_data["quantity"] assert response.json["price"] == updated_venue_provider_data["price"] assert response.json["isDuo"] == updated_venue_provider_data["isDuo"]
def when_add_allocine_stocks_provider_with_price_but_no_isDuo_config( self, app): # Given venue = offer_factories.VenueFactory( managingOfferer__siren="775671464") user = user_factories.AdminFactory() AllocinePivotFactory(siret=venue.siret) provider = activate_provider("AllocineStocks") venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), "price": "9.99" } auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 201 json = response.json assert "_sa_polymorphic_on" not in json venue_provider = VenueProvider.query.one() assert json["venueId"] == humanize(venue_provider.venueId)
def test_edit_venue_withdrawal_details_with_applied_on_all_offers( self, mocked_update_all_venue_offers_withdrawal_details_job, app): user_offerer = offers_factories.UserOffererFactory() venue = offers_factories.VenueFactory( name="old name", managingOfferer=user_offerer.offerer, ) auth_request = TestClient( app.test_client()).with_session_auth(email=user_offerer.user.email) venue_data = populate_missing_data_from_venue( { "name": "new name", "withdrawalDetails": "Ceci est un texte de modalités de retrait", "isWithdrawalAppliedOnAllOffers": True, }, venue, ) response = auth_request.patch("/venues/%s" % humanize(venue.id), json=venue_data) assert response.status_code == 200 assert venue.withdrawalDetails == "Ceci est un texte de modalités de retrait" mocked_update_all_venue_offers_withdrawal_details_job.assert_called_once_with( venue, "Ceci est un texte de modalités de retrait")
def when_add_allocine_stocks_provider_with_default_settings_at_import( self, app): # Given venue = offer_factories.VenueFactory( managingOfferer__siren="775671464") user = user_factories.AdminFactory() AllocinePivotFactory(siret=venue.siret) provider = activate_provider("AllocineStocks") venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), "price": "9.99", "quantity": 50, "isDuo": True, } auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 201 assert response.json["isDuo"] assert response.json["price"] == 9.99 assert response.json["quantity"] == 50