Esempio n. 1
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)])
Esempio n. 2
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)])
Esempio n. 3
0
 def __init__(self, unique, new=False, rate=None, rounding=None, userid=1):
     """ Invoices can be instantiated from a rowid or a name.
         If the name isn't already in the database a new one
         will be created if `new` is true. Otherwise the program 
         halts. If instantiated from a rowid, using a rowid that 
         does not exist will throw an exception. `rate` and 
         `rounding` args unnecessary if querying by rowid. 
         `rate` and `rounding` default to user values.
     """
     self.user = User(userid)
     meta = db.query_invoice(unique)
     if meta:
         if new:
             print("An invoice with the name %s already exists. You can't "
                 "make a new one with that name." %unique, file=sys.stderr)
             sys.exit()
         self.name = meta[0]
         self.rate = meta[1]
         self.rounding = meta[2]
         self.rowid = meta[3] if len(meta) == 4 else unique
     else:
         # this will only happen if `unique` is a name
         # if `unique` is a rowid, an exception is raised
         # on the query.
         if not new:
             raise InvoiceNotFound
         self.name = unique
         if rate is None and self.user.rate == 0:
             fprintf("WARNING: Your default hourly rate is set to zero. This"
                 " means that no earnings will be recorded. You can set your"
                 " default rate with `gitime set -r <rate>` or set the rate "
                 "for this invoice with `gitime invoice <invoice name> -r "
                 "<rate>`.")
         self.rate = rate if rate is not None else self.user.rate
         self.rounding = (rounding if rounding is not None 
             else self.user.rounding)
         self.rowid = db.insert_invoice(self.name, self.rate, self.rounding)
Esempio n. 4
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)
Esempio n. 5
0
 def test_access_invoice(self):
 	db.insert_invoice('a project', 20.0, 1.0)
 	inv = invoice.Invoice('a project')
 	self.assertEqual(inv.name, 'a project')
 	self.assertEqual(inv.rate, 20.0)
 	self.assertEqual(inv.rounding, 1.0)
Esempio n. 6
0
 def test_update(self):
     invoice_id = db.insert_invoice('Cool Project', 20.0, 1.0)
     db.update(lambda c_: c_.execute('UPDATE invoice SET rate=? WHERE rowid=?', (40.0, invoice_id)))
     self.c.execute('SELECT * FROM invoice WHERE rowid=?', (invoice_id,))
     self.assertEqual(self.c.fetchall(), [('Cool Project', 40.0, 1.0)])