add test case

This commit is contained in:
Glandos 2023-01-29 22:58:08 +01:00
parent 3a984ee206
commit d477b41d9a
2 changed files with 25 additions and 7 deletions

View file

@ -926,13 +926,8 @@ class BudgetTestCase(IhatemoneyTestCase):
self.assertIn('<div class="alert alert-danger">', resp.data.decode("utf-8"))
# test access to the dashboard when it is activated
self.app.config["ACTIVATE_ADMIN_DASHBOARD"] = True
self.app.config["ADMIN_PASSWORD"] = generate_password_hash("adminpass")
resp = self.client.post(
"/admin?goto=%2Fdashboard",
data={"admin_password": "adminpass"},
follow_redirects=True,
)
self.enable_admin()
resp = self.client.get("/dashboard")
self.assertIn(
"""<thead>
<tr>
@ -941,6 +936,20 @@ class BudgetTestCase(IhatemoneyTestCase):
resp.data.decode("utf-8"),
)
def test_dashboard_project_deletion(self):
self.post_project("raclette")
self.enable_admin()
resp = self.client.get("/dashboard")
pattern = re.compile(r"<form id=\"delete-project\" [^>]*?action=\"(.*?)\"")
match = pattern.search(resp.data.decode("utf-8"))
assert match is not None
assert match.group(1) is not None
resp = self.client.post(match.group(1))
# project removed
assert len(models.Project.query.all()) == 0
def test_statistics_page(self):
self.post_project("raclette")
response = self.client.get("/raclette/statistics")

View file

@ -110,3 +110,12 @@ class IhatemoneyTestCase(BaseTestCase):
resp.status_code,
f"{url} expected {expected}, got {resp.status_code}",
)
def enable_admin(self, password="adminpass"):
self.app.config["ACTIVATE_ADMIN_DASHBOARD"] = True
self.app.config["ADMIN_PASSWORD"] = generate_password_hash(password)
return self.client.post(
"/admin?goto=%2Fdashboard",
data={"admin_password": password},
follow_redirects=True,
)