def from_dict(cls, dict): trs = cls(trs_id=dict['trs_id'], trs_timestamp=dict['trs_timestamp'], trs_from=Account.from_dict(dict['trs_from']), trs_to=Account.from_dict(dict['trs_to']), trs_amount=dict['trs_amount']) return trs
def unit_of_work(): uow = FakeUnitOfWork() uow.accounts.add_account( Account.from_dict({ 'code': '1234567890F', 'balance': 1000.00 })) uow.accounts.add_account( Account.from_dict({ 'code': '7765432255B', 'balance': 10000.00 })) return uow
def test_account_from_dict(): code = '2222222222M' dict = {'id': id, 'code': code, 'balance': 321.10} account = Account.from_dict(dict) assert account.code == code assert account.balance == 321.10
def test_transfer_serielizer(): _id = str(uuid.uuid4()) test_trs = Transfer(trs_id=_id, trs_timestamp="2019-01-22 09:00:00", trs_from=Account.from_dict({ "code": "222222222M", "balance": 1000 }), trs_to=Account.from_dict({ "code": "1111111111V", "balance": 1000 }), trs_amount=321.45) expected = ''' { "trs_id":"''' + _id + '''", "trs_timestamp":"2019-01-22 09:00:00", "trs_from":{"code":"222222222M", "balance":1000}, "trs_to":{"code":"1111111111V", "balance":1000}, "trs_amount":321.45 }''' json_trs = json.dumps(test_trs, cls=TransferEncoder) assert json.loads(json_trs) == json.loads(expected)
def test_account_comparison(): dict = {'code': '1234522222F', 'balance': 1200.00} account1 = Account.from_dict(dict) account2 = Account.from_dict(dict) assert account1 == account2
def test_account_to_dict(): dict = {'code': '1234522222F', 'balance': 1200.00} account = Account.from_dict(dict) assert dict == account.to_dict()
def find_account(self, account_code= None): _elem = next((e for e in self._entries if e['code']==account_code), None) return Account.from_dict(_elem) if _elem else None
import json from unittest import mock from bankaccount.usecases import response_objects as resp from bankaccount.entities.transfer import Transfer from bankaccount.entities.account import Account test_trs = Transfer(trs_id=1, trs_timestamp="2019-01-22 09:00:00", trs_from=Account.from_dict({ 'code': "1234567890F", 'balance': 1000 }), trs_to=Account.from_dict({ 'code': "3333333333A", 'balance': 1000 }), trs_amount=321.00) mimetype = 'application/json' headers = {'Content-Type': mimetype, 'Accept': mimetype} data = {'from': '1234567890F', 'to': '3333333333A', 'amount': 321.00} @mock.patch('bankaccount.usecases.transfer_usecases.TransferAmountUseCase') def test_post_transfer(mock_usecase, client): mock_usecase().execute.return_value = resp.ResponseSuccess(test_trs) http_response = client.post('/transfer', data=json.dumps(data), headers=headers)