Skip to content

Commit

Permalink
added test for mpsk
Browse files Browse the repository at this point in the history
added tests for mpsk
added capability displayable to test
  • Loading branch information
agmes4 committed Jan 19, 2025
1 parent 10dc7a8 commit e8aadc6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
5 changes: 0 additions & 5 deletions sipa/model/pycroft/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import json
import logging
from datetime import date

Expand Down Expand Up @@ -363,10 +362,6 @@ def add_mpsk_client(self, name, mac, password):
elif status == 412:
raise NoWiFiPasswordGenerated


if type(response) is not dict:
raise ValueError(f"Invalid response from {response}")

if 'name' in response.keys() and 'mac' in response.keys() and 'id' in response.keys():
return MPSKClientEntry(name=response.get('name'), mac=response.get('mac'), id=response.get('id'))
else:
Expand Down
78 changes: 78 additions & 0 deletions tests/blueprints/usersuite/test_usersuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def usersuite_passed_rows(_usersuite_index) -> list[TableRow]:
"status",
"userdb_status", # unsupported
"wifi_password",
"mpsk_clients",
),
)
def test_usersuite_passes_correct_rows(usersuite_passed_rows, propname):
Expand Down Expand Up @@ -101,3 +102,80 @@ def test_usersuite_contains_urls(usersuite_response):
assert re.search(
f'href="[^"]*{url}[^"]*"', usersuite_response.data.decode()
), f"Usersuite does not contain any reference to url {url!r}"


def test_usersuite_form_add_mpsk(client):
client.assert_ok("usersuite.add_mpsk")


def test_usersuite_change_mpsk_not_found(client):
resp = client.get(url_for("usersuite.change_mpsk", mpsk_id=1))
assert resp.status_code == 404

def test_usersuite_delete_mpsk_not_found(client):
resp = client.get(url_for("usersuite.delete_mpsk", mpsk_id=1))
assert resp.status_code == 404


@pytest.mark.parametrize(
"data", ({"password": "test", "name": "a", "mac": "88:88:88:88:87:88"},)
)
def test_add_mpsk_client(client, data):
resp = client.post(url_for("usersuite.add_mpsk"), data=data)
assert resp.status_code == 302

assert resp.headers["location"] == url_for("usersuite.view_mpsk")


@pytest.mark.parametrize(
"data",
(
{"password": "test"},
{"name": "a"},
{"mac": "88:88:88:88:87:88"},
{"password": "test", "name": "", "mac": "88:88:88:88:87:88"},
{"password": "test", "name": "", "mac": "FF:FF:FF:FF:FF:FF"},
),
)
def test_add_invalid_mpsk(client, data):
resp = client.post(url_for("usersuite.add_mpsk"), data=data)
assert resp.status_code == 200

@pytest.mark.parametrize(
"data",
(
{"password": "test"},
{"name": "a"},
{"mac": "88:88:88:88:87:88"},
{"password": "test", "name": "", "mac": "88:88:88:88:87:88"},
{"password": "test", "name": "", "mac": "FF:FF:FF:FF:FF:FF"},
),
)
def test_change_invalid_mpsk(client, data):
resp = client.post(url_for("usersuite.add_mpsk"), data={"password": "test", "name": "a", "mac": "88:88:88:88:87:88"})
assert resp.status_code == 302

resp = client.post(url_for("usersuite.change_mpsk", mpsk_id=0), data=data)
assert resp.status_code == 200

@pytest.mark.parametrize(
"data", ({"password": "test", "name": "a", "mac": "88:88:88:88:87:88"},)
)
def test_delete_mpsk(client, data):
resp = client.post(url_for("usersuite.add_mpsk"), data=data)
assert resp.status_code == 302

assert resp.headers["location"] == url_for("usersuite.view_mpsk")
resp = client.post(
url_for("usersuite.delete_mpsk", mpsk_id=0), data={"password": "test"}
)
assert resp.status_code == 302

assert resp.headers["location"] == url_for("usersuite.view_mpsk")


def test_usersuite_get_no_mpsks(client):
client.assert_ok("usersuite.view_mpsk")
resp = client.get("usersuite.view_mpsk")

assert "delete-mpsk" not in str(resp)
4 changes: 2 additions & 2 deletions tests/model/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def sample_users(app) -> dict[str, SampleUserData]:
# 'attr_name': ('key_in_sample_dict', Capabilities())
"realname": ("name", NO_CAPABILITIES),
"login": ("uid", NO_CAPABILITIES),
"mac": ("mac", Capabilities(edit=True, delete=False)),
"mail": ("mail", Capabilities(edit=True, delete=False)),
"mac": ("mac", Capabilities(edit=True, delete=False, displayable=True)),
"mail": ("mail", Capabilities(edit=True, delete=False, displayable=True)),
"address": ("address", NO_CAPABILITIES),
"ips": ("ip", NO_CAPABILITIES),
"status": ("status", NO_CAPABILITIES),
Expand Down

0 comments on commit e8aadc6

Please sign in to comment.