Beispiel #1
0
def validate(model: Model) -> ApiErrors:
    api_errors = validate_generic(model)

    if api_errors.errors:
        return api_errors

    if isinstance(model, HasAddressMixin):
        api_errors = has_address_mixin.validate(model, api_errors)

    if isinstance(model, BankInformation):
        api_errors = bank_information.validate(model, api_errors)
    elif isinstance(model, Offer):
        api_errors = offer.validate(model, api_errors)
    elif isinstance(model, Offerer):
        api_errors = offerer.validate(model, api_errors)
    elif isinstance(model, Product):
        api_errors = product.validate(model, api_errors)
    elif isinstance(model, Stock):
        api_errors = stock.validate(model, api_errors)
    elif isinstance(model, User):
        api_errors = user.validate(model, api_errors)
    elif isinstance(model, VenueSQLEntity):
        api_errors = venue.validate(model, api_errors)

    return api_errors
Beispiel #2
0
def test_should_not_return_error_message_when_offer_is_valid():
    # Given
    offerer = create_offerer()
    venue = create_venue(offerer, is_virtual=True)
    thing_offer = create_offer_with_thing_product(venue, is_digital=True)
    api_errors = ApiErrors()

    # When
    api_error = validate(thing_offer, api_errors)

    # Then
    assert api_error.errors == {}
Beispiel #3
0
def test_should_return_error_message_when_offer_is_digital_and_his_venue_is_not_virtual(
):
    # Given
    offerer = create_offerer()
    venue = create_venue(offerer, is_virtual=False)
    thing_offer = create_offer_with_thing_product(venue, is_digital=True)
    api_errors = ApiErrors()

    # When
    api_error = validate(thing_offer, api_errors)

    # Then
    assert api_error.errors["venue"] == [
        'Une offre numérique doit obligatoirement être associée au lieu "Offre numérique"'
    ]
Beispiel #4
0
def test_should_return_error_message_when_offer_is_digital_and_its_type_is_offline_only(
):
    # Given
    offerer = create_offerer()
    venue = create_venue(offerer, is_virtual=True)
    thing_offer = create_offer_with_thing_product(venue,
                                                  is_digital=True,
                                                  is_offline_only=True)
    api_errors = ApiErrors()

    # When
    api_error = validate(thing_offer, api_errors)

    # Then
    assert api_error.errors["url"] == [
        "Une offre de sous-catégorie Carte cinéma multi-séances ne peut pas être numérique"
    ]
Beispiel #5
0
def test_should_return_error_messages_when_offer_is_digital_and_offline_and_venue_is_not_virtual(
):
    # Given
    offerer = create_offerer()
    venue = create_venue(offerer, is_virtual=False)
    thing_offer = create_offer_with_thing_product(venue,
                                                  is_digital=True,
                                                  is_offline_only=True)
    api_errors = ApiErrors()

    # When
    api_error = validate(thing_offer, api_errors)

    # Then
    assert api_error.errors == {
        "url": [
            "Une offre de sous-catégorie Carte cinéma multi-séances ne peut pas être numérique"
        ],
        "venue": [
            'Une offre numérique doit obligatoirement être associée au lieu "Offre numérique"'
        ],
    }