def test_client_pays_by_parts(self): credit_transaction = CreditTransaction() credit_transaction.agent_from = self.client credit_transaction.agent_to = self.service_provider credit_transaction.amount = 1000 self.ledger.add_transaction(credit_transaction) debit_transaction = DebitTransaction() debit_transaction.transaction = credit_transaction debit_transaction.amount = 200 debit_transaction.agent_from = self.client debit_transaction.agent_to = self.service_provider self.ledger.add_transaction(debit_transaction) self.assertEqual(200, self.account_manager.get_agent_to_balance(self.service_provider)) self.assertEqual(-800, self.account_manager.get_agent_from_balance(self.client)) debit_transaction = DebitTransaction() debit_transaction.transaction = credit_transaction debit_transaction.amount = 800 debit_transaction.agent_from = self.client debit_transaction.agent_to = self.service_provider self.ledger.add_transaction(debit_transaction) self.assertEqual(1000, self.account_manager.get_agent_to_balance(self.service_provider)) self.assertEqual(0, self.account_manager.get_receivable_balance(self.service_provider)) self.assertEqual(0, self.account_manager.get_agent_from_balance(self.client)) self.assertEqual(0, self.account_manager.get_balance(self.client)) self.assertEqual(1000, self.account_manager.get_balance(self.service_provider))
def test_get_agent_from_balance(self): credit_transaction = CreditTransaction() credit_transaction.agent_from = self.client credit_transaction.agent_to = self.service_provider credit_transaction.amount = 1000 self.ledger.add_transaction(credit_transaction) self.assertEqual(-1000, self.account_manager.get_agent_from_balance(self.client))
def test_dept_transaction(self): transaction = CreditTransaction() 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_CREDIT, transaction.transaction_type)
def test_payment_transaction(self): credit_transaction = CreditTransaction() credit_transaction.agent_from = self.client credit_transaction.agent_to = self.service_provider credit_transaction.amount = 200 debit_transaction = DebitTransaction() debit_transaction.agent_from = self.client debit_transaction.agent_to = self.service_provider debit_transaction.transaction = credit_transaction debit_transaction.amount = 200 self.assertEqual(credit_transaction.agent_from, debit_transaction.agent_from) self.assertEqual(credit_transaction.agent_to, debit_transaction.agent_to) self.assertEqual(200, debit_transaction.amount) self.assertEqual(TRANSACTION_DEBIT, debit_transaction.transaction_type)
def test_client_is_billed_and_pays_full(self): credit_transaction = CreditTransaction() credit_transaction.agent_from = self.client credit_transaction.agent_to = self.service_provider credit_transaction.amount = 1000 self.ledger.add_transaction(credit_transaction) debit_transaction = DebitTransaction() debit_transaction.transaction = credit_transaction debit_transaction.amount = 1000 debit_transaction.agent_from = self.client debit_transaction.agent_to = self.service_provider self.ledger.add_transaction(debit_transaction) self.assertEqual(2, len(self.ledger.get_transactions_from(self.client))) self.assertEqual(0, len(self.ledger.get_transactions_to(self.client))) self.assertEqual(2, len(self.ledger.get_transactions_to(self.service_provider)))
def test_add_batch_transactions(self): transactions = list() credit_transaction = CreditTransaction() credit_transaction.agent_from = self.client credit_transaction.agent_to = self.service_provider credit_transaction.amount = 1000 debit_transaction = DebitTransaction() debit_transaction.transaction = credit_transaction debit_transaction.amount = 1000 debit_transaction.agent_from = self.client debit_transaction.agent_to = self.service_provider transactions.append(credit_transaction) transactions.append(debit_transaction) self.ledger.add_batch(transactions, 'helo') self.assertEqual(2, len(self.ledger.get_transactions_from(self.client))) self.assertEqual(0, len(self.ledger.get_transactions_to(self.client))) self.assertEqual(2, len(self.ledger.get_transactions_to(self.service_provider))) self.assertEqual('helo', self.ledger.get_transactions_to(self.service_provider)[0].batch_id)
def test_transaction_reason(self): credit_transaction = CreditTransaction() credit_transaction.agent_from = self.client credit_transaction.agent_to = self.service credit_transaction.amount = 200 credit_transaction.batch_id = 'custom_batch_id' reason = TestReason() reason.description = "Here is long and funny description object for the payment" reason.save() credit_transaction.reason = reason self.storage.save_transaction(credit_transaction) transaction = self.storage.filter(self.storage.get_transactions_from(self.client), TRANSACTION_CREDIT)[0] self.assertEqual(reason, transaction.reason)