Beispiel #1
0
 def __init__(self, message, hours, invoice, date=None, rowid=None, 
     new=True):
         """ creates a new commit and adds it to the database. To access
             an existing commit, do not access this constructor directly.
             Instead, use the `access` class method.
             Args:
             * message - the commit message
             * hours - the hours worked
             * invoice - the invoice rowid, or name
             * date - unix date of commit. Use None to determine the date
                      automatically
             * rowid - this is provided by the `access` method
             * new - create a new commit. If false, access an existing one
         """
         self.message = message
         self.hours = hours
         self.invoice = Invoice(invoice)
         self.date = date if date is not None else math.floor(time.time())
         if new:
             self.rowid = db.insert_commit(
                 self.message, self.date, self.hours, self.invoice.rowid)
         elif rowid:
             self.rowid = rowid
         else:
             raise Exception(
                 "Rowid must be provided to access an existing commit")
Beispiel #2
0
 def test_insert(self):
     invoice_id = db.insert_invoice('Cool Project', 20.0, 1.0)
     self.c.execute('SELECT * FROM invoice WHERE rowid=?', (invoice_id,))
     self.assertEqual(self.c.fetchall(), [('Cool Project', 20.0, 1.0)])
     commit_id = db.insert_commit('Did a thing', 1405184155, 2.0, invoice_id)
     self.c.execute('SELECT * FROM gtcommit WHERE commit_invoice=?', (invoice_id,))
     self.assertEqual(self.c.fetchall(), [('Did a thing', 1405184155, 2.0, invoice_id)])
Beispiel #3
0
 def test_access_commit(self):
     comid = db.insert_commit('fixed a thing', 1405287929, 2, 1)
     com = commit.Commit.access(comid)
     self.assertEqual(com.message, 'fixed a thing')
     self.assertEqual(com.hours, 2)
     self.assertEqual(com.date, 1405287929)
     self.assertEqual(com.invoice.name, 'some project')
     self.assertEqual(com.rowid, comid)
Beispiel #4
0
 def test_query(self):
     invoice_id = db.insert_invoice('Cool Project', 20.0, 1.0)
     commit_id = db.insert_commit('Did a thing', 1405184155, 2.0, invoice_id)
     self.assertEqual(db.query_user(1), (0.0, 0.25, 0, 0, 0, 0))
     self.assertEqual(db.query_invoice(1), ('Cool Project', 20.0, 1.0))
     self.assertEqual(db.query_invoice('Cool Project'), ('Cool Project', 20.0, 1.0, 1))
     self.assertEqual(db.query_commit(1), ('Did a thing', 1405184155, 2.0, invoice_id))
     self.assertEqual(db.query_invoice_commit_meta(1), [('Did a thing', 1405184155, 2.0, invoice_id)])
Beispiel #5
0
 def test_total_earnings(self):
 	invid = db.insert_invoice('a project', 20.0, 1.0)
 	db.insert_commit('fixed a thing', 1405287929, 2, invid)
 	inv = invoice.Invoice(invid)
 	self.assertEqual(inv.total_earnings(), 40.0)