Skip to content

Commit

Permalink
[tests] test interface_delete
Browse files Browse the repository at this point in the history
Refs #641
  • Loading branch information
lukasjuhrich committed Jun 29, 2023
1 parent 7632d66 commit 99623d9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions tests/frontend/test_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2015 The Pycroft Authors. See the AUTHORS file.
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.

import pytest
from flask import url_for

from pycroft.model.host import Host, Interface
from tests import factories as f

from .assertions import TestClient


@pytest.fixture(scope="module")
def client(module_test_client: TestClient) -> TestClient:
return module_test_client


@pytest.fixture(scope="module")
def host(module_session) -> Host:
return f.HostFactory(interface=None)


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


pytestmark = pytest.mark.usefixtures("admin_logged_in")


@pytest.mark.usefixtures("session")
class TestInterfaceDelete:
def test_delete_nonexistent_interface(self, client):
client.assert_url_response_code(
url_for("host.interface_delete", interface_id=999), code=404
)

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

def test_delete_interface_post(self, session, client, interface):
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
2 changes: 1 addition & 1 deletion web/blueprints/host/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def default_response():
with handle_errors(session.session):
lib_host.interface_delete(interface, current_user)
session.session.commit()
except PycroftException:
except PycroftException: # pragma: no cover
return default_response()

flash("Interface erfolgreich gelöscht.", 'success')
Expand Down

0 comments on commit 99623d9

Please sign in to comment.