GnuCash 2.4.99
test_business.py
00001 from unittest import main
00002 
00003 from datetime import datetime
00004 
00005 from gnucash import Account, \
00006     ACCT_TYPE_RECEIVABLE, ACCT_TYPE_INCOME, ACCT_TYPE_BANK, \
00007     GncNumeric
00008 from gnucash.gnucash_business import Vendor, Employee, Customer, Job, Invoice, Entry
00009 
00010 from test_book import BookSession
00011 
00012 class BusinessSession( BookSession ):
00013     def setUp(self):
00014         BookSession.setUp(self)
00015 
00016         self.today = datetime.today()
00017 
00018         self.bank = Account(self.book)
00019         self.bank.SetType(ACCT_TYPE_BANK)
00020         self.bank.SetCommodity(self.currency)
00021         self.income = Account(self.book)
00022         self.income.SetType(ACCT_TYPE_INCOME)
00023         self.income.SetCommodity(self.currency)
00024         self.receivable = Account(self.book)
00025         self.receivable.SetType(ACCT_TYPE_RECEIVABLE)
00026         self.receivable.SetCommodity(self.currency)
00027 
00028         self.customer = Customer(self.book,'CustomerID',self.currency)
00029         self.vendor = Vendor(self.book,'VendorID',self.currency)
00030         self.employee = Employee(self.book,'EmployeeID',self.currency)
00031         self.job = Job(self.book,'JobID',self.customer)
00032 
00033         self.invoice = Invoice(self.book,'InvoiceID',self.currency,self.customer)
00034         self.invoice.SetDateOpened(self.today)
00035         entry = Entry(self.book)
00036         entry.SetDate(self.today)
00037         entry.SetDescription("Some income")
00038         entry.SetQuantity(GncNumeric(1))
00039         entry.SetInvAccount(self.income)
00040         entry.SetInvPrice(GncNumeric(100))
00041         self.invoice.AddEntry(entry)
00042 
00043         self.invoice.PostToAccount(self.receivable,
00044             self.today, self.today, "", True)
00045 
00046 class TestBusiness( BusinessSession ):
00047     def test_equal(self):
00048         self.assertTrue( self.vendor.Equal( self.vendor.GetVendor() ) )
00049         self.assertTrue( self.customer.Equal( self.job.GetOwner() ) )
00050         self.assertTrue( self.customer.Equal( self.invoice.GetOwner() ) )
00051 
00052     def test_employee_name(self):
00053         NAME = 'John Doe'
00054         self.assertEqual( '', self.employee.GetUsername() )
00055         self.employee.SetUsername(NAME)
00056         self.assertEqual( NAME, self.employee.GetUsername() )
00057 
00058     def test_post(self):
00059         self.assertTrue( self.invoice.IsPosted() )
00060 
00061     def test_owner(self):
00062         OWNER = self.invoice.GetOwner()
00063         self.assertTrue( self.customer.Equal( OWNER ) )
00064 
00065     def test_commodities(self):
00066         self.assertTrue( self.currency.equal( self.customer.GetCommoditiesList()[0] ) )
00067 
00068 if __name__ == '__main__':
00069     main()
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines