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
def test_should_return_no_error_message_when_iban_and_bic_are_valid_and_status_accepted( ): # Given bank_information = create_bank_information() api_errors = ApiErrors() # When api_error = validate(bank_information, api_errors) # Then assert api_error.errors == {}
def test_should_not_return_an_error_if_status_is_not_accepted_and_bic_and_iban_are_empty( ): # Given bank_information = create_bank_information( bic=None, iban=None, status=BankInformationStatus.DRAFT) api_errors = ApiErrors() # When api_error = validate(bank_information, api_errors) # Then assert api_error.errors == {}
def test_should_return_error_message_when_iban_is_invalid(): # Given bank_information = create_bank_information(iban="FR76") api_errors = ApiErrors() # When api_error = validate(bank_information, api_errors) # Then assert api_error.errors["iban"] == [ 'L’IBAN renseigné ("FR76") est invalide' ]
def test_should_return_error_message_when_bic_is_invalid(): # Given bank_information = create_bank_information(bic="1234") api_errors = ApiErrors() # When api_error = validate(bank_information, api_errors) # Then assert api_error.errors["bic"] == [ 'Le BIC renseigné ("1234") est invalide' ]
def test_should_return_error_messages_when_iban_and_bic_are_invalid(): # Given bank_information = create_bank_information(bic="1234", iban="1234") api_errors = ApiErrors() # When api_error = validate(bank_information, api_errors) # Then assert api_error.errors == { "bic": ['Le BIC renseigné ("1234") est invalide'], "iban": ['L’IBAN renseigné ("1234") est invalide'], }
def test_should_return_an_error_if_status_is_not_accepted_and_bic_or_iban_is_present( ): # Given bank_information = create_bank_information( status=BankInformationStatus.DRAFT) api_errors = ApiErrors() # When api_error = validate(bank_information, api_errors) # Then assert api_error.errors == { "bic": ["Le BIC doit être vide pour le statut DRAFT"], "iban": ["L’IBAN doit être vide pour le statut DRAFT"], }