def should_not_connect_venue_when_venue_has_no_siret(self, app): # Given offerer = create_offerer() venue = create_venue(offerer, siret=None, is_virtual=True) provider = activate_provider("LibrairesStocks") repository.save(venue) self.find_by_id.return_value = venue stock_repository = MagicMock() provider_type = LibrairesStocks venue_provider_payload = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } # when with pytest.raises(ApiErrors) as error: connect_venue_to_provider(provider_type, stock_repository, venue_provider_payload, self.find_by_id) # then assert error.value.errors["provider"] == [ "L’importation d’offres avec LesLibraires n’est pas disponible sans SIRET associé au lieu. Ajoutez un SIRET pour pouvoir importer les offres." ]
def should_raise_an_error(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) provider = create_provider(local_class="TestLocalProvider") repository.save(venue, provider) self.find_by_id.return_value = venue stock_repository = MagicMock() provider_type = TestLocalProvider venue_provider_payload = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } # When with pytest.raises(ApiErrors) as error: connect_venue_to_provider(provider_type, stock_repository, venue_provider_payload, self.find_by_id) # Then assert error.value.errors["provider"] == [ "Provider non pris en charge" ]
def should_connect_venue_when_synchronization_is_allowed(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) provider = activate_provider("PraxielStocks") repository.save(venue) self.find_by_id.return_value = venue stock_repository = MagicMock() stock_repository.can_be_synchronized.return_value = True provider_type = PraxielStocks venue_provider_payload = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } # When connect_venue_to_provider(provider_type, stock_repository, venue_provider_payload, self.find_by_id) # Then praxiel_venue_provider = VenueProvider.query.one() assert praxiel_venue_provider.venue == venue
def should_not_connect_venue_when_synchronization_is_not_allowed( self, app): # Given offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") provider = activate_provider("PraxielStocks") repository.save(venue) self.find_by_id.return_value = venue stock_repository = MagicMock() stock_repository.can_be_synchronized.return_value = False provider_type = PraxielStocks venue_provider_payload = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } # when with pytest.raises(ApiErrors) as error: connect_venue_to_provider(provider_type, stock_repository, venue_provider_payload, self.find_by_id) # then assert error.value.errors["provider"] == [ "L’importation d’offres avec Praxiel/Inférence n’est pas disponible pour le SIRET 12345678912345" ]
def create_venue_provider(): venue_provider_payload = request.json check_new_venue_provider_information(venue_provider_payload) provider_id = dehumanize(venue_provider_payload["providerId"]) provider = get_provider_enabled_for_pro_by_id(provider_id) check_existing_provider(provider) provider_class = getattr(pcapi.local_providers, provider.localClass) if provider_class == AllocineStocks: new_venue_provider = connect_venue_to_allocine( venue_provider_payload, find_by_id, get_allocine_theaterId_for_venue) else: stock_provider_repository = _get_stock_provider_repository( provider_class) new_venue_provider = connect_venue_to_provider( provider_class, stock_provider_repository, venue_provider_payload, find_by_id) _run_first_synchronization(new_venue_provider) return jsonify( as_dict(new_venue_provider, includes=VENUE_PROVIDER_INCLUDES)), 201