def test_iban_validator_deconstruct(self): # Call to the required deconstruct method to see if it exists and # it doesn't throw an error. IBANValidator().deconstruct() test_cases = [ { 'use_nordea_extensions': True, 'include_countries': ['IS', 'IT'] }, { 'use_nordea_extensions': True }, { 'include_countries': ['IS', 'IT'] }, {}, ] for test_case in test_cases: iban1 = IBANValidator(**test_case) iban2 = IBANValidator(**test_case) self.assertEqual( iban1, iban2, msg="IBAN validators with equal parameters are not equal.")
def test_iban_validator(self): valid = [ 'GB82WeST12345698765432', 'GB82 WEST 1234 5698 7654 32', 'GR1601101250000000012300695', 'GR16-0110-1250-0000-0001-2300-695', 'GB29NWBK60161331926819', 'GB29N-WB K6016-13319-26819', 'SA0380000000608010167519', 'SA0380 0 0000 06 0 8 0 1 0 1 6 7 519 ', 'CH9300762011623852957', 'IL620108000000099999999', 'EE982200221111099080', 'VA59001123000012345678', None, ] invalid = { 'GB82WEST1234569876543': 'GB IBANs must contain 22 characters.', 'CA34CIBC123425345': 'CA is not a valid country code for IBAN.', 'GB29ÉWBK60161331926819': 'is not a valid character for IBAN.', 'SA0380000000608019167519': 'Not a valid IBAN.', 'EE012200221111099080': 'Not a valid IBAN.', } iban_validator = IBANValidator() for iban in valid: iban_validator(iban) for iban in invalid: self.assertRaisesMessage(ValidationError, invalid[iban], IBANValidator(), iban)
def check_iban_phone(ldap_entries) -> Iterable[str]: """Check if IBAN and phone number are valid (otherwise cloning will fail as well).""" validate_iban = IBANValidator() for dn, attrs in _iterate_people(ldap_entries): try: validate_iban(_get_val(attrs, 'qIBAN')) validate_international_phonenumber(_get_val(attrs, 'telephoneNumber')) except ValidationError as e: yield 'Phone or IBAN error for person {}: {}'.format(dn, e)
def payment_refund_supported(self, payment: OrderPayment) -> bool: if not all(payment.info_data.get(key) for key in ("payer", "iban")): return False try: IBANValidator()(self.norm(payment.info_data['iban'])) except ValidationError: return False else: return True
def create_payout_finished_project(sender, instance, created, **kwargs): """ Create or update Payout for finished projects. Project finish when deadline is hit or when it's changed manually in admin. """ from bluebottle.payouts.models import ProjectPayout from localflavor.generic.validators import IBANValidator project = instance if project.status.slug in ['done-complete', 'done-incomplete'] \ and project.amount_asked: next_date = ProjectPayout.get_next_planned_date() payouts = ProjectPayout.objects.filter(project=project) if payouts.count(): # Get the latest payout payout = payouts.order_by('-created').all()[0] if payout.status == StatusDefinition.NEW: # Update planned payout date for new Payouts payout.calculate_amounts() payout.planned = next_date payout.save() else: if project.campaign_started: # Create new Payout payout = ProjectPayout(planned=next_date, project=project) # Calculate amounts payout.calculate_amounts() if project.is_closed: payout.status = StatusDefinition.SETTLED # Set payment details try: IBANValidator()(project.account_number) payout.receiver_account_iban = project.account_number except ValidationError as e: logger.info( "IBAN error payout {0}, project: {1}: {2}".format( payout.id, project.id, e.message)) payout.receiver_account_details = project.account_details or '' payout.receiver_account_number = project.account_number or '' payout.receiver_account_name = project.account_holder_name or '' payout.receiver_account_city = project.account_holder_city or '' try: payout.receiver_account_country = project.account_bank_country.name except AttributeError: payout.receiver_account_country = '' payout.save()
def payment_refund_supported(self, payment: OrderPayment) -> bool: if not all(payment.info_data.get(key) for key in ("payer", "iban")): return False try: iban = self.norm(payment.info_data['iban']) IBANValidator()(iban) except ValidationError: return False else: return not any( iban.startswith(b) for b in (self.settings.refund_iban_blocklist or '').splitlines() if b)
def payment_refund_supported(self, payment: OrderPayment) -> bool: if not payment.sepaexportorder_set.exists(): return True if not all( payment.info_data.get(key) for key in ("account", "iban", "bic")): return False try: IBANValidator()(self.norm(payment.info_data['iban'])) BICValidator()(self.norm(payment.info_data['bic'])) except ValidationError: return False else: return True
def validate_account_number(value): if value: country_code = value[:2] digits_regex = re.compile('\d{2}') check_digits = value[2:4] # Only try iban validaton when the field matches start of # iban format as the field can also contain non-iban # account numbers. # Expecting something like: NL18xxxxxxxxxx iban_validator = IBANValidator() if country_code in iban_validator.validation_countries.keys() and \ digits_regex.match(check_digits): iban_validator(value) return value
def clean(self): """Clean and validate the form data.""" data = super().clean() # When `bank account` is chosen as refund type, three additional fields must be validated: # Bank account owner, IBAN and BIC. if data.get("refund_type") == "bank_account": if not data.get("bank_account_owner"): self.add_error("bank_account_owner", _("This field is required.")) if data.get("bank_account_iban"): iban_validator = IBANValidator() try: iban_validator(data.get("bank_account_iban")) except ValidationError: self.add_error("bank_account_iban", _("A valid IBAN is required.")) else: self.add_error("bank_account_iban", _("This field is required.")) if data.get("bank_account_bic"): bic_validator = BICValidator() try: bic_validator(data.get("bank_account_bic")) except ValidationError: self.add_error("bank_account_bic", _("A valid BIC is required.")) else: self.add_error("bank_account_bic", _("This field is required.")) # Receipt validation if not any([data.get("receipt_{}_picture".format(i)) for i in range(10)]): self.add_error("receipt_0_picture", _("At least one receipt is required.")) for i in range(10): if data.get(f"receipt_{i}_picture") and not data.get(f"receipt_{i}_amount"): self.add_error(f"receipt_{i}_picture", _("The amount for this receipt is required.")) elif data.get(f"receipt_{i}_amount") and not data.get(f"receipt_{i}_picture"): self.add_error(f"receipt_{i}_amount", _("The receipt for this amount is required."))
def test_nordea_extensions(self): """ Test a valid IBAN in the Nordea extensions. """ iban_validator = IBANValidator(use_nordea_extensions=True) # Run the validator to ensure there are no ValidationErrors raised. iban_validator('Eg1100006001880800100014553')
def test_nordea_extensions(self): """Test a valid IBAN in the Nordea extensions.""" iban_validator = IBANValidator(use_nordea_extensions=True) # Run the validator to ensure there are no ValidationErrors raised. iban_validator('Bj11B00610100400271101192591')