Ejemplo n.º 1
0
def serialize_account(account):
    '''
    Serializes data for a single account
    '''
    return {
        'id': account.id,
        'user': {
            'id': account.user.id,
            'username': account.user.username,
        },
        'name': account.name,
        'balance': account.balance,
        'address': account.address,
        'phoneNumber': account.phone_number,
        'transactions': serialize_transactions(Transaction.get_by_account(account))
    }
Ejemplo n.º 2
0
 def test_an_account_can_have_many_transactions(self):
     """
     Tests that can get all transactions for account
     """
     user = User.objects.create_user('john', '*****@*****.**',
                                     'johnpassword')
     account = Account.objects.create(user=user,
                                      balance=1000,
                                      address="New York",
                                      phone_number="9176910399",
                                      name="John's private account",
                                      creator=user)
     transaction1 = Transaction.objects.create(
         transaction_type="withdrawal",
         amount=30,
         account_from=account,
         account_to=None,
         creator=user)
     transaction2 = Transaction.objects.create(transaction_type="deposit",
                                               amount=30,
                                               account_from=None,
                                               account_to=account,
                                               creator=user)
     self.assertEqual(Transaction.get_by_account(account).count(), 2)