Example #1
0
def get_bookings_csv():
    only_digital_venues = request.args.get('onlyDigitalVenues', False)

    try:
        venue_id = dehumanize(request.args.get('venueId', None))
        offer_id = dehumanize(request.args.get('offerId', None))
    except ValueError:
        errors = ApiErrors()
        errors.add_error('global', 'Les identifiants sont incorrects')
        errors.status_code = 400
        raise errors

    try:
        if request.args.get('dateFrom', None):
            date_from = dateutil.parser.parse(request.args.get('dateFrom'))
        else:
            date_from = None
        if request.args.get('dateTo', None):
            date_to = dateutil.parser.parse(request.args.get('dateTo'))
        else:
            date_to = None
    except ValueError:
        errors = ApiErrors()
        errors.add_error('global', 'Les dates sont incorrectes')
        errors.status_code = 400
        raise errors
    check_rights_to_get_bookings_csv(current_user, venue_id, offer_id)

    query = filter_query_where_user_is_user_offerer_and_is_validated(
        Offerer.query, current_user)
    if only_digital_venues:
        bookings = chain(*list(
            map(
                lambda offerer: find_all_digital_bookings_for_offerer(
                    offerer.id, offer_id, date_from, date_to), query)))
    else:
        bookings = chain(*list(
            map(
                lambda offerer: find_all_offerer_bookings(
                    offerer.id, venue_id, offer_id, date_from, date_to),
                query)))

    bookings_csv = generate_bookings_details_csv(bookings)

    return bookings_csv.encode('utf-8-sig'), \
           200, \
           {'Content-type': 'text/csv; charset=utf-8;',
            'Content-Disposition': 'attachment; filename=reservations_pass_culture.csv'}
        def when_api_error_raise_from_payload_validation(
                self, validate_new_venue_provider_information, app):
            # given
            api_errors = ApiErrors()
            api_errors.status_code = 400
            api_errors.add_error('errors', 'error received')

            validate_new_venue_provider_information.side_effect = api_errors

            user = create_user(is_admin=True, can_book_free_offers=False)
            PcObject.save(user)
            auth_request = TestClient(app.test_client()) \
                .with_auth(email=user.email)
            venue_provider_data = {
                'providerId': 'B9',
                'venueId': 'B9',
                'venueIdAtOfferProvider': '77567146400110'
            }

            # when
            response = auth_request.post('/venueProviders',
                                         json=venue_provider_data)

            # then
            assert response.status_code == 400
            assert ['error received'] == response.json['errors']
Example #3
0
def _validate_existing_provider(provider_id: str):
    provider = find_provider_by_id(provider_id)
    is_provider_available_for_pro_usage = provider and provider.isActive and provider.enabledForPro
    if not is_provider_available_for_pro_usage:
        errors = ApiErrors()
        errors.status_code = 400
        errors.add_error('provider', "Cette source n'est pas disponible")
        raise errors
Example #4
0
def _validate_existing_venue_provider(provider_id: int, venue_id: int, venue_id_at_offer_provider: str):
    is_existing_venue_provider = find_venue_provider(provider_id,
                                                     venue_id,
                                                     venue_id_at_offer_provider)
    if is_existing_venue_provider:
        errors = ApiErrors()
        errors.status_code = 400
        errors.add_error('venueProvider', "Votre lieu est déjà lié à cette source")
        raise errors
Example #5
0
def check_valid_signin(identifier: str, password: str):
    errors = ApiErrors()
    errors.status_code = 401

    if identifier is None:
        errors.add_error('identifier', 'Identifiant manquant')
    if password is None:
        errors.add_error('password', 'Mot de passe manquant')

    errors.maybe_raise()
Example #6
0
def validate_new_venue_provider_information(payload: json):
    errors = ApiErrors()
    errors.status_code = 400

    if 'venueIdAtOfferProvider' not in payload:
        errors.add_error('venueIdAtOfferProvider', 'Ce champ est obligatoire')
    if 'venueId' not in payload:
        errors.add_error('venueId', 'Ce champ est obligatoire')
    if 'providerId' not in payload:
        errors.add_error('providerId', 'Ce champ est obligatoire')

    errors.maybe_raise()

    provider_id = dehumanize(payload.get('providerId'))
    venue_id = dehumanize(payload.get('venueId'))
    venue_id_at_offer_provider = payload.get('venueIdAtOfferProvider')

    _validate_existing_provider(provider_id)
    _validate_existing_venue_provider(provider_id, venue_id, venue_id_at_offer_provider)