Skip to content

Commit

Permalink
[tests] test interface_edit
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjuhrich committed Jun 29, 2023
1 parent 99623d9 commit 8f521cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
36 changes: 34 additions & 2 deletions tests/frontend/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def host(module_session) -> Host:


@pytest.fixture(scope="module")
def interface(module_session) -> Interface:
def interface(module_session, host) -> Interface:
return f.InterfaceFactory(host=host)


Expand All @@ -42,11 +42,43 @@ def test_delete_interface_get(self, client, interface):
url_for("host.interface_delete", interface_id=interface.id)
)

def test_delete_interface_post(self, session, client, interface):
def test_delete_interface_post(self, session, client, interface, host):
with client.flashes_message("Interface.*gelöscht", category="success"):
client.assert_url_redirects(
url_for("host.interface_delete", interface_id=interface.id),
method="POST",
)
session.refresh(host)
assert interface not in host.interfaces


@pytest.mark.usefixtures("session")
class TestInterfaceEdit:
def test_edit_nonexistent_interface(self, client):
client.assert_url_response_code(
url_for("host.interface_edit", interface_id=999), code=404
)

def test_edit_interface_get(self, client, interface):
with client.renders_template("generic_form.html"):
client.assert_url_ok(
url_for("host.interface_edit", interface_id=interface.id)
)

def test_edit_interface_post_invalid_data(self, client, interface):
with client.renders_template("generic_form.html"):
client.assert_url_ok(
url_for("host.interface_edit", interface_id=interface.id),
data={"mac": "invalid"},
)

def test_edit_interface_success(self, session, client, interface):
with client.flashes_message("Interface.*bearbeitet", category="success"):
client.assert_url_redirects(
url_for("host.interface_edit", interface_id=interface.id),
method="POST",
data={"mac": "00:11:22:33:44:55", "name": "new name"},
)
session.refresh(interface)
assert interface.mac == "00:11:22:33:44:55"
assert interface.name == "new name"
2 changes: 1 addition & 1 deletion web/blueprints/host/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def default_response():
processor=current_user
)
session.session.commit()
except PycroftException:
except PycroftException: # pragma: no cover
return default_response()

flash("Interface erfolgreich bearbeitet.", 'success')
Expand Down

0 comments on commit 8f521cc

Please sign in to comment.