コード例 #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
コード例 #2
0
def test_should_return_error_message_when_postal_code_is_invalid():
    # Given
    offerer = create_offerer(postal_code="fgvbhjnk")
    api_errors = ApiErrors()

    # When
    api_error = validate(offerer, api_errors)

    # Then
    assert api_error.errors["postalCode"] == ["Ce code postal est invalide"]
コード例 #3
0
def test_should_not_return_error_message_when_postal_code_is_valid():
    # Given
    offerer = create_offerer(postal_code="75000")
    api_errors = ApiErrors()

    # When
    api_error = validate(offerer, api_errors)

    # Then
    assert api_error.errors == {}