import time
from random import randrange

from model.group import Group


def test_edit_group(app, db):
    app.group.open_group_page()
    if db.get_group_list() == 0:
        app.group.create(Group(name="test"))
    old_groups = db.get_group_list()
    index = randrange(len(old_groups))
    group = Group(name="123456766")
    group.id = old_groups[index].id
    app.group.edit_group_by_index(index, group)  # header="123456789", footer="123456789"))
    new_groups = db.get_group_list()
    assert len(old_groups) == len(new_groups)
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
