class TestJournalEntry(unittest.TestCase): def setUp(self): # Setup access to Subledger Organization.authenticate(API_KEY, SECRET) self.org = Organization('ACME Inc.') self.org.save() self.book = Book(self.org, 'USD') self.book.save() self.account_01 = Account(book=self.book, description='1210 Accounts Receivable', normal_balance='debit') save_result = self.account_01.save() assert save_result == True self.account_02 = Account(book=self.book, description='2110 Accounts Paypable', normal_balance='credit') save_result = self.account_02.save() assert save_result == True at_datetime_utc = datetime.datetime.utcnow() effective_at = at_datetime_utc.strftime('%Y-%m-%dT%H:%M:%SZ') lines = [ { 'account': self.account_01._id, 'value': { 'type': 'debit', 'amount': '10.00' } }, { 'account': self.account_02._id, 'value': { 'type': 'credit', 'amount': '10.00' } } ] self.journal_entry = JournalEntry(book=self.book, description='Recharge account', effective_at=effective_at, lines=lines, reference='http://acme.com/journal_entry/') save_result = self.journal_entry.save() self.assertTrue(save_result) def test_from_id(self): retrieved = JournalEntry.from_id(self.journal_entry._id, self.org._id, self.book._id) self.assertIs(retrieved, self.journal_entry)
class TestAccount(unittest.TestCase): def setUp(self): # Setup access to Subledger Organization.authenticate(API_KEY, SECRET) self.org = Organization('ACME Inc.') self.org.save() self.book = Book(self.org, 'USD') self.book.save() self.account = Account(book=self.book, description='1210 Accounts Receivable', normal_balance='debit') save_result = self.account.save() assert save_result == True def test_balance(self): at_datetime_utc = datetime.datetime.utcnow() balance_result = self.account.get_balance(at_datetime_utc=at_datetime_utc) self.assertIsNotNone(balance_result) self.assertIn('balance', balance_result) balance = balance_result['balance'] self.assertIn('debit_value', balance) self.assertIn('type', balance['debit_value']) self.assertEqual(balance['debit_value']['type'], 'zero') self.assertIn('amount', balance['debit_value']) self.assertEqual(balance['debit_value']['amount'], '0') self.assertIn('credit_value', balance) self.assertIn('type', balance['credit_value']) self.assertEqual(balance['credit_value']['type'], 'zero') self.assertIn('amount', balance['credit_value']) self.assertEqual(balance['credit_value']['amount'], '0') self.assertIn('value', balance) self.assertIn('type', balance['value']) self.assertEqual(balance['value']['type'], 'zero') self.assertIn('amount', balance['value']) self.assertEqual(balance['value']['amount'], '0') def test_from_id(self): retrieved = Account.from_id(self.account._id, self.book._id) self.assertIs(retrieved, self.account) def test_from_dict_index(self): data = {'id': self.account._id, 'book': self.book._id} logging.info(data) retrieved = Account._from_dict(data) # Identity self.assertIs(retrieved, self.account) def test_from_dict(self): account = Account._from_dict( {'id': None, 'book': self.book._id, 'org': self.org._id, 'version': self.account._version, 'type': self.account._type, 'normal_balance': self.account.normal_balance, 'description': '1210 Accounts Receivable'}) # Attribute values self.assertEqual(account.description, '1210 Accounts Receivable') self.assertEqual(account.reference, None) # Identity self.assertIsNot(account, self.account)