def test_imbricated_tuple_in_dict_value(self): data = (('a', (('d', 4), ('e', 5))), ('b', 2), ( 'c', 3, )) req = api.TupleRequest(data) self.assertEqual(req.data, {'a': {'d': 4, 'e': 5}, 'b': 2, 'c': 3})
def make_transaction(self): make_transaction = banking.MakeTransaction() # get code from client code = self.client.read_code() # search the corresponding account into the database accounts = self.accounts.read() accounts = api.TextRequest(accounts).data for i, account in enumerate(accounts): if account['code'] == str(code[1]): # found account print("\nThe corresponding account is:") print(api.TextResponse(account).data) action = self.client.read_action() amount = self.client.read_int('amount') data = action, amount, ('account', account) client_request = api.TupleRequest(data) try: transaction = make_transaction.execute(client_request.data) except Exception as e: self.client.show(f"\n{e}") return # update account balance print("\nTransaction completed:") print(api.TextResponse(transaction).data) account['balance'] = transaction['new_balance'] accounts[i] = account # save to database transaction_response = api.TextResponse(accounts) self.accounts.write(transaction_response.data)
def test_transaction_request_using_dicts_in_inputs(self): ill_data = (('action', 'deposit'), ('amount', 2000), ('account', { 'code': '2520', 'balance': '5000', 'client': { 'address': 'thiaroye', 'lastname': 'ba', 'firstname': 'amadou' } })) req = api.TupleRequest(ill_data) self.assertEqual( req.data, { 'action': 'deposit', 'amount': 2000.0, 'account': { 'code': 2520.0, 'balance': 5000.0, 'client': { 'address': 'thiaroye', 'lastname': 'ba', 'firstname': 'amadou' } } })
def test_read_client(self): data = (('firstname', 'moctar'), ('lastname', 'diallo'), ('address', 'plateau'), ('balance', '8000')) req = api.TupleRequest(data) self.assertEqual( req.data, { 'firstname': 'moctar', 'lastname': 'diallo', 'address': 'plateau', 'balance': '8000' })
def create_account(self): client = self.client.read_client() balance = self.client.read_float('balance') request = api.TupleRequest(client + (balance, )) create_account = banking.CreateAccount() account = create_account.execute(request.data) response = api.TextResponse(account) print(response.data) self.accounts.add(response.data)
def test_read_client_for_user(self): data = (('client', (('firstname', 'moctar'), ('lastname', 'diallo'), ('address', 'medina'), ('balance', '8000'))), ) req = api.TupleRequest(data) self.assertEqual( req.data, { 'client': { 'firstname': 'moctar', 'lastname': 'diallo', 'address': 'medina', 'balance': '8000' } })
def test_triply_imbricated_tuple_with_dict_inputs(self): data = (('a', 1), ('b', ({'f': ({'d': '4'}, {'e': 5})}, )), ('c', 3)) req = api.TupleRequest(data) self.assertEqual(req.data, { 'a': 1, 'b': { 'f': { 'd': 4.0, 'e': 5 } }, 'c': 3.0 })
def test_triply_imbricated_tuple_in_dict_value_and_string_numbers(self): data = (('a', 1), ('b', (('f', (('d', '4.1'), ('e', 5))), )), ('c', 3)) req = api.TupleRequest(data) self.assertEqual(req.data, { 'a': 1, 'b': { 'f': { 'd': 4.1, 'e': 5 } }, 'c': 3 })
def test_account(self): data = (('action', 'deposit'), ('account', (('client', (('firstname', 'moctar'), ('lastname', 'diallo'), ('address', 'medina'), ('balance', '80000'))), ('code', '4455'), ('amount', '5000')))) req = api.TupleRequest(data) self.assertEqual( req.data, { 'action': 'deposit', 'account': { 'client': { 'firstname': 'moctar', 'lastname': 'diallo', 'address': 'medina', 'balance': '80000' }, 'code': '4455', 'amount': '5000' } })
def test_transaction_request_using_tuples(self): data = (('action', 'deposit'), ('amount', 2000), ('account', (('code', '2520'), ('balance', '5000'), ('client', (('address', 'plateau'), ('lastname', 'ba'), ('firstname', 'amadou')))))) req = api.TupleRequest(data) self.assertEqual( req.data, { 'action': 'deposit', 'amount': 2000.0, 'account': { 'code': 2520.0, 'balance': 5000.0, 'client': { 'address': 'plateau', 'lastname': 'ba', 'firstname': 'amadou' } } })
def test_basic(self): data = ('a', 1), req = api.TupleRequest(data) self.assertEqual(req.data, { 'a': 1, })
def test_basic_with_dict_in_inputs(self): data = ('a', '1'), {'b': 2} req = api.TupleRequest(data) self.assertEqual(req.data, {'a': 1, 'b': 2})
def test_basic_with_string_value(self): data = ('a', '1'), ('b', 2) req = api.TupleRequest(data) self.assertEqual(req.data, {'a': 1, 'b': 2})
def test_simple(self): data = (('a', 1), ('b', 2), ('c', 3)) req = api.TupleRequest(data) self.assertEqual(req.data, {'a': 1, 'b': 2, 'c': 3})
def test_simple_imbrication_with_string_value_of_float(self): data = (('a', (('d', '4.2'), ('e', 5))), ) req = api.TupleRequest(data) self.assertEqual(req.data, {'a': {'d': 4.2, 'e': 5}})
def test_simple_imbrication_with_dict_inputs(self): data = ({'a': (('d', '4'), ('e', 5))}, ) req = api.TupleRequest(data) self.assertEqual(req.data, {'a': {'d': 4, 'e': 5}})
def test_simple_imbrication(self): data = (('a', (('d', 4), ('e', 5))), ) req = api.TupleRequest(data) self.assertEqual(req.data, {'a': {'d': 4, 'e': 5}})