Skip to content

Commit

Permalink
Test for form errors instead of error flash
Browse files Browse the repository at this point in the history
  • Loading branch information
FestplattenSchnitzel committed Apr 15, 2024
1 parent 130e7cf commit 313257a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/blueprints/test_bp_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,21 @@ def test_get(self, client: TestClient, endpoint, template):
client.assert_ok(endpoint)

def test_post_flashes(self, client: TestClient, endpoint, template):
with client.renders_template(template), client.capture_flashes() as flashed:
with client.renders_template(template) as recorded:
client.assert_ok(endpoint, method="POST")
assert flashed
assert all(m.category == "error" for m in flashed)

[(_, template_args)] = recorded
assert template_args["form"].errors

def test_invalid_data_flashes(
self, client: TestClient, endpoint, template, invalid_data
):
with client.renders_template(template), client.flashes_message(
".*", category="error"
):
with client.renders_template(template) as recorded:
client.assert_ok(endpoint, data=invalid_data, method="POST")

[(_, template_args)] = recorded
assert template_args["form"].errors

@pytest.fixture()
def silence_logs(self):
logging.disable()
Expand Down

0 comments on commit 313257a

Please sign in to comment.