Skip to content

Commit

Permalink
Update tests to work with the new statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Dec 26, 2024
1 parent 43eeed4 commit d29236e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
15 changes: 10 additions & 5 deletions ihatemoney/tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,8 @@ def test_statistics(self):
"/api/projects/raclette/statistics", headers=self.get_auth("raclette")
)
self.assertStatus(200, req)
assert [
received_stats = json.loads(req.data.decode("utf-8"))
assert received_stats == [
{
"balance": 12.5,
"member": {
Expand All @@ -824,7 +825,9 @@ def test_statistics(self):
"weight": 1.0,
},
"paid": 25.0,
"spent": 12.5,
"received": 0.0,
"spent": -12.5,
"transferred": 0.0,
},
{
"balance": -12.5,
Expand All @@ -834,10 +837,12 @@ def test_statistics(self):
"name": "jeanne",
"weight": 1.0,
},
"paid": 0,
"spent": 12.5,
"paid": 0.0,
"received": 0.0,
"spent": -12.5,
"transferred": 0.0,
},
] == json.loads(req.data.decode("utf-8"))
]

def test_username_xss(self):
# create a project
Expand Down
56 changes: 37 additions & 19 deletions ihatemoney/tests/budget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,14 +1069,25 @@ def test_statistics(self):
assert len(project.active_months_range()) == 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")

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>"
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"))

assert re.search(regex, response.data.decode("utf-8"))
# create bills
self.client.post(
"/raclette/add",
Expand Down Expand Up @@ -1115,22 +1126,29 @@ def test_statistics(self):
)

response = self.client.get("/raclette/statistics")
regex = r"<td class=\"d-md-none\">{}</td>\s*<td>{}</td>\s*<td>{}</td>"
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")
)
html = 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
# same as in the main table.
order = ["jeanne", "pépé", "tata", "zorglub"]
Expand Down

0 comments on commit d29236e

Please sign in to comment.