From e281446016fc7c431ea569c1489fafbf17abfaaa Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Sep 2024 14:08:48 +0200 Subject: [PATCH] api mpsk api more clients the api is now able to add more clients Signed-off-by: Alex #744 --- pycroft/lib/mpsk_client.py | 4 ++-- tests/model/test_mpsk.py | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pycroft/lib/mpsk_client.py b/pycroft/lib/mpsk_client.py index ae64e2b42..ca29f365c 100644 --- a/pycroft/lib/mpsk_client.py +++ b/pycroft/lib/mpsk_client.py @@ -44,9 +44,9 @@ def mpsk_client_create(owner: User, name: str, mac: str, processor: User, api=Fa :param processor: the user who initiated the mac address change. :param api: whether to create an api client or not. If set Ture checks rather a user exceeds the maximum of clients (set to 10). """ - if len(owner.mpsks) >= 10 and api: + if len(owner.mpsks) >= 30 and api: raise AmountExceededError( - "the limit of added mpsks clients is exceeded", limit=10, actual=len(owner.mpsks) + "the limit of added mpsks clients is exceeded", limit=30, actual=len(owner.mpsks) ) client = MPSKClient(name=name, owner_id=owner.id, mac=mac) diff --git a/tests/model/test_mpsk.py b/tests/model/test_mpsk.py index c336b02f7..3d361439d 100644 --- a/tests/model/test_mpsk.py +++ b/tests/model/test_mpsk.py @@ -71,27 +71,27 @@ def test_names(self, session, user, name): assert mpsk_client.name == name def test_exceeds_max_api(self, session, user): - mac = "00:00:00:00:00:0" - for i in range(10): - mac_client = mac + hex(i)[2:] - c = mpsk_client_create(user, "Hallo", mac_client, user, api=True) - user.mpsks.append(c) - session.flush() - assert len(user.mpsks) == i + 1 + mac = "00:00:00:00:00:" + for j in range(1, 4): + for i in range(10): + mac_client = mac + hex(j)[2:] + hex(i)[2:] + c = mpsk_client_create(user, "Hallo", mac_client, user, api=True) + user.mpsks.append(c) + session.flush() - for i in range(10, 15): - mac_client = mac + hex(i)[2:] + for i in range(15): + mac_client = mac + "0" + hex(i)[2:] with pytest.raises(AmountExceededError): - c = mpsk_client_create(user, "Hallo", mac_client, user, api=True) + mpsk_client_create(user, "Hallo", mac_client, user, api=True) def test_admin_exceeds(self, session, user): - mac = "00:00:00:00:00:0" - for i in range(15): - mac_client = mac + hex(i)[2:] - c = mpsk_client_create(user, "Hallo", mac_client, user, api=False) - user.mpsks.append(c) - session.flush() - assert len(user.mpsks) == i + 1 + mac = "00:00:00:00:00:" + for j in range(0, 4): + for i in range(15): + mac_client = mac + hex(j)[2:] + hex(i)[2:] + c = mpsk_client_create(user, "Hallo", mac_client, user) + user.mpsks.append(c) + session.flush() @pytest.fixture(scope="class") def user(self, class_session):