def test_init_without_known_permissions(self): with pytest.raises(ValueError): role.PermissionSet([{"name": "api", "permissions": ["1"]}]) role.PermissionSet.add_permission("api", "2") pset = role.PermissionSet([{"name": "api", "permissions": ["1", "2"]}]) assert pset["api"] == {"2"}
def test_make_api_structure(self): role.PermissionSet.add_permission("api", "1") role.PermissionSet.add_permission("api", "2") pset = role.PermissionSet([{"name": "api", "permissions": ["1", "2"]}]) assert pset.make_api_structure() == [ {"name": "api", "permissions": ["1", "2"]} ]
def test_access_ok(sudo_client_v1): known_permissions = [{ "name": k, "permissions": sorted(v) } for k, v in role.PermissionSet.KNOWN_PERMISSIONS.items()] pset = role.PermissionSet(known_permissions) response = sudo_client_v1.get("/v1/permission") assert response.status_code == 200 assert isinstance(response.json["items"], list) assert sorted(pset.make_api_structure(), key=lambda el: el["name"]) \ == sorted(response.json["items"], key=lambda el: el["name"])
def test_unknown_permission_class(self): role.PermissionSet.add_permission("api", "1") pset = role.PermissionSet([{"name": "api", "permissions": ["1"]}]) with pytest.raises(ValueError): pset["a"] = ["1"]
def test_init_with_known_permissions(self): role.PermissionSet.add_permission("api", "2") pset = role.PermissionSet([{"name": "api", "permissions": ["2"]}]) assert pset["api"] == {"2"}