mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Add some more tests about membership. (#14)
Fixes #15 as invalid: deactivated users are not listed on the bill form or on the balance.
This commit is contained in:
parent
683c7ee0b8
commit
822058b251
4 changed files with 48 additions and 4 deletions
|
@ -62,7 +62,6 @@ class BillForm(Form):
|
||||||
bill.what=self.what.data
|
bill.what=self.what.data
|
||||||
bill.date=self.date.data
|
bill.date=self.date.data
|
||||||
bill.owers = [Person.query.get(ower) for ower in self.payed_for.data]
|
bill.owers = [Person.query.get(ower) for ower in self.payed_for.data]
|
||||||
print self.payed_for.data
|
|
||||||
|
|
||||||
return bill
|
return bill
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Person(db.Model):
|
||||||
name = db.Column(db.UnicodeText)
|
name = db.Column(db.UnicodeText)
|
||||||
activated = db.Column(db.Boolean, default=True)
|
activated = db.Column(db.Boolean, default=True)
|
||||||
|
|
||||||
def is_used(self):
|
def has_bills(self):
|
||||||
bills_as_ower_number = db.session.query(Bill).join(billowers, Person)\
|
bills_as_ower_number = db.session.query(Bill).join(billowers, Person)\
|
||||||
.filter("Bill.id == billowers.bill_id")\
|
.filter("Bill.id == billowers.bill_id")\
|
||||||
.filter("Person.id == billowers.person_id")\
|
.filter("Person.id == billowers.person_id")\
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -119,7 +120,7 @@ class BudgetTestCase(TestCase):
|
||||||
# no new project added
|
# no new project added
|
||||||
self.assertEqual(len(models.Project.query.all()), 1)
|
self.assertEqual(len(models.Project.query.all()), 1)
|
||||||
|
|
||||||
def test_add_member(self):
|
def test_membership(self):
|
||||||
self.create_project("raclette")
|
self.create_project("raclette")
|
||||||
self.login("raclette")
|
self.login("raclette")
|
||||||
|
|
||||||
|
@ -132,6 +133,50 @@ class BudgetTestCase(TestCase):
|
||||||
# should not accept him
|
# should not accept him
|
||||||
self.assertEqual(len(models.Project.query.get("raclette").members), 1)
|
self.assertEqual(len(models.Project.query.get("raclette").members), 1)
|
||||||
|
|
||||||
|
# add fred
|
||||||
|
self.app.post("/raclette/members/add", data={'name': 'fred' })
|
||||||
|
self.assertEqual(len(models.Project.query.get("raclette").members), 2)
|
||||||
|
|
||||||
|
# check fred is present in the bills page
|
||||||
|
result = self.app.get("/raclette/")
|
||||||
|
self.assertIn("fred", result.data)
|
||||||
|
|
||||||
|
# remove fred
|
||||||
|
self.app.post("/raclette/members/%s/delete" %
|
||||||
|
models.Project.query.get("raclette").members[-1].id)
|
||||||
|
|
||||||
|
# as fred is not bound to any bill, he is removed
|
||||||
|
self.assertEqual(len(models.Project.query.get("raclette").members), 1)
|
||||||
|
|
||||||
|
# add fred again
|
||||||
|
self.app.post("/raclette/members/add", data={'name': 'fred' })
|
||||||
|
fred_id = models.Project.query.get("raclette").members[-1].id
|
||||||
|
|
||||||
|
# bound him to a bill
|
||||||
|
result = self.app.post("/raclette/add", data={
|
||||||
|
'date': '2011-08-10',
|
||||||
|
'what': u'fromage à raclette',
|
||||||
|
'payer': fred_id,
|
||||||
|
'payed_for': [fred_id,],
|
||||||
|
'amount': '25',
|
||||||
|
})
|
||||||
|
|
||||||
|
# remove fred
|
||||||
|
self.app.post("/raclette/members/%s/delete" % fred_id)
|
||||||
|
|
||||||
|
# he is still in the database, but is deactivated
|
||||||
|
self.assertEqual(len(models.Project.query.get("raclette").members), 2)
|
||||||
|
self.assertEqual(
|
||||||
|
len(models.Project.query.get("raclette").active_members), 1)
|
||||||
|
|
||||||
|
# as fred is now deactivated, check that he is not listed when adding
|
||||||
|
# a bill or displaying the balance
|
||||||
|
result = self.app.get("/raclette/")
|
||||||
|
self.assertNotIn("/raclette/members/%s/delete" % fred_id, result.data)
|
||||||
|
|
||||||
|
result = self.app.get("/raclette/add")
|
||||||
|
self.assertNotIn("fred", result.data)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -150,7 +150,7 @@ def add_member(project):
|
||||||
def remove_member(project, member_id):
|
def remove_member(project, member_id):
|
||||||
person = Person.query.get_or_404(member_id)
|
person = Person.query.get_or_404(member_id)
|
||||||
if person.project == project:
|
if person.project == project:
|
||||||
if not person.is_used():
|
if not person.has_bills():
|
||||||
db.session.delete(person)
|
db.session.delete(person)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("User '%s' has been removed" % person.name)
|
flash("User '%s' has been removed" % person.name)
|
||||||
|
|
Loading…
Reference in a new issue