def test_remove_role_permission_file(change_to_test_directory):
    Permissions.PERMISSION_PATH = 'test_permissions_01.json'
    perms = Permissions(".")
    perms.add_role_permission("managerUser", "engineer", "roles_write",
                              "potato.obj")
    assert not perms.remove_role_permission("engineerUser", "engineer",
                                            "roles_write", "potato.obj")
    assert perms.remove_role_permission("managerUser", "engineer",
                                        "roles_write", "potato.obj")
    assert not perms.can_write("engineerUser", "potato.obj")
def test_add_role_permission(change_to_test_directory):
    Permissions.PERMISSION_PATH = 'test_permissions_01.json'
    perms = Permissions(".")
    assert perms.add_role_permission("managerUser", "engineer", "roles_write")
    assert perms.can_write("engineerUser", "misc.txt")
    assert not perms.add_role_permission("engineerUser", "engineer",
                                         "roles_write")
    assert not perms.add_role_permission("managerUser", "fakeRole",
                                         "roles_write")
    with pytest.raises(KeyError):
        perms.add_role_permission("managerUser", "manager", "fakePermission")
def test_delete_role(change_to_test_directory):
    Permissions.PERMISSION_PATH = 'test_permissions_01.json'
    perms = Permissions(".")
    assert perms.delete_role("managerUser", "engineer")
    assert "engineer" not in perms.get_roles("engineerUser")
    assert not perms.delete_role("managerUser", "fakeRole")
    assert not perms.delete_role("engineerUser", "manager")
    assert not perms.delete_role("managerUser", "default")
    perms.create_role("managerUser", "newRole")
    perms.add_role_permission("managerUser", "newRole", "roles_write")
    assert perms.delete_role("managerUser", "newRole")
    assert "newRole" not in perms["general"]["roles_write"]