Exemple #1
0
def get_export_offerers():
    check_user_is_admin(current_user)

    params_keys = [
        'sirens', 'dpts', 'zip_codes', 'from_date', 'to_date', 'has_siren',
        'has_not_virtual_venue', 'has_validated_venue', 'has_venue_with_siret',
        'offer_status', 'is_validated', 'has_validated_user',
        'has_bank_information', 'is_active', 'has_validated_user_offerer'
    ]
    params = {}

    for key in params_keys:
        params[key] = request.json.get(key, None)

    check_get_offerers_params(params)
    offerers = find_filtered_offerers(
        sirens=params['sirens'],
        dpts=params['dpts'],
        zip_codes=params['zip_codes'],
        from_date=params['from_date'],
        to_date=params['to_date'],
        has_siren=params['has_siren'],
        has_not_virtual_venue=params['has_not_virtual_venue'],
        has_validated_venue=params['has_validated_venue'],
        has_venue_with_siret=params['has_venue_with_siret'],
        offer_status=params['offer_status'],
        is_validated=params['is_validated'],
        has_validated_user=params['has_validated_user'],
        has_bank_information=params['has_bank_information'],
        is_active=params['is_active'],
        has_validated_user_offerer=params['has_validated_user_offerer'])

    return jsonify([as_dict(offerer) for offerer in offerers]), 200
Exemple #2
0
def test_check_get_offerers_params_does_not_raise_api_error_if_good_params(
        app):
    # given
    params = {}
    params['sirens'] = ['123456789', '123454789', '789654123']
    params['dpts'] = ['12', '2A', '56']
    params['zip_codes'] = ['12111', '2A250', '56698']
    params['from_date'] = '2018-05-30'
    params['to_date'] = '2018-12-31'
    params['has_siren'] = True
    params['has_not_virtual_venue'] = False
    params['has_validated_venue'] = True
    params['has_venue_with_siret'] = True
    params['offer_status'] = 'EXPIRED'
    params['is_validated'] = True
    params['has_validated_user'] = True
    params['has_bank_information'] = False
    params['is_active'] = True
    params['has_validated_user_offerer'] = False

    # when
    try:
        check_get_offerers_params(params)

    except ApiErrors:
        # Then
        assert pytest.fail("Should not fail with valid params")
Exemple #3
0
def test_check_get_offerers_params_does_not_raise_api_error_if_empty_params(
        app):
    # given
    params = {}

    # when
    try:
        check_get_offerers_params(params)

    except ApiErrors:
        # Then
        assert pytest.fail("Should not fail with valid params")
Exemple #4
0
def test_check_get_offerers_params_raises_api_error_if_letter_in_siren(app):
    # given
    not_valid_siren = {}
    not_valid_siren['sirens'] = ['78sang40R']

    # when
    with pytest.raises(ApiErrors) as errors:
        check_get_offerers_params(not_valid_siren)

    # then
    assert errors.value.errors['sirens'] == \
           ['sirens is a list of 9 digits : ["123456789", "789654123"]']
Exemple #5
0
def test_check_get_offerers_params_doesnt_raise_api_error_for_valid_siren(app):
    # given
    valid_siren = {}
    valid_siren['sirens'] = ["123456789", "789654123"]

    # when
    try:
        check_get_offerers_params(valid_siren)

    except ApiErrors:
        # Then
        assert pytest.fail("Should not fail with valid params")
Exemple #6
0
def test_check_get_offerers_params_raises_api_error_if_dpts_is_not_list(app):
    # given
    not_valid_dpts = {}
    not_valid_dpts['dpts'] = '93'
    # when
    with pytest.raises(ApiErrors) as errors:
        check_get_offerers_params(not_valid_dpts)

    # then
    assert errors.value.errors['dpts'] == [
        'dpts is a list of type xx or xxx (2 or 3 digits), or 2A, or 2B :\
                ["34", "37"]'
    ]
Exemple #7
0
def test_check_get_offerers_params_doesnt_raise_api_error_for_valid_dpts_in(
        app):
    # given
    valid_dpts = {}
    valid_dpts['dpts'] = ['93', '17', '01', '2a', '2B', '978']

    # when
    try:
        check_get_offerers_params(valid_dpts)

    except ApiErrors:
        # Then
        assert pytest.fail("Should not fail with valid params")
Exemple #8
0
def test_check_get_offerers_params_raises_api_error_if_not_valid_date(app):
    # given
    not_valid_date = {}
    not_valid_date['to_date'] = '12/52-0001'

    # when
    with pytest.raises(ApiErrors) as errors:
        check_get_offerers_params(not_valid_date)

    # then
    assert errors.value.errors['date_format'] == [
        'to_date and from_date are of type yyyy-mm-dd'
    ]
Exemple #9
0
def test_check_get_offerers_params_raises_api_error_if_not_valid_offer_status_params(
        app):
    # given
    not_valid_offer_status_param = {}
    not_valid_offer_status_param['offer_status'] = 'I\'m not a boolean'

    # when
    with pytest.raises(ApiErrors) as errors:
        check_get_offerers_params(not_valid_offer_status_param)

    # then
    assert errors.value.errors['offer_status'] == [
        'offer_status accepte ALL ou VALID ou WITHOUT ou EXPIRED'
    ]
Exemple #10
0
def test_check_get_offerers_params_raises_api_error_if_not_valid_is_active_params(
        app):
    # given
    not_valid_is_active_param = {}
    not_valid_is_active_param['is_active'] = 'I\'m not a boolean'

    # when
    with pytest.raises(ApiErrors) as errors:
        check_get_offerers_params(not_valid_is_active_param)

    # then
    assert errors.value.errors['is_active'] == [
        'is_active is a boolean, it accepts True or False'
    ]
Exemple #11
0
def test_check_get_offerers_params_raises_api_error_if_not_valid_zip_codes(
        app):
    # given
    not_valid_zip_codes = {}
    not_valid_zip_codes['zip_codes'] = ['69000', '13020', '78sang40RpZ', 78140]

    # when
    with pytest.raises(ApiErrors) as errors:
        check_get_offerers_params(not_valid_zip_codes)

    # then
    assert errors.value.errors['zip_codes'] == \
           ['zip_codes is a list of type xxxxx (5 digits, ex: 78140 ou 2a000) : \
        ["78140", "69007"]'                           ]
Exemple #12
0
def test_check_get_offerers_params_doesnt_raise_api_error_for_valid_zip_codes(
        app):
    # given
    valid_zip_codes = {}
    valid_zip_codes['zip_codes'] = [
        '69000', '13020', '2a250', '2B456', '00007'
    ]

    # when
    try:
        check_get_offerers_params(valid_zip_codes)

    except ApiErrors:
        # Then
        assert pytest.fail("Should not fail with valid params")