<commit_before>__author__ = 'ZSGX'

from model.contact import Contact
from random import randrange

def test_edit_first_contact_from_homepage(app):
    if app.contact.count() == 0:
        app.contact.create(Contact(firstname="test"))
    contact = Contact(firstname="first", middlename="Jasd", lastname="homepage", nickname="Madsti",
                               title="adasor", company="Hoasdadood", address="Ladngeles")
    old_contacts = app.contact.get_contact_list()
    contact.id = old_contacts[0].id
    app.contact.go_to_editpage_from_homepage(0)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[0] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)

def test_edit_first_contact_from_details(app):
    if app.contact.count() == 0:
       app.contact.create(Contact(firstname="test"))
    contact = Contact(firstname="first", middlename="Jasd", lastname="editing", nickname="Madsti",
                               title="adasor", company="Hoasdadood", address="Ladngeles")
    old_contacts = app.contact.get_contact_list()
    contact.id = old_contacts[0].id
    app.contact.go_to_editpage_from_details(0)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[0] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)

def test_edit_rand_contact_from_homepage(app):
    if app.contact.count() == 0:
        app.contact.create(Contact(firstname="test"))
    contact = Contact(firstname="rand", middlename="Jasd", lastname="homepage", nickname="Madsti",
                               title="adasor", company="Hoasdadood", address="Ladngeles")
    old_contacts = app.contact.get_contact_list()
    index = randrange(len(old_contacts))
    contact.id = old_contacts[index].id
    app.contact.go_to_editpage_from_homepage(index)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[index] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)

def test_edit_rand_contact_from_details(app):
    if app.contact.count() == 0:
       app.contact.create(Contact(firstname="test"))
    contact = Contact(firstname="rand", middlename="Jasd", lastname="editing", nickname="Madsti",
                               title="adasor", company="Hoasdadood", address="Ladngeles")
    old_contacts = app.contact.get_contact_list()
    index = randrange(len(old_contacts))
    contact.id = old_contacts[index].id
    app.contact.go_to_editpage_from_details(index)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[index] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)<commit_msg>param_edit_contact<commit_after>__author__ = 'ZSGX'

from model.contact import Contact
from random import randrange
import random
import string
import pytest

def random_string(prefix, maxlen):
    symbols = string.ascii_letters + string.digits + " "*10
    return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))])

testdata = [Contact(firstname="Michael", middlename="J.", lastname="Fox", nickname="Marti",
                    title="Actor", company="Hollywood", address="Los Angeles", homephone="911",
                    mobilephone="9911", workphone="999111", fax="919191", email2="<EMAIL>",
                    email3="<EMAIL>", homepage="fox.ff", address2="adr2", phone2="02",
                    notes="Back to the Future", bday=9, bmonth=6, byear=1961, aday=26, amonth=10,
                    ayear=1985, path="C:\\img.jpg")] + [
    Contact(firstname=random_string("", 10), middlename=random_string("", 10), lastname=random_string("", 10),
            nickname=random_string("", 10), title=random_string("", 10), company=random_string("", 10),
            address=random_string("", 10), homephone=random_string("", 10), mobilephone=random_string("", 10),
            workphone=random_string("", 10), fax=random_string("", 10), email2=random_string("", 10),
            email3=random_string("", 10), homepage=random_string("", 10), address2=random_string("", 10),
            phone2=random_string("", 10), notes=random_string("", 100), bday=9, bmonth=6, byear=1961, aday=26,
            amonth=10, ayear=1985, path="C:\\img.jpg")
    for i in range(2)]


def test_edit_first_contact_from_homepage(app):
    if app.contact.count() == 0:
        app.contact.create(Contact(firstname="test"))
    contact = Contact(firstname="first", middlename="Jasd", lastname="homepage", nickname="Madsti",
                               title="adasor", company="Hoasdadood", address="Ladngeles")
    old_contacts = app.contact.get_contact_list()
    contact.id = old_contacts[0].id
    app.contact.go_to_editpage_from_homepage(0)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[0] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)

def test_edit_first_contact_from_details(app):
    if app.contact.count() == 0:
       app.contact.create(Contact(firstname="test"))
    contact = Contact(firstname="first", middlename="Jasd", lastname="editing", nickname="Madsti",
                               title="adasor", company="Hoasdadood", address="Ladngeles")
    old_contacts = app.contact.get_contact_list()
    contact.id = old_contacts[0].id
    app.contact.go_to_editpage_from_details(0)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[0] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)

@pytest.mark.parametrize("contact", testdata, ids=[str(x) for x in testdata])
def test_edit_rand_contact_from_homepage(app, contact):
    if app.contact.count() == 0:
        app.contact.create(Contact(firstname="test"))
    old_contacts = app.contact.get_contact_list()
    index = randrange(len(old_contacts))
    contact.id = old_contacts[index].id
    app.contact.go_to_editpage_from_homepage(index)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[index] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)

@pytest.mark.parametrize("contact", testdata, ids=[str(x) for x in testdata])
def test_edit_rand_contact_from_details(app, contact):
    if app.contact.count() == 0:
       app.contact.create(Contact(firstname="test"))
    old_contacts = app.contact.get_contact_list()
    index = randrange(len(old_contacts))
    contact.id = old_contacts[index].id
    app.contact.go_to_editpage_from_details(index)
    app.contact.edit_contact(contact)
    assert len(old_contacts) == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts[index] = contact
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
{'fraction_non_alphanumeric': 0.1371587596077392, 'fraction_numerical': 0.015372382719321495, 'mean_word_length': 4.425593098490295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1975095', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2482, 'n_words': 377}