mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
Update tests to work with the new statistics
This commit is contained in:
parent
43eeed41f4
commit
0a50941c35
2 changed files with 76 additions and 42 deletions
|
@ -814,7 +814,8 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
"/api/projects/raclette/statistics", headers=self.get_auth("raclette")
|
"/api/projects/raclette/statistics", headers=self.get_auth("raclette")
|
||||||
)
|
)
|
||||||
self.assertStatus(200, req)
|
self.assertStatus(200, req)
|
||||||
assert [
|
received_stats = json.loads(req.data.decode("utf-8"))
|
||||||
|
assert received_stats == [
|
||||||
{
|
{
|
||||||
"balance": 12.5,
|
"balance": 12.5,
|
||||||
"member": {
|
"member": {
|
||||||
|
@ -824,7 +825,9 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
"weight": 1.0,
|
"weight": 1.0,
|
||||||
},
|
},
|
||||||
"paid": 25.0,
|
"paid": 25.0,
|
||||||
"spent": 12.5,
|
"received": 0.0,
|
||||||
|
"spent": -12.5,
|
||||||
|
"transferred": 0.0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"balance": -12.5,
|
"balance": -12.5,
|
||||||
|
@ -834,10 +837,12 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
"name": "jeanne",
|
"name": "jeanne",
|
||||||
"weight": 1.0,
|
"weight": 1.0,
|
||||||
},
|
},
|
||||||
"paid": 0,
|
"paid": 0.0,
|
||||||
"spent": 12.5,
|
"received": 0.0,
|
||||||
|
"spent": -12.5,
|
||||||
|
"transferred": 0.0,
|
||||||
},
|
},
|
||||||
] == json.loads(req.data.decode("utf-8"))
|
]
|
||||||
|
|
||||||
def test_username_xss(self):
|
def test_username_xss(self):
|
||||||
# create a project
|
# create a project
|
||||||
|
|
|
@ -790,15 +790,18 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
self.client.post("/rent/members/add", data={"name": "bob"})
|
self.client.post("/rent/members/add", data={"name": "bob"})
|
||||||
self.client.post("/rent/members/add", data={"name": "alice"})
|
self.client.post("/rent/members/add", data={"name": "alice"})
|
||||||
|
|
||||||
members_ids = [m.id for m in self.get_project("rent").members]
|
everybody = [m.id for m in self.get_project("rent").members]
|
||||||
# create a bill to test reimbursement
|
bob = everybody[0]
|
||||||
|
alice = everybody[1]
|
||||||
|
|
||||||
|
# create a bill
|
||||||
self.client.post(
|
self.client.post(
|
||||||
"/rent/add",
|
"/rent/add",
|
||||||
data={
|
data={
|
||||||
"date": "2022-12-12",
|
"date": "2022-12-12",
|
||||||
"what": "december rent",
|
"what": "december rent",
|
||||||
"payer": members_ids[0], # bob
|
"payer": bob,
|
||||||
"payed_for": members_ids, # bob and alice
|
"payed_for": everybody,
|
||||||
"bill_type": "Expense",
|
"bill_type": "Expense",
|
||||||
"amount": "1000",
|
"amount": "1000",
|
||||||
},
|
},
|
||||||
|
@ -806,32 +809,40 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
# check balance
|
# check balance
|
||||||
balance = self.get_project("rent").balance
|
balance = self.get_project("rent").balance
|
||||||
assert set(balance.values()), set([500 == -500])
|
assert set(balance.values()), set([500 == -500])
|
||||||
# check paid
|
|
||||||
bob_paid = self.get_project("rent").full_balance[2][members_ids[0]]
|
project = self.get_project("rent")
|
||||||
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
|
bob_paid = project.full_balance[2][bob]
|
||||||
|
alice_paid = project.full_balance[2][alice]
|
||||||
assert bob_paid == 1000
|
assert bob_paid == 1000
|
||||||
assert alice_paid == 0
|
assert alice_paid == 0
|
||||||
|
|
||||||
# test reimbursement bill
|
# reimbursement bill
|
||||||
self.client.post(
|
self.client.post(
|
||||||
"/rent/add",
|
"/rent/add",
|
||||||
data={
|
data={
|
||||||
"date": "2022-12-13",
|
"date": "2022-12-13",
|
||||||
"what": "reimbursement for rent",
|
"what": "reimbursement for rent",
|
||||||
"payer": members_ids[1], # alice
|
"payer": alice,
|
||||||
"payed_for": members_ids[0], # bob
|
"payed_for": bob,
|
||||||
"bill_type": "Reimbursement",
|
"bill_type": "Reimbursement",
|
||||||
"amount": "500",
|
"amount": "500",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
balance = self.get_project("rent").balance
|
balance = project.balance
|
||||||
assert set(balance.values()), set([0 == 0])
|
assert set(balance.values()), set([0 == 0])
|
||||||
# check paid
|
|
||||||
bob_paid = self.get_project("rent").full_balance[2][members_ids[0]]
|
# After the reimbursement, the full balance should be populated with
|
||||||
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
|
# transfer items
|
||||||
assert bob_paid == 500
|
bob_paid = project.full_balance[2][bob]
|
||||||
assert alice_paid == 500
|
alice_paid = project.full_balance[2][alice]
|
||||||
|
assert bob_paid == 1000
|
||||||
|
assert alice_paid == 0
|
||||||
|
|
||||||
|
bob_received = project.full_balance[4][bob]
|
||||||
|
alice_transferred = project.full_balance[3][alice]
|
||||||
|
assert bob_received == 500
|
||||||
|
assert alice_transferred == 500
|
||||||
|
|
||||||
def test_weighted_balance(self):
|
def test_weighted_balance(self):
|
||||||
self.post_project("raclette")
|
self.post_project("raclette")
|
||||||
|
@ -1069,14 +1080,25 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
assert len(project.active_months_range()) == 0
|
assert len(project.active_months_range()) == 0
|
||||||
assert len(project.monthly_stats) == 0
|
assert len(project.monthly_stats) == 0
|
||||||
|
|
||||||
# Check that the "monthly expenses" table is empty
|
# Check that the "monthly expenses" table exists
|
||||||
|
# and is empty.
|
||||||
response = self.client.get("/raclette/statistics")
|
response = self.client.get("/raclette/statistics")
|
||||||
regex = (
|
|
||||||
r"<table id=\"monthly_stats\".*>\s*<thead>\s*<tr>\s*<th>Period</th>\s*"
|
|
||||||
r"<th>Spent</th>\s*</tr>\s*</thead>\s*<tbody>\s*</tbody>\s*</table>"
|
|
||||||
)
|
|
||||||
assert re.search(regex, response.data.decode("utf-8"))
|
|
||||||
|
|
||||||
|
regex = (
|
||||||
|
r'<table id="monthly_stats" class="table table-striped">\n'
|
||||||
|
r" <thead>\n"
|
||||||
|
r" <tr>\n"
|
||||||
|
r" <th>Period</th>\n"
|
||||||
|
r" <th>Expenses</th>\n"
|
||||||
|
r" </tr>\n"
|
||||||
|
r" </thead>\n"
|
||||||
|
r" <tbody>\n"
|
||||||
|
r" \n"
|
||||||
|
r" </tbody>\n"
|
||||||
|
r" </table>"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert re.search(regex, response.data.decode("utf-8"))
|
||||||
# create bills
|
# create bills
|
||||||
self.client.post(
|
self.client.post(
|
||||||
"/raclette/add",
|
"/raclette/add",
|
||||||
|
@ -1115,22 +1137,29 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
response = self.client.get("/raclette/statistics")
|
response = self.client.get("/raclette/statistics")
|
||||||
regex = r"<td class=\"d-md-none\">{}</td>\s*<td>{}</td>\s*<td>{}</td>"
|
html = response.data.decode("utf-8")
|
||||||
assert re.search(
|
|
||||||
regex.format("zorglub", r"\$20\.00", r"\$31\.67"),
|
|
||||||
response.data.decode("utf-8"),
|
|
||||||
)
|
|
||||||
assert re.search(
|
|
||||||
regex.format("jeanne", r"\$20\.00", r"\$5\.83"),
|
|
||||||
response.data.decode("utf-8"),
|
|
||||||
)
|
|
||||||
assert re.search(
|
|
||||||
regex.format("tata", r"\$0\.00", r"\$2\.50"), response.data.decode("utf-8")
|
|
||||||
)
|
|
||||||
assert re.search(
|
|
||||||
regex.format("pépé", r"\$0\.00", r"\$0\.00"), response.data.decode("utf-8")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
def stat_entry(name, paid, spent, transferred=None, received=None):
|
||||||
|
return (
|
||||||
|
f'<td class="d-md-none">{name}</td>\n'
|
||||||
|
f" <td>{paid}</td>\n"
|
||||||
|
f" <td>{spent}</td>\n"
|
||||||
|
# f" <td>${spent}</td>\n"
|
||||||
|
# f" <td>${transferred}</td>"
|
||||||
|
)
|
||||||
|
|
||||||
|
# set_trace()
|
||||||
|
|
||||||
|
# regex = (
|
||||||
|
# r'\s*<td class="d-md-none">{}</td>\n'
|
||||||
|
# r"\s*<td>{}</td>\n"
|
||||||
|
# r"\s*<td>{}</td>\n"
|
||||||
|
# )
|
||||||
|
|
||||||
|
assert stat_entry("zorglub", "$20.00", "-$31.67") in html
|
||||||
|
assert stat_entry("jeanne", "$20.00", "-$5.83") in html
|
||||||
|
assert stat_entry("tata", "$0.00", "-$2.50") in html
|
||||||
|
assert stat_entry("pépé", "$0.00", "-$0.00") in html
|
||||||
# Check that the order of participants in the sidebar table is the
|
# Check that the order of participants in the sidebar table is the
|
||||||
# same as in the main table.
|
# same as in the main table.
|
||||||
order = ["jeanne", "pépé", "tata", "zorglub"]
|
order = ["jeanne", "pépé", "tata", "zorglub"]
|
||||||
|
|
Loading…
Reference in a new issue