-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clase 15: Uso de la Biblioteca Faker para Datos de Prueba
- Loading branch information
1 parent
336a33c
commit 37344a1
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
requests==2.32.3 | ||
Faker==28.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class User: | ||
def __init__(self, name, email): | ||
self.name = name | ||
self.email = email | ||
self.accounts = [] | ||
|
||
def add_account(self, account): | ||
self.accounts.append(account) | ||
|
||
def get_total_balance(self): | ||
return sum(account.get_balance() for account in self.accounts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import unittest, os | ||
from faker import Faker | ||
|
||
from src.user import User | ||
from src.bank_account import BankAccount | ||
|
||
|
||
class UserTests(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.faker = Faker(locale="es") | ||
self.user = User(name=self.faker.name(), email=self.faker.email()) | ||
|
||
def test_user_creation(self): | ||
name_generated = self.faker.name() | ||
email_generated = self.faker.email() | ||
user = User(name=name_generated, email=email_generated) | ||
self.assertEqual(user.name, name_generated) | ||
self.assertEqual(user.email, email_generated) | ||
|
||
def test_user_with_multiple_accounts(self): | ||
for _ in range(3): | ||
bank_account = BankAccount( | ||
balance=self.faker.random_int(min=100, max=2000, step=50), | ||
log_file=self.faker.file_name(extension=".txt") | ||
) | ||
self.user.add_account(account=bank_account) | ||
|
||
expected_value = self.user.get_total_balance() | ||
value = sum(account.get_balance() for account in self.user.accounts) | ||
self.assertEqual(value, expected_value) | ||
|
||
def tearDown(self) -> None: | ||
for account in self.user.accounts: | ||
os.remove(account.log_file) |