Пример #1
0
 def test_update_expense_with_invalid_date(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     fs.insert_expense(self.cursor, 'test1', 20, '20130101', 1, (1, 2))
     self.connection.commit()
     values = ('20130229', 'jfjfjf', '130101', '', ' ')
     for x in values:
         self.assertRaises(fs.IllegalExpenseDateError, fs.update_expense, 
                           self.cursor, 1, 'edit', 20, x, 2, (1, 2))
     self.connection.commit()
Пример #2
0
 def test_update_expense_with_unknown_debtor(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     fs.insert_expense(self.cursor, 'test1', 20, '20130101', 1, (1, 2))
     self.connection.commit()
     values = (3, 4, 9000, 'a', '')
     for x in values:
         self.assertRaises(fs.UserNotFoundError, fs.update_expense, 
                           self.cursor, 1, 'edit', 20, '20130101', 1, (x,))
     self.connection.commit()
Пример #3
0
 def test_update_expense_with_invalid_cost(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     fs.insert_expense(self.cursor, 'test1', 20, '20130101', 1, (1, 2))
     self.connection.commit()
     values = (-30, '-30', 0, '0', '', ' ', '-.2')
     for x in values:
         self.assertRaises(fs.IllegalExpenseCostError, fs.update_expense, 
                           self.cursor, 1, 'edit', x, '20130102', 2, (1, 2))
     self.connection.commit()
Пример #4
0
 def test_update_expense(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     fs.insert_expense(self.cursor, 'test1', 20, '20130101', 1, (1, 2))
     self.connection.commit()
     fs.update_expense(self.cursor, 1, 'edit1', 30, '20130102', 2, (1,))
     expected_expense = {'id': 1, 'title': 'edit1', 'cost': 30, 
                         'date': '20130102', 'payer': 2}
     expected_debtors = [1,]
     self.assertEqual(fs.get_expense(self.cursor, 1), expected_expense)
     self.assertEqual(fs.get_debtors(self.cursor, 1), expected_debtors)
Пример #5
0
 def test_get_debtors(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     fs.insert_expense(self.cursor, 'test1', 20, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test2', 30, '20130102', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test3', 40, '20130103', 2, (1, 2))
     self.connection.commit()
     expected_deb = ([1, 2], [1, 2], [1, 2])
     for i in range(len(expected_deb)):
         self.assertEqual(fs.get_debtors(self.cursor, i+1), expected_deb[i])
Пример #6
0
 def test_get_expenses(self):
     self.assertEqual(fs.get_expenses(self.cursor), [])
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     fs.insert_expense(self.cursor, 'test1', 20, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test2', 30, '20130102', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test3', 40, '20130103', 2, (1, 2))
     self.connection.commit()
     expected_result = [
         {'id': 1, 'date': '20130101', 'title': 'test1', 'payer': 1, 
          'cost': 20},
         {'id': 2, 'date': '20130102', 'title': 'test2', 'payer': 1, 
          'cost': 30},
         {'id': 3, 'date': '20130103', 'title': 'test3', 'payer': 2, 
          'cost': 40},
     ]
     self.assertEqual(fs.get_expenses(self.cursor), expected_result)
Пример #7
0
 def test_get_expense(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     fs.insert_expense(self.cursor, 'test1', 20, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test2', 30, '20130102', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test3', 40, '20130103', 2, (1, 2))
     self.connection.commit()
     expected_exp = (
         {'id': 1, 'date': '20130101', 'title': 'test1', 'payer': 1, 
          'cost': 20},
         {'id': 2, 'date': '20130102', 'title': 'test2', 'payer': 1, 
          'cost': 30},
         {'id': 3, 'date': '20130103', 'title': 'test3', 'payer': 2, 
          'cost': 40},
     )
     for i in range(len(expected_exp)):
         self.assertEqual(fs.get_expense(self.cursor, i+1), expected_exp[i])
Пример #8
0
 def test_get_status_dict(self):
     users = fs.get_users_dict(self.cursor)
     self.assertEqual(fs.get_status_dict(self.cursor, users), {})
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     fs.insert_user(self.cursor, 'user3')
     fs.insert_expense(self.cursor, 'test', 20, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test', 30, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test', 40, '20130101', 2, (1, 2))
     fs.insert_expense(self.cursor, 'test', 40, '20130101', 2, (1, 2))
     fs.insert_expense(self.cursor, 'test', 40, '20130101', 2, (1, 2))
     fs.insert_expense(self.cursor, 'test', 5, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test', 105, '20130101', 3, (1, 2))
     fs.insert_expense(self.cursor, 'test', 210, '20130101', 3, (1, 2, 3))
     self.connection.commit()
     expected_status = {
         'user1': {'user1': 0, 'user2': 0, 'user3': 0},
         'user2': {'user1': 32.5, 'user2': 0, 'user3': 0},
         'user3': {'user1': 122.5, 'user2': 122.5, 'user3': 0},
     }
     users = fs.get_users_dict(self.cursor)
     self.assertEqual(fs.get_status_dict(self.cursor, users), 
                      expected_status)
Пример #9
0
 def test_get_status_list(self):
     self.assertEqual(fs.get_status_list(self.cursor), [])
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     fs.insert_expense(self.cursor, 'test', 20, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test', 30, '20130101', 1, (1, 2))
     fs.insert_expense(self.cursor, 'test', 40, '20130101', 2, (1, 2))
     self.connection.commit()
     expected_status =  [('user2', 'user1', 5)]
     self.assertEqual(fs.get_status_list(self.cursor), expected_status)
     fs.insert_expense(self.cursor, 'test', 40, '20130101', 2, (1, 2))
     fs.insert_expense(self.cursor, 'test', 40, '20130101', 2, (1, 2))
     fs.insert_expense(self.cursor, 'test', 5, '20130101', 1, (1, 2))
     self.connection.commit()
     expected_status =  [('user1', 'user2', 32.5)]
     self.assertEqual(fs.get_status_list(self.cursor), expected_status)
     fs.insert_user(self.cursor, 'user3')
     fs.insert_expense(self.cursor, 'test', 105, '20130101', 3, (1, 2))
     fs.insert_expense(self.cursor, 'test', 210, '20130101', 3, (1, 2, 3))
     self.connection.commit()
     expected_status =  [
         ('user1', 'user2', 32.5),
         ('user1', 'user3', 122.5),
         ('user2', 'user3', 122.5),
     ]
     self.assertEqual(fs.get_status_list(self.cursor), expected_status)