<gh_stars>0
from model.contact import Contact
import random
import pytest


def test_mod_contact(app, db, check_ui):
    with pytest.allure.step('Given a contact list'):
        if len(db.get_contact_list()) == 0:
            app.contact.client_create(
                Contact(firstname="Petrov", lastname="Petrovich", home="+7(333)9983333", mobile="+7(912)8838833",
                        work="+7(938)8848844", phone2="dfdf",
                        email="<EMAIL>", email2="<EMAIL>", email3="<EMAIL>"))
        old_contacts = db.get_contact_list()
    with pytest.allure.step('Mod contact from contact list'):
        contact = Contact(firstname="Иванов", lastname="Иванович", home="+7(333)9983000", mobile="+7(912)8838000",
                          work="+7(938)8848000", phone2="222", address="hghgg",
                          email="<EMAIL>", email2="<EMAIL>", email3="<EMAIL>")
        index = random.randrange(len(old_contacts))
        contact.id = old_contacts[index].id
        id = contact.id
        app.contact.mod_contact_by_id(contact, id)
    with pytest.allure.step('Compare new_contacts and old_contacts after modify contact'):
        new_contacts = db.get_contact_list()
        assert len(old_contacts) == len(new_contacts)
        old_contacts[index] = contact
        assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
        if check_ui:
            assert sorted(new_contacts, key=Contact.id_or_max) == sorted(app.contact.get_contact_list(),
                                                                         key=Contact.id_or_max)

from model.contact import Contact
import random
import pytest


def test_mod_contact(app, db, check_ui):
    with pytest.allure.step('Given a contact list'):
        if len(db.get_contact_list()) == 0:
            app.contact.client_create(
                Contact(firstname="Petrov", lastname="Petrovich", home="+7(333)9983333", mobile="+7(912)8838833",
                        work="+7(938)8848844", phone2="dfdf",
                        email="<EMAIL>", email2="<EMAIL>", email3="<EMAIL>"))
        old_contacts = db.get_contact_list()
    with pytest.allure.step('Mod contact from contact list'):
        contact = Contact(firstname="Иванов", lastname="Иванович", home="+7(333)9983000", mobile="+7(912)8838000",
                          work="+7(938)8848000", phone2="222", address="hghgg",
                          email="<EMAIL>", email2="<EMAIL>", email3="<EMAIL>")
        index = random.randrange(len(old_contacts))
        contact.id = old_contacts[index].id
        id = contact.id
        app.contact.mod_contact_by_id(contact, id)
    with pytest.allure.step('Compare new_contacts and old_contacts after modify contact'):
        new_contacts = db.get_contact_list()
        assert len(old_contacts) == len(new_contacts)
        old_contacts[index] = contact
        assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
        if check_ui:
            assert sorted(new_contacts, key=Contact.id_or_max) == sorted(app.contact.get_contact_list(),
                                                                         key=Contact.id_or_max)