Skip to content

Commit

Permalink
style: format code with Autopep8, Black, ClangFormat, dotnet-format, …
Browse files Browse the repository at this point in the history
…Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf

This commit fixes the style issues introduced in 978d3bc according to the output
from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java
Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt,
Scalafmt, StandardJS, StandardRB, swift-format and Yapf.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored May 10, 2024
1 parent 978d3bc commit 5e6d39e
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions transaction_processing/transaction_validation.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import re


class TransactionValidation:
def __init__(self):
self.validation_rules = {
'account_number': {
'regex': r'^\d{10}$',
'message': 'Invalid account number format. Please enter a 10-digit account number.'
"account_number": {
"regex": r"^\d{10}$",
"message": "Invalid account number format. Please enter a 10-digit account number.",
},
"amount": {
"min": 0,
"max": 1000000,
"message": "Transaction amount must be between 0 and 1,000,000.",
},
'amount': {
'min': 0,
'max': 1000000,
'message': 'Transaction amount must be between 0 and 1,000,000.'
}
}

def validate_transaction(self, transaction):
errors = []
for field, rules in self.validation_rules.items():
if field in transaction:
for rule in rules:
if rule == 'regex':
if rule == "regex":
if not re.match(rules[rule], transaction[field]):
errors.append(rules['message'])
elif rule == 'min':
errors.append(rules["message"])
elif rule == "min":
if float(transaction[field]) < rules[rule]:
errors.append(f'Transaction amount must be at least {rules[rule]}')
elif rule == 'max':
errors.append(
f"Transaction amount must be at least {rules[rule]}"
)
elif rule == "max":
if float(transaction[field]) > rules[rule]:
errors.append(f'Transaction amount must not exceed {rules[rule]}')
errors.append(
f"Transaction amount must not exceed {rules[rule]}"
)
return errors

0 comments on commit 5e6d39e

Please sign in to comment.