import random
from model.project import Project


def test_delete_project(app):
    app.session.login("administrator", "root")
    if len(app.project.get_projects_lst()) == 0:
        app.project.create_project(Project(name="name-" + str(random.randrange(100)),
                                           status=random.choice(["development", "release"]),
                                           viewstatus=random.choice(["private", "public"]),
                                           description="description-" + str(random.randrange(100))))
    # old_projects_lst = app.project.get_projects_lst()
    old_projects_lst = app.soap.get_projects_lst("administrator", "root")
    project = random.choice(old_projects_lst)
    app.project.delete_project(project)
    # new_projects_list = app.project.get_projects_lst()
    new_projects_list = app.soap.get_projects_lst("administrator", "root")
    old_projects_lst.remove(project)
    assert old_projects_lst == new_projects_list
    """
    old_projects_lst.remove(project)
    assert sorted(old_projects_lst, key=Project.id_or_max) == sorted(new_projects_list, key=Project.id_or_max)
    """
