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_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 test_success_if_digital_product_and_virtual_venue(self): venue = factories.VirtualVenueFactory() user_offerer = factories.UserOffererFactory(offerer=venue.managingOfferer) product = factories.DigitalProductFactory() data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), productId=humanize(product.id), ) api.create_offer(data, user_offerer.user) # should not fail
def test_fail_if_user_not_related_to_offerer(self): venue = factories.VenueFactory() user = users_factories.UserFactory() data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), ) with pytest.raises(api_errors.ApiErrors) as error: api.create_offer(data, user) err = "Vous n'avez pas les droits d'accès suffisant pour accéder à cette information." assert error.value.errors["global"] == [err]
def test_fail_if_unknown_venue(self): user = users_factories.UserFactory() data = offers_serialize.PostOfferBodyModel( venueId=humanize(1), name="An awful offer", type=str(offer_type.EventType.ACTIVATION), ) with pytest.raises(api_errors.ApiErrors) as error: api.create_offer(data, user) err = "Aucun objet ne correspond à cet identifiant dans notre base de données" assert error.value.errors["global"] == [err]
def test_create_activation_offer(self): user = users_factories.UserFactory(isAdmin=True) venue = factories.VenueFactory() data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), name="An offer he can't refuse", type=str(offer_type.EventType.ACTIVATION), ) offer = api.create_offer(data, user) assert offer.type == str(offer_type.EventType.ACTIVATION)
def test_fail_if_physical_product_and_virtual_venue(self): venue = factories.VirtualVenueFactory() user_offerer = factories.UserOffererFactory(offerer=venue.managingOfferer) product = factories.ProductFactory() data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), productId=humanize(product.id), ) with pytest.raises(api_errors.ApiErrors) as error: api.create_offer(data, user_offerer.user) err = 'Une offre physique ne peut être associée au lieu "Offre numérique"' assert error.value.errors["venue"] == [err]
def test_fail_to_create_activation_offer_if_no_admin(self): 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 pathetic offer", type=str(offer_type.EventType.ACTIVATION), ) with pytest.raises(api_errors.ApiErrors) as error: api.create_offer(data, user) err = "Seuls les administrateurs du pass Culture peuvent créer des offres d'activation" assert error.value.errors["type"] == [err]
def test_success_if_physical_product_and_physical_venue(self): venue = factories.VenueFactory() user_offerer = factories.UserOffererFactory( offerer=venue.managingOfferer) product = factories.ProductFactory() data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), productId=humanize(product.id), audioDisabilityCompliant=True, mentalDisabilityCompliant=True, motorDisabilityCompliant=True, visualDisabilityCompliant=True, ) api.create_offer(data, user_offerer.user) # should not fail
def test_create_offer_from_scratch(self): 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), ) 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 not offer.bookingEmail
def test_fail_if_digital_product_and_physical_venue(self): venue = factories.VenueFactory() user_offerer = factories.UserOffererFactory( offerer=venue.managingOfferer) product = factories.DigitalProductFactory() data = offers_serialize.PostOfferBodyModel( venueId=humanize(venue.id), productId=humanize(product.id), audioDisabilityCompliant=True, mentalDisabilityCompliant=True, motorDisabilityCompliant=True, visualDisabilityCompliant=True, ) with pytest.raises(api_errors.ApiErrors) as error: api.create_offer(data, user_offerer.user) err = 'Une offre numérique doit obligatoirement être associée au lieu "Offre numérique"' assert error.value.errors["venue"] == [err]
def test_create_offer_from_existing_product(self): 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), ) offer = api.create_offer(data, user) assert offer.name == "An excellent offer" assert offer.type == str(offer_type.EventType.CINEMA) assert offer.product == product