def test_get_total_deposit(self):
     deposit_transaction = DepositTransaction()
     deposit_transaction.amount = 200
     deposit_transaction.agent_from = self.client
     deposit_transaction.agent_to = self.service_provider
     self.ledger.add_transaction(deposit_transaction)
     self.assertEqual(200, self.account_manager.get_total_by(self.client, TRANSACTION_DEPOSIT))
 def test_get_deposit_transactions(self):
     deposit_transaction = DepositTransaction()
     deposit_transaction.agent_from = self.client
     deposit_transaction.agent_to = self.service
     deposit_transaction.amount = 1000
     deposit_transaction.batch_id = 'custom_batch_id'
     self.storage.save_transaction(deposit_transaction)
     transaction = self.storage.filter(self.storage.get_transactions_from(self.client), TRANSACTION_DEPOSIT)[0]
     self.assertEqual(1000, transaction.amount)
    def test_client_pays_advance_payment_to_provider(self):
        transaction = DepositTransaction()
        transaction.amount = 200
        transaction.agent_from = self.client
        transaction.agent_to = self.service_provider

        self.ledger.add_transaction(transaction)
        self.assertEqual(1, len(self.ledger.get_transactions_from(self.client)))
        self.assertEqual(1, len(self.ledger.get_transactions_to(self.service_provider)))
 def test_credit_transaction(self):
     transaction = DepositTransaction()
     transaction.agent_from = self.client
     transaction.agent_to = self.service_provider
     transaction.amount = 200
     self.assertEqual(self.client, transaction.agent_from)
     self.assertEqual(self.service_provider, transaction.agent_to)
     self.assertEqual(200, transaction.amount)
     self.assertEqual(TRANSACTION_DEPOSIT, transaction.transaction_type)
    def test_save_transaction_to_db(self):

        deposit_transaction = DepositTransaction()
        deposit_transaction.agent_from = self.client
        deposit_transaction.agent_to = self.service
        deposit_transaction.amount = 200
        deposit_transaction.batch_id = 'custom_batch_id'

        self.storage.save_transaction(deposit_transaction)

        db_transaction = Transaction.objects.get(agent_from_id=self.client.pk, agent_from_content_type=ContentType.objects.get_for_model(self.client))

        self.assertEqual(db_transaction.agent_from, self.client)
        self.assertEqual(db_transaction.agent_to, self.service)
        self.assertEqual(1, len(self.storage.get_transactions_from(self.client)))
        self.assertEqual(1, len(self.storage.get_transactions_to(self.service)))
    def test_deposits_and_withdraw(self):
        deposit_transaction = DepositTransaction()
        deposit_transaction.amount = 200
        deposit_transaction.agent_from = self.client
        deposit_transaction.agent_to = self.service_provider
        self.ledger.add_transaction(deposit_transaction)
        withdraw_transaction = WithdrawTransaction()
        withdraw_transaction.agent_from = self.client
        withdraw_transaction.agent_to = self.service_provider
        withdraw_transaction.amount = 100
        self.ledger.add_transaction(withdraw_transaction)
        self.assertEqual(100, self.account_manager.get_agent_to_balance(self.service_provider))
        self.assertEqual(100, self.account_manager.get_agent_from_balance(self.client))

        self.assertEqual(100, self.account_manager.get_balance(self.client))
        self.assertEqual(100, self.account_manager.get_balance(self.service_provider))