mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-15 17:01:49 +02:00
Compare commits
4 commits
81b00967eb
...
224bcc3a8e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
224bcc3a8e | ||
![]() |
1d62f74f0b | ||
![]() |
3b74e2cea1 | ||
![]() |
77e33286aa |
7 changed files with 109 additions and 10 deletions
1
bin/python
Symbolic link
1
bin/python
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
python3
|
1
bin/python3
Symbolic link
1
bin/python3
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/usr/bin/python3
|
1
bin/python3.10
Symbolic link
1
bin/python3.10
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
python3
|
|
@ -4,6 +4,7 @@ import socket
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from flask import g, request, url_for
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
from werkzeug.security import check_password_hash
|
from werkzeug.security import check_password_hash
|
||||||
|
|
||||||
|
@ -164,6 +165,91 @@ class ModelsTestCase(IhatemoneyTestCase):
|
||||||
pay_each_expected = 10 / 3
|
pay_each_expected = 10 / 3
|
||||||
self.assertEqual(bill.amount / weight, pay_each_expected)
|
self.assertEqual(bill.amount / weight, pay_each_expected)
|
||||||
|
|
||||||
|
def test_remove_member(self):
|
||||||
|
# make project
|
||||||
|
self.post_project("raclette")
|
||||||
|
|
||||||
|
# add members
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "zorglub", "weight": 2})
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "fred"})
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "tata"})
|
||||||
|
|
||||||
|
# make bills
|
||||||
|
self.client.post(
|
||||||
|
"/raclette/add",
|
||||||
|
data={
|
||||||
|
"date": "2011-08-10",
|
||||||
|
"what": "red wine",
|
||||||
|
"payer": 1,
|
||||||
|
"payed_for": [2],
|
||||||
|
"amount": "20",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
project = models.Project.query.get_by_name(name="raclette")
|
||||||
|
|
||||||
|
zorglub = models.Person.query.get_by_name(name="zorglub", project=project)
|
||||||
|
tata = models.Person.query.get_by_name(name="tata", project=project)
|
||||||
|
fred = models.Person.query.get_by_name(name="fred", project=project)
|
||||||
|
|
||||||
|
g.project.remove_member(tata.id)
|
||||||
|
# tata should be fully removed because they are not connected to a bill
|
||||||
|
self.assertEqual(project.members, [zorglub, fred])
|
||||||
|
|
||||||
|
g.project.remove_member(zorglub.id)
|
||||||
|
|
||||||
|
# zorglub is connected to a bill so they should be deactivated
|
||||||
|
self.assertEqual(project.members, [zorglub, fred])
|
||||||
|
self.assertEqual(zorglub.activated, False)
|
||||||
|
|
||||||
|
def test_deactivated_user_bill(self):
|
||||||
|
|
||||||
|
self.post_project("raclette")
|
||||||
|
|
||||||
|
# add members
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "zorglub", "weight": 2})
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "fred"})
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "tata"})
|
||||||
|
|
||||||
|
project = models.Project.query.get_by_name(name="raclette")
|
||||||
|
zorglub = models.Person.query.get_by_name(name="zorglub", project=project)
|
||||||
|
|
||||||
|
self.client.post(
|
||||||
|
"/raclette/add",
|
||||||
|
data={
|
||||||
|
"date": "2011-08-10",
|
||||||
|
"what": "red wine",
|
||||||
|
"payer": 1,
|
||||||
|
"payed_for": [2],
|
||||||
|
"amount": "20",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
g.project.remove_member(zorglub.id)
|
||||||
|
|
||||||
|
self.client.post(
|
||||||
|
"/raclette/edit",
|
||||||
|
data={
|
||||||
|
"date": "2011-08-10",
|
||||||
|
"what": "red wine",
|
||||||
|
"payer": 1,
|
||||||
|
"payed_for": [2],
|
||||||
|
"amount": "30",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
zorglub_bill = models.Bill.query.options(
|
||||||
|
orm.subqueryload(models.Bill.owers)
|
||||||
|
).filter(models.Bill.owers.contains(zorglub))
|
||||||
|
for bill in zorglub_bill:
|
||||||
|
id = bill.id
|
||||||
|
resp = self.client.post("/<raclette/edit/" + str(id), follow_redirects=True)
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
assert request.path == url_for(".list_bills")
|
||||||
|
|
||||||
|
# user edits a form, redirect + error should occur
|
||||||
|
# Check that we were redirected to the list of bills page
|
||||||
|
|
||||||
def test_bill_pay_each(self):
|
def test_bill_pay_each(self):
|
||||||
|
|
||||||
self.post_project("raclette")
|
self.post_project("raclette")
|
||||||
|
|
|
@ -773,6 +773,9 @@ def edit_bill(bill_id):
|
||||||
bill = Bill.query.get(g.project, bill_id)
|
bill = Bill.query.get(g.project, bill_id)
|
||||||
if not bill:
|
if not bill:
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
|
payer_id = bill.payer_id
|
||||||
|
payer = Person.query.get(payer_id)
|
||||||
|
if payer.activated:
|
||||||
|
|
||||||
form = get_billform_for(g.project, set_default=False)
|
form = get_billform_for(g.project, set_default=False)
|
||||||
|
|
||||||
|
@ -787,6 +790,9 @@ def edit_bill(bill_id):
|
||||||
form.fill(bill, g.project)
|
form.fill(bill, g.project)
|
||||||
|
|
||||||
return render_template("add_bill.html", form=form, edit=True)
|
return render_template("add_bill.html", form=form, edit=True)
|
||||||
|
else:
|
||||||
|
flash(_("The payer is deactivated. You cannot edit the bill."))
|
||||||
|
return redirect(url_for(".list_bills"))
|
||||||
|
|
||||||
|
|
||||||
@main.route("/lang/<lang>")
|
@main.route("/lang/<lang>")
|
||||||
|
|
1
lib64
Symbolic link
1
lib64
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
lib
|
3
pyvenv.cfg
Normal file
3
pyvenv.cfg
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
home = /usr/bin
|
||||||
|
include-system-site-packages = false
|
||||||
|
version = 3.10.6
|
Loading…
Reference in a new issue