def test_should_return_errors_when_valid_product(): # Given product = create_product_with_thing_type() # When api_errors = validate(product) # Then assert api_errors.errors == {}
def test_should_not_return_errors_when_valid_offerer(): # Given offerer = create_offerer(siren="123456789") # When api_errors = validate(offerer) # Then assert api_errors.errors == {}
def test_validate_bank_information_raises_an_error_if_iban_is_missing(): # given bank_information = create_bank_information(bic="BDFEFR2LCCB", iban=None) # when errors = entity_validator.validate(bank_information) # then assert errors.errors["iban"] == ["Cette information est obligatoire"]
def test_should_return_multiple_errors_when_invalid_offerer_and_address(): # Given offerer = create_offerer(siren="1", postal_code="123") # When api_errors = validate(offerer) # Then assert api_errors.errors == {"postalCode": ["Ce code postal est invalide"], "siren": ["Ce code SIREN est invalide"]}
def test_should_return_errors_when_invalid_stock(): # Given stock = create_stock(quantity=-1) # When api_errors = validate(stock) # Then assert api_errors.errors == {"quantity": ["La quantité doit être positive."]}
def test_should_return_errors_when_invalid_address(): # Given offerer = create_offerer(postal_code="abcde") # When api_errors = validate(offerer) # Then assert api_errors.errors == {"postalCode": ["Ce code postal est invalide"]}
def test_should_not_return_errors_when_valid_stock(): # Given stock = create_stock(quantity=1) # When api_errors = validate(stock) # Then assert api_errors.errors == {}
def test_should_not_return_errors_when_valid_address(): # Given offerer = create_offerer(postal_code="75000") # When api_errors = validate(offerer) # Then assert api_errors.errors == {}
def test_should_return_errors_when_invalid_product(): # Given product = create_product_with_thing_type(is_offline_only=True, is_digital=True) # When api_errors = validate(product) # Then assert api_errors.errors == {"url": ["Une offre de type Cinéma - cartes d'abonnement ne peut pas être numérique"]}
def test_should_not_return_errors_when_valid_bank_information(): # Given bank_information = create_bank_information(bic="AGFBFRCC", iban="FR7014508000301971798194B82") # When api_errors = validate(bank_information) # Then assert api_errors.errors == {}
def test_should_return_errors_when_invalid_offerer(): # Given offerer = create_offerer(siren="1") # When api_errors = validate(offerer) # Then assert api_errors.errors == {"siren": ["Ce code SIREN est invalide"]}
def test_should_return_errors_when_invalid_user(mock_count_users_by_email, app): # Given user = create_user(public_name="Jo") mock_count_users_by_email.return_value = 0 # When api_errors = validate(user) # Then assert api_errors.errors == {"publicName": ["Tu dois saisir au moins 3 caractères."]}
def test_validate_bank_information_raises_an_error_if_bic_is_missing(): # given bank_information = create_bank_information( bic=None, iban="FR7630006000011234567890189") # when errors = entity_validator.validate(bank_information) # then assert errors.errors["bic"] == ["Cette information est obligatoire"]
def test_should_return_errors_when_invalid_venue(): # Given offerer = create_offerer() venue = create_venue(offerer, siret="123") # When api_errors = validate(venue) # Then assert api_errors.errors == {"siret": ["Ce code SIRET est invalide : 123"]}
def test_should_not_return_errors_when_valid_venue(): # Given offerer = create_offerer() venue = create_venue(offerer, siret="44229377500031") # When api_errors = validate(venue) # Then assert api_errors.errors == {}
def test_should_not_return_errors_when_valid_user(mock_count_users_by_email, app): # Given user = create_user(public_name="Joe la bricole") mock_count_users_by_email.return_value = 0 # When api_errors = validate(user) # Then assert api_errors.errors == {}
def test_offerer_errors_raises_an_error_if_both_iban_and_bic_are_empty(): # given bank_information = create_bank_information(bic="", iban="") # when errors = entity_validator.validate(bank_information) # then assert errors.errors["iban"] == ['L’IBAN renseigné ("") est invalide'] assert errors.errors["bic"] == ['Le BIC renseigné ("") est invalide']
def test_offerer_errors_raises_an_error_if_both_iban_and_bic_are_none(): # given bank_information = create_bank_information(bic=None, iban=None) # when errors = entity_validator.validate(bank_information) # then assert errors.errors["iban"] == ["Cette information est obligatoire"] assert errors.errors["bic"] == ["Cette information est obligatoire"]
def _validate_stock_or_offer(model: Union[Offer, Stock]) -> bool: model_api_errors = validate(model) if model_api_errors.errors.keys(): logger.exception( "[FNAC SYNC] errors while trying to add stock or offer with ref %s: %s", model.idAtProviders, model_api_errors.errors, ) return False return True
def test_should_not_return_errors_when_valid_user(mock_count_users_by_email, app): # Given user = users_factories.UserFactory.build(publicName="Joe la bricole") mock_count_users_by_email.return_value = 0 # When api_errors = validate(user) # Then assert api_errors.errors == {}
def test_should_not_return_errors_when_valid_offer(): # Given offerer = create_offerer() venue = create_venue(offerer, is_virtual=True) offer = create_offer_with_thing_product(venue, is_digital=True) # When api_errors = validate(offer) # Then assert api_errors.errors == {}
def test_should_return_errors_when_invalid_bank_information(): # Given bank_information = create_bank_information(bic="1234", iban="1234") # When api_errors = validate(bank_information) # Then assert api_errors.errors == { "bic": ['Le BIC renseigné ("1234") est invalide'], "iban": ['L’IBAN renseigné ("1234") est invalide'], }
def test_should_return_errors_when_invalid_offer(): # Given offerer = create_offerer() venue = create_venue(offerer, is_virtual=False) offer = create_offer_with_thing_product(venue, is_digital=True) # When api_errors = validate(offer) # Then assert api_errors.errors == { "venue": ['Une offre numérique doit obligatoirement être associée au lieu "Offre numérique"'] }
def test_validate_bank_information_raises_an_error_if_iban_looks_correct_but_does_not_pass_validation_algorithm( ): # given bank_information = create_bank_information( bic="BDFEFR2LCCB", iban="FR7630006000011234567890180") # when errors = entity_validator.validate(bank_information) # then assert errors.errors["iban"] == [ 'L’IBAN renseigné ("FR7630006000011234567890180") est invalide' ]
def test_validate_bank_information_raises_an_error_if_bic_has_correct_length_of_11_but_is_unknown( ): # given bank_information = create_bank_information( bic="fake_bic", iban="FR7630006000011234567890189") # when errors = entity_validator.validate(bank_information) # then assert errors.errors["bic"] == [ 'Le BIC renseigné ("fake_bic") est invalide' ]
def _handle_update(self, pc_object, providable_info): self.fill_object_attributes(pc_object) pc_object.lastProviderId = self.provider.id pc_object.dateModifiedAtLastProvider = providable_info.date_modified_at_provider errors = entity_validator.validate(pc_object) if errors and len(errors.errors) > 0: self.log_provider_event(LocalProviderEventType.SyncError, "ApiErrors") self.erroredObjects += 1 raise errors self.updatedObjects += 1
def test_should_return_errors_when_invalid_user(mock_count_users_by_email, app): # Given user = users_factories.UserFactory.build(publicName="") mock_count_users_by_email.return_value = 0 # When api_errors = validate(user) # Then assert api_errors.errors == { "publicName": ["Tu dois saisir au moins 1 caractères."] }
def test_should_return_errors_when_invalid_product(): # Given product = create_product_with_thing_subcategory(is_offline_only=True, is_digital=True) # When api_errors = validate(product) # Then assert api_errors.errors == { "url": [ "Un produit de sous-catégorie CARTE_CINE_MULTISEANCES ne peut pas être numérique" ] }
def test_validate_bank_information_raises_an_error_if_iban_is_valid_but_bic_is_not( ): # given bank_information = create_bank_information( bic="fake_bic", iban="FR7630006000011234567890189") # when errors = entity_validator.validate(bank_information) # then assert errors.errors["bic"] == [ 'Le BIC renseigné ("fake_bic") est invalide' ] assert "iban" not in errors.errors
def test_validate_bank_information_raises_an_error_if_bic_is_valid_but_iban_is_not( ): # given bank_information = create_bank_information(bic="BDFEFR2LCCB", iban="fake_iban") # when errors = entity_validator.validate(bank_information) # then assert errors.errors["iban"] == [ 'L’IBAN renseigné ("fake_iban") est invalide' ] assert "bic" not in errors.errors