Пример #1
0
  def setUp(self):
    """Create a simple account hierarchy for use in this test case.

    root
      income
        salary
        annual-bonus
        spot-bonus
      liabilities
        credit-cards
          bonus-card"""
    root_account = gcdomain_test_util.root_account(account_id='root-account')
    income_account = gcdomain_test_util.account(
          account_id='income',
          name='Income',
          parent_id='root-account')
    salary_account = gcdomain_test_util.account(
          account_id='salary',
          name='Salary',
          parent_id='income')
    # The two bonus accounts have diferent IDs but the same name
    annual_bonus_account = gcdomain_test_util.account(
          account_id='annual-bonus',
          name='Bonus',
          parent_id='income')
    spot_bonus_account = gcdomain_test_util.account(
          account_id='spot-bonus',
          name='Bonus',
          parent_id='income')
    liabilities_account = gcdomain_test_util.account(
          account_id='liabilities',
          name='Liabilities',
          parent_id='root-account')
    credit_cards_account = gcdomain_test_util.account(
          account_id='credit-cards',
          name='Credit Cards',
          parent_id='liabilities')
    # A "Bonus Card" account that has the same name as an account in a separate hierarchy
    bonus_card_account = gcdomain_test_util.account(
          account_id='bonus-card',
          name='Bonus',
          parent_id='credit-cards')

    # Book has account hierarchy but no transactions
    self.book = Book(
        book_id='book',
        commodities=[],
        accounts=[root_account, income_account, salary_account, annual_bonus_account,
            spot_bonus_account, liabilities_account, credit_cards_account, bonus_card_account],
        transactions=[])

    # Get the _BookAccount objects associated with each test account
    self.root_account = self._get_account(root_account)
    self.income_account = self._get_account(income_account)
    self.salary_account = self._get_account(salary_account)
    self.annual_bonus_account = self._get_account(annual_bonus_account)
    self.spot_bonus_account = self._get_account(spot_bonus_account)
    self.liabilities_account = self._get_account(liabilities_account)
    self.credit_cards_account = self._get_account(credit_cards_account)
    self.bonus_card_account = self._get_account(bonus_card_account)
Пример #2
0
  def test_get(self):
    root_account = gcdomain_test_util.root_account(account_id='root-account')
    checking_account = gcdomain_test_util.account(account_id='checking-account')
    savings_account = gcdomain_test_util.account(account_id='savings-account')
    expense_account = gcdomain_test_util.account(account_id='expenses')

    # Buy with savings, buy with checking, transfer savings to checking
    checking_purchase = gcdomain_test_util.transaction(
        date_posted='2011-10-08 12:00:00 -0600',
        splits=[(-5, 'checking-account'), (5, 'expenses')])
    savings_purchase = gcdomain_test_util.transaction(
        date_posted='2011-10-09 12:00:00 -0600',
        splits=[(-1500, 'savings-account'), (1500, 'expenses')])
    savings_transfer = gcdomain_test_util.transaction(
        date_posted='2011-10-15 12:00:00 -0600',
        splits=[(-500, 'savings-account'), (500, 'checking-account')])

    book = Book(
        book_id='book',
        commodities=[],
        accounts=[root_account, checking_account, savings_account],
        transactions=[savings_transfer, savings_purchase, checking_purchase])

    # Transactions should be sorted by date
    self.assertEqual([checking_purchase, savings_transfer],
        book.transactions.get(account_id='checking-account'))
    self.assertEqual([savings_purchase, savings_transfer],
        book.transactions.get(account_id='savings-account'))
    self.assertEqual([checking_purchase, savings_purchase],
        book.transactions.get(account_id='expenses'))
Пример #3
0
  def test_root_account(self):
    root_account = gcdomain_test_util.root_account(account_id='root')
    account = gcdomain_test_util.account(account_id='account')
    book = Book(book_id='book', commodities=[], accounts=[root_account, account], transactions=[])

    self.assertEqual(root_account, book.accounts.root)

    # More than one root account -> ValueError
    # Error is raised when the accounts.root property is read, not on construction.
    root_account2 = gcdomain_test_util.root_account(account_id='root2')
    book = Book(
        book_id='book',
        commodities=[],
        accounts=[root_account, root_account2],
        transactions = [])
    self.assertRaises(ValueError, lambda x: x.accounts.root, book)

    # No root account -> ValueError
    # Error is raised when the accounts.root property is read, not on construction.
    account2 = gcdomain_test_util.account(account_id='account2')
    book = Book(book_id='book', commodities=[], accounts=[account, account2], transactions=[])
    self.assertRaises(ValueError, lambda x: x.accounts.root, book)
Пример #4
0
  def test_repr(self):
    root_account = gcdomain_test_util.root_account()
    self.assertEqual(root_account, eval(repr(root_account)))

    account = gcdomain_test_util.account()
    self.assertEqual(account, eval(repr(account)))