transactions.py 741 B

123456789101112131415161718192021222324252627
  1. """Utilities to model money transactions."""
  2. from random import choices, randint
  3. from string import ascii_letters, digits
  4. account_chars: str = digits + ascii_letters
  5. def _random_account_id() -> str:
  6. """Return a random account number made of 12 characters."""
  7. return ''.join(choices(account_chars, k=12))
  8. def _random_amount() -> float:
  9. """Return a random amount between 1.00 and 1000.00."""
  10. return randint(100, 100000) / 100
  11. def create_random_transaction() -> dict:
  12. """Create a fake, randomised transaction."""
  13. return {
  14. 'source': _random_account_id(),
  15. 'target': _random_account_id(),
  16. 'amount': _random_amount(),
  17. # Keep it simple: it's all euros
  18. 'currency': 'EUR',
  19. }