Ejemplo n.º 1
0
 def test_get_users_list(self):
     self.assertEqual(fs.get_users_list(self.cursor), [])
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     users_expected = [(1, 'user1'), (2, 'user2')]
     self.assertEqual(fs.get_users_list(self.cursor), users_expected)
Ejemplo n.º 2
0
 def test_get_users_dict(self):
     self.assertEqual(fs.get_users_dict(self.cursor), {})
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     users_expected = {1: 'user1', 2: 'user2'}
     self.assertEqual(fs.get_users_dict(self.cursor), users_expected)
Ejemplo n.º 3
0
 def test_update_expense_that_does_not_exist(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     values = (1, 2, '', ' ', 'a')
     for x in values:
         self.assertRaises(fs.ExpenseNotFoundError, fs.update_expense, 
                           self.cursor, x, 'edit', 30, '20130102', 2, (1,))
Ejemplo n.º 4
0
 def test_insert_expense_with_invalid_date(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     values = ('20130229', 'jfjfjf', '130101', '', ' ')
     for x in values:
         self.assertRaises(fs.IllegalExpenseDateError, fs.insert_expense, 
                           self.cursor, 'test', 20, x, 1, (1, 2))
     self.connection.commit()
Ejemplo n.º 5
0
 def test_insert_expense_with_unknown_debtor(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     values = (3, 4, 9000, 'a', '')
     for x in values:
         self.assertRaises(fs.UserNotFoundError, fs.insert_expense, 
                           self.cursor, 'test', 20, '20130101', 1, (1, x))
     self.connection.commit()
Ejemplo n.º 6
0
 def test_insert_expense_with_invalid_title(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     values = (' title ', ' title', '', ' ')
     for x in values:
         self.assertRaises(fs.IllegalExpenseTitleError, fs.insert_expense, 
                           self.cursor, x, 20, '20130101', 1, (1, 2))
     self.connection.commit()
Ejemplo n.º 7
0
 def test_insert_expense_with_invalid_cost(self):
     fs.insert_user(self.cursor, 'user1')
     fs.insert_user(self.cursor, 'user2')
     self.connection.commit()
     values = (-30, '-30', 0, '0', '', ' ', '-.2')
     for x in values:
         self.assertRaises(fs.IllegalExpenseCostError, fs.insert_expense, 
                           self.cursor, 'test', x, '20130101', 1, (1, 2))
     self.connection.commit()
Ejemplo n.º 8
0
 def test_update_expense_with_unknown_payer(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', x, (2,))
     self.connection.commit()
Ejemplo n.º 9
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)
Ejemplo n.º 10
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])
Ejemplo n.º 11
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)
Ejemplo n.º 12
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])
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def test_get_u_name(self):
     fs.insert_user(self.cursor, 'user1')
     self.connection.commit()
     self.assertEqual(fs.get_u_name(self.cursor, 1), 'user1')
Ejemplo n.º 16
0
 def test_insert_user_twice(self):
     '''insert_user should raise an exception if u_name already exists'''
     fs.insert_user(self.cursor, 'user1')
     self.assertRaises(sqlite3.IntegrityError, fs.insert_user, 
                       self.cursor, 'user1')