def test_modify_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: test_contact = Contact() test_contact.dummy() app.contact.create(test_contact) old_contacts = db.get_contact_list() cont = random.choice(old_contacts) test_contact_new = Contact(lastname="random",anniversary_month="random") test_contact_new.id = cont.id app.contact.modify_by_id(cont.id, test_contact_new) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[old_contacts.index(cont)] = test_contact_new assert old_contacts == new_contacts if check_ui: assert sorted(map(clean, new_contacts), key = Contact.id_or_max) == \ sorted(app.contact.get_contacts_list(), key = Contact.id_or_max)
def test_modify_contact_firstname_by_index(app): if app.contact.count() == 0: app.contact.add(Contact(firstname='Susan', lastname='Ivanova')) old_contact_list = app.contact.get_contact_list() index = randrange(len(old_contact_list)) new_firstname = 'Petro' contact = Contact(firstname=new_firstname) contact.id = new_firstname.rjust(20, '_') + old_contact_list[index].id[20:] app.contact.modify_contact_by_index(contact, index) new_contact_list = app.contact.get_contact_list() assert len(old_contact_list) == len(new_contact_list) old_contact_list[index] = contact assert sorted(old_contact_list) == sorted(new_contact_list) #def test_modify_first_contact_lastname(app): # if app.contact.count() == 0: # app.contact.add(Contact(firstname='Susan', lastname='Ivanova')) # old_contact_list = app.contact.get_contact_list() # app.contact.modify_first_contact(Contact(lastname='Pupkin2')) # new_contact_list = app.contact.get_contact_list() # assert len(old_contact_list) == len(new_contact_list)
def test_modify_contact_initials(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create( Contact( firstname="first", lastname="last", nickname="nick", company="company", homePhone="+22222222", email="mail@updated", ) ) old_contacts = db.get_contact_list() contact = Contact(firstname="updated firstname", lastname="updated lastname") random_contact = random.choice(old_contacts) contact_index = old_contacts.index(random_contact) contact.id = random_contact.id app.contact.modify_contact_by_id(contact, random_contact.id) new_contacts = db.get_contact_list() old_contacts[contact_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.group.get_contact_list(), key=Contact.id_or_max )
def test_modify_contact(app): if app.contact.count() == 0: app.contact.create(Contact(firstname="for modifdy")) old_contacts = app.contact.get_contacts_list() contact=Contact(firstname="1+m", middlename="2+m", lastname=("modify_lastname_"), nickname="4+m", title="6", company="7", address="8", home="9", mobile="10", work="11", fax="12", email2="14", email3="15", homepage="16", address2="19", phone2="20"#, # notes="21+m" ) index=randrange(len(old_contacts)) contact .id = old_contacts[index].id #[TEST] app.contact.modify_contact_by_index(contact,index) assert len(old_contacts) == app.contact.count() # хеш функция - считает количество элементов new_contacts = app.contact.get_contacts_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_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contact(firstname="test")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) contact_new = Contact( firstname="Petr", middlename="Petrovich", lastname="Petrov", nickname="PETRO", title="Mr", company="SUPERCOMPANY_2", address="Moscow, Old Arbat, 10", tel_home="595555555", tel_mobile="89009009091", tel_work="495123555", tel_fax="+799999999", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**", homepage="www.petrusha.com", address2="none_2", phone2="none_2", notes="too many funny comments", ) contact_new.id = contact.id app.contact.edit_contact_by_id(contact.id, contact_new) new_contacts = db.get_contact_list() assert len(old_contacts) == app.contact.count() # 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 )
def convert(contact): converted = Contact(id=str(contact.id), firstname=contact.firstname.strip(), lastname=contact.lastname.strip(), address=contact.address.strip(), homephone=contact.homephone.strip(), mobilephone=contact.mobilephone.strip(), workphone=contact.workphone.strip(), email=contact.email.strip(), email2=contact.email2.strip(), email3=contact.email3.strip()) converted.phones = self.merge_phones(converted) converted.emails = self.merge_emails(converted) return converted
def test_modify_contact_name(app): old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(firstname="Test") contact.id = old_contacts[index].id if app.contact.count() == 0: app.contact.create(Contact(firstname="New")) app.contact.modify_contact_by_index(index, contact) new_contacts = app.contact.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[index] = contact
def test_modify_firstname_contact(app, db): if len(db.get_contact_list()) == 0: app.contact.create(Contact(firstname = "test")) old_contacts = db.get_contact_list() random_index = random.choice(old_contacts) contact = Contact(firstname="Hello") contact.id = random_index.id app.contact.modify_contact_by_id(contact) new_contacts = app.contact.get_contact_list() assert len(old_contacts) == len(new_contacts) assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def test_edit_contact_firstname(app): if app.contact.count() == 0: app.contact.add_new(Contact(firstname="test")) old_contacts = app.contact.get_contact_list() index=randrange(len(old_contacts)) contact = Contact(firstname="new", lastname="contact") contact.id = old_contacts[index].id app.contact.edit_contact_by_index(index,contact) new_contacts = app.contact.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)
def test_modify_contact(app): if app.contact.count() == 0: app.contact.create(Contact(firstname="test")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(firstname="Mila") contact.id = old_contacts[index].id app.contact.modify_contact_by_index(index,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_modify_firstname_contact(app): if app.contact.count() == 0: app.contact.create(Contact(firstname="test")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(firstname="New", middlename="Tip", lastname="Tipy", company="ladCompany", address="Ca, adventure", homephone="+7098", mobilephone="+75325623895", email="*****@*****.**") contact.id = old_contacts[index].id app.contact.modify_contact_by_index(index, contact) new_contacts = app.contact.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)
def test_mod_some_contact(app): if app.contact.count() == 0: app.contact.create(Contact(name="test")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(name="1", middle="1", home="1", mobile="1", phone="1") contact.id = old_contacts[index].id app.contact.modify_contact_by_index(contact, index) 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_first_contact(app, db): if len(db.get_contact_list()) == 0: app.contact.create() old_contacts = db.get_contact_list() target_contact = random.choice(old_contacts) contact = Contact(firstname="Test", lastname="Last") contact.id = target_contact.id app.contact.edit_by_id(target_contact.id, contact) assert len(old_contacts) == app.contact.count() new_contacts = db.get_contact_list() old_contacts = [contact if con.id == contact.id else con for con in old_contacts] assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def test_modify_contact_name(app): old_contacts = app.contact.get_contact_list() contact = Contact(name="acdc") index = randrange(len(old_contacts)) contact.id = old_contacts[index].id if app.contact.count()== 0: app.contact.create(Contact(name="test contact")) app.contact.modify_contact_by_index(index, contact) new_contacts = app.contact.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)
def test_modify_contact_first_name(app): contact = Contact(firstname = "First Name Update") if app.contact.count() == 0: app.contact.create(Contact(firstname = "To be modified", middlename = "To be modified", lastname = "To be modified", nick = "To be modified")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) app.contact.edit_contact_by_index(contact, index) assert len(old_contacts) == app.contact.count() new_contacts = app.contact.get_contact_list() contact.id = old_contacts[index].id contact.lastname = old_contacts[index].lastname old_contacts[index] = contact assert sorted(old_contacts, key = Contact.id_or_max) == sorted(new_contacts, key = Contact.id_or_max)
def test_modify_contact_firstname(app, db, check_ui): if db.get_contact_list() == 0: app.contact.create(Contact(firstname="", middlename="")) old_contacts = db.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(firstname="Dmitriyppppp") contact.id = old_contacts[index].id app.contact.modify_contact_by_index(index, contact) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[index] = contact if check_ui: assert sorted(new_contacts, key=Contact.id_or_max) == sorted(app.contact.get_contact_list(), key=Contact.id_or_max)
def test_edit_contact(app): if app.contact.count() == 0: app.contact.create(Contact(name="test")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact=Contact(name="Loli", surname="Pop", job="Semant", mainaddress="22, Fearless.ave, Lynn, MA, 01902", phone="857-251-5655u", year="1885", secondaddress="85, Shirley ave, Revere, MA, 02151") contact.id=old_contacts[index].id app.contact.edit_contact_by_index(index,contact) new_contacts = app.contact.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)
def test_edit_some_contact(app, db, check_ui): if app.contact.count() == 0: app.contact.create(Contact(firstname = "test")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) contact_new = Contact(firstname ="Maria") contact_new.id = contact.id contact_new.lastname = contact.lastname app.contact.edit_contact_by_id (contact.id, contact_new) new_contacts = db.get_contact_list() old_contacts.remove(contact) old_contacts.append(contact_new) if check_ui: assert sorted(old_contacts, key = Contact.id_con_max) == sorted(new_contacts, key = Contact.id_con_max)
def test_modify_contact_firstname(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contact(firstname="test")) old_contacts = db.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(firstname="John") contact.id = old_contacts[index].id app.contact.modify_contact_by_id(contact.id, contact, index) 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: list_contact_after_mod = app.contact.get_contact_list() assert sorted(list_contact_after_mod, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def test_modify_some_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contact(firstname="testcontact")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) modified_contact = Contact(firstname="New name", lastname="Newlastname") modified_contact.id = contact.id app.contact.modify_contact_by_id(modified_contact.id, modified_contact) new_contacts = db.get_contact_list() old_contacts.remove(contact) old_contacts.append(modified_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)
def test_edit_some_contact_from_edit_form(app, db, check_ui): if len(db.get_contact_list()) == 0: with pytest.allure.step('If there is no contact I will add a new one'): app.contact.add_contact(Contact(last_name="test" + app.libs.substring), delete_photo=False, dataset=(("1", "3"), ("2", "2"), ("3", "12"), ("4", "3"), ("5", "1"))) contact = Contact(first_name="First_Name", middle_name="Middle_Name", last_name="Last_Name" + app.libs.substring, nickname="Nickname", pic=str(os.path.dirname(__file__)) + "\\photo.gif", title="Title", company_name="Company Name", company_address="Company Address", home_phone="(999)111-11-11", mobile_phone="(999)111-11-22", work_phone="(999)111-11-33", fax="(999)111-11-44", email_1="*****@*****.**", email_2="*****@*****.**", email_3="*****@*****.**", homepage="http://www.homepage.net", birth_year="1970", anniv_year="1990", home_addr="Home Address", notes="Some Notes", extra_phone="(999)111-11-55") with pytest.allure.step('Given a contact list before edit'): old_contacts = db.get_contact_list() with pytest.allure.step('Given a random contact from the list for edit'): modified_contact = random.choice(old_contacts) with pytest.allure.step('I modified the contact'): app.contact.modify_some_contact_by_id(modified_contact.id, contact, delete_photo=True, dataset=(("1", "3"), ("2", "3"), ("3", "14"), ("4", "3")), edit_detail="edit_form") with pytest.allure.step('Given a contact list after edit'): new_contacts = db.get_contact_list() with pytest.allure.step('Then the length of the new contact list is equal to the length of the old list'): assert len(old_contacts) == len(new_contacts) with pytest.allure.step('The modified contact was changed in the old list'): contact.id = modified_contact.id old_contacts.remove(modified_contact) old_contacts.insert(int(modified_contact.id), contact) with pytest.allure.step('Then the new contact list is equal to the old list with the edit contact'): assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max) if check_ui: assert sorted(map(app.libs.clean_contact, new_contacts), key=Contact.id_or_max) ==\ sorted(app.contact.get_contact_list(), key=Contact.id_or_max)
def test_modify_random_contact(app, db): if app.contact.count() == 0: app.contact.create(Contact(first_name="First", last_name="Last", address="Address", home_phone="12345678", work_phone="(312)98756-32", secondary_phone="312-987-78-23", email="*****@*****.**", email2="*****@*****.**")) old_contacts_list = db.get_contacts_list() modified_contact = Contact(first_name="New_name", last_name="New_Last_name", address="New_Address", home_phone="11111111", mobile_phone="111111111", email="*****@*****.**") contact = random.choice(old_contacts_list) modified_contact.contact_id = contact.contact_id app.contact.modify_contact_by_id(modified_contact.contact_id, modified_contact) new_contacts_list = db.get_contacts_list() old_contacts_list.remove(contact) old_contacts_list.append(modified_contact) assert sorted(old_contacts_list, key=Contact.id_or_max) == sorted(new_contacts_list, key=Contact.id_or_max)
def test_modify_contact_first_last_name(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contact(first="Last contact first name")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) app.contact.select_contact_by_id(contact.id) contact_new = Contact(first = "New contact first name", last = "New contact last name") contact_new.id = contact.id app.contact.modify_contact_by_id(contact_new.id, contact_new) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts.remove(contact) old_contacts.append(contact_new) 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)
def test_full_modify_some_contact(app, db, check_ui): if len(db.get_cont_list()) == 0: app.contact.create(Contact(firstname="hghjdsfni4389")) old_contacts = db.get_cont_list() index = random.choice(old_contacts) contact = Contact(firstname="ertyuiklkmnbvc", middlename="dfg", lastname="sdfghjk", nick="rtlkjhkl", tytle="rty567,mnb", company="wertyuiop", address="xcvbntrewertyujnbvccfghj", home_tel="123456789", mobile_tel="987654321", work_tel="345643", fax="098789", birth_day="2", birth_month="October", birth_year="1985", second_addr="ertyukjbvcjkmnbbjkl,mnhghjkl", second_phone="45676789890", notes="erctvybuniercvybyygvbhjhdtrch") app.contact.modify_contact_by_id(int(index.id), contact) assert len(old_contacts) == app.contact.contactcount() new_contacts = db.get_cont_list() 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.group.get_group_list(), key=Contact.id_or_max())
def test_contact_by_index(app): if app.contact.count()==0: app.contact.create(Contact(firstname="for edit username", lastname="for edit lastname",)) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(firstname="__edit_firstname__", lastname="__edit_lastname__", home="555", mobile="5555", work="55555", phone2="555555") contact.id = old_contacts[index].id app.contact.edit_contact_by_index(index, contact) new_contacts = app.contact.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)
def test_edit_random_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contact(first_name="First", middle_name="Middle", last_name="Last")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) new_contact = Contact(first_name="FirstName", middle_name="MiddleName", last_name="LastName", nickname="NickName", company="Test", mobile_phone="+79805894179", email="*****@*****.**", year_of_birth="2000") new_contact.contact_id = contact.contact_id app.contact.edit_contact_by_id(new_contact, contact.contact_id) assert len(old_contacts) == app.contact.count() new_contacts = db.get_contact_list() old_contacts.remove(contact) old_contacts.append(new_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)
def test_modify_contact(app, db, check_ui): if app.contact.count() == 0: app.contact.create(Contact(firstname="test")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) newContact = Contact("aaaaa", "bbb", "ccc") newContact.id = contact.id app.contact.modify_by_id(contact.id, newContact) assert len(old_contacts) == app.contact.count() new_contacts = db.get_contact_list() for i in range(len(old_contacts)): if old_contacts[i].id == newContact.id: old_contacts[i] = newContact 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)
def test_modify_some_contact(app, db, check_ui): if app.contact.count() == 0: app.contact.create(Contact(middlename="test")) old_contacts = db.get_contact_list() contact = Contact(home="111", mobile= "222", work="333", phone2="444") index = randrange(len(old_contacts)) contact.id = old_contacts[index].id contact.firstname = old_contacts[index].firstname contact.lastname = old_contacts[index].lastname app.contact.modify_contact_by_index(index, contact) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[index] = contact def clean(contact): return Contact(id=contact.id, firstname=contact.firstname.strip()) new_contacts = map(clean, db.get_contact_list()) new_contacts_1 = map(clean, app.contact.get_contact_list()) if check_ui: assert sorted(new_contacts, key=Contact.id_or_max) == sorted(new_contacts_1, key=Contact.id_or_max)
def test_change_some_contact_names(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contact(name="contact", middle_name="middle_name", last_name="last_name", nickname="nickname", title="title", company="company", address="address", home_telephone="123456", mobile_telephone="234567", work_telephone="345678", email="*****@*****.**", year="2000", address2="address", phone2="12")) old_contacts = db.get_contact_list() old_contact = random.choice(old_contacts) id = old_contact.id contact = Contact(name="change_new_contact", middle_name="change_contact_middle_name", last_name="change_contact_last_name") contact.id = id app.contact.change_by_id(contact.id, contact) new_contacts = db.get_contact_list() old_contacts.insert(old_contacts.index(old_contact), contact) old_contacts.remove(old_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)
def test_modify_some_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contact(firstname="test")) old_contacts = db.get_contact_list() random_contact = random.choice(old_contacts) contact = Contact(firstname="update", middlename="update", lastname="update", nickname="update", title="update", company="update", address="update", homephone="321", mobilephone="321", workphone="321", fax="321", email="update") contact.id = random_contact.id app.contact.modify_contact_by_id(contact) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) i = 0 for x in old_contacts: if x.id == random_contact.id: old_contacts[i] = contact i += 1 assert old_contacts == new_contacts if check_ui: assert sorted(new_contacts, key=Contact.id_or_max) == sorted(app.contact.get_contact_list(), key=Contact.id_or_max)
def test_delete_first_contact(app): if app.contact.count() == 0: app.contact.add_new(Contact(firstname="test", lastname="test")) app.contact.delete_first_contact()
def convert(contact): return Contact(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname)
return "".join([ random.choice(string.ascii_lowercase) for i in range(random.randrange(min_len, max_len)) ]) def get_random_string_upper(len): return "".join([random.choice(string.ascii_uppercase) for i in range(len)]) def get_random_string_digits(min_len, max_len): result = "".join([ random.choice(string.digits) for i in range(random.randrange(min_len, max_len)) ]) return result.replace(' ', ' ') test_data = [Contact(first_name="", last_name="", address="", home_phone="", work_phone="", mobile_phone="", secondary_phone="", email="", email2="", email3="")] + \ [Contact(first_name=get_random_name(), last_name=get_random_name(), address=get_random_address(), home_phone=get_random_string_digits(10, 11), work_phone=get_random_string_digits(10, 11), mobile_phone=get_random_string_digits(10, 11), secondary_phone=get_random_string_digits(10, 11), email=get_random_email(), email2=get_random_email(), email3=get_random_email()) for i in range(n)] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', f) with open(file, 'w') as out: jsonpickle.set_encoder_options('json', indent=2) out.write(jsonpickle.encode(test_data))
return website testdata = [ Contact(firstname="", middlename="", lastname="", username="", title="", company="", address="", homephone="", mobilephone="", workphone="", fax="", email="", email2="", email3="", homepage="", birthday="", aday="", birthmonth="-", amonth="-", birthyear="", ayear="", address2="", phone2="", notes="") ] + [ Contact(firstname=random_string('first'), middlename=random_string('middle'), lastname=random_string('last'),
sys.exit(2) n = 5 f = "data/contacts.json" for o, a in opts: if o == "-n": n=int(a) elif o == "-f": f = a def random_string(prefix, maxlen): symbols = string.ascii_letters + string.digits return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))]) def random_phone_number(): n_groups = random.randint(3, 6) symbols = string.digits + "-" return ('-'.join([''.join(random.choices(symbols, k=random.randint(1, 3))) for _ in range(n_groups)])) testdata=[Contact(firstname="", lastname="", home_phone="", mobile_phone="", work_phone="", secondary_phone="")] + [Contact(firstname=random_string("FirstName", 10), lastname=random_string("LastName", 10), home_phone=random_phone_number(), mobile_phone=random_phone_number(), work_phone=random_phone_number(), secondary_phone=random_phone_number()) for i in range(n)] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f) with open(file, "w") as out: jsonpickle.set_encoder_options("json", indent=2) out.write(jsonpickle.encode(testdata))
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))]) def random_digits(maxlen): return "".join([random.choice(string.digits) for i in range(maxlen)]) testdata = [ Contact(id=None, first_name=random_string("FirstName", 5), last_name=random_string("LastName", 5), home_phone="+" + random_digits(7), mobile_phone="(" + random_digits(3) + ")" + random_digits(6), work_phone=random_digits(3) + " " + random_digits(3) + " " + random_digits(3), secondary_phone="", address=random_string("Address", 10), email=random_string("email1", 5) + "@mail.com", email2=random_string("email2", 5) + "@mail.com", email3=random_string("email3", 5) + "@mail.com") for i in range(n) ] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f) with open(file, "w") as out: jsonpickle.set_encoder_options("json", indent=2) out.write(jsonpickle.encode(testdata))
from model.contact import Contact import random import string constant = [ Contact(firstname="Анна", lastname="Иванова", address="ул.Смольная, д.18", homephone="(495)123-12-23", mobilephone="903-456-12-12", workphone="+7(495)120 18 20", secondaryphone="(495)1820", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**") # создаем объект контакт ] def random_string_firstname(maxlen): #генератор случайных строк для имени simbols = ["Елена", "Сергей", "Дмитрий", "Алексей", "Алла", "Мария"] return random.choice(simbols) def random_string_lastname(maxlen): #генератор случайных строк для фамилии simbols = "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЭЮЯ" + " " return "".join( [random.choice(simbols) for i in range(random.randrange(maxlen))]) def random_string_address(prefix, maxlen): #генератор случайных строк для адреса
def test_contact_add(app): app.contact.create( Contact("Contact_first_name", "Contact_Last_Name", "Contact_Nick_Name"))
import random def random_string(prefix, maxlen): symbols = string.ascii_letters + string.digits + " "*10 + string.punctuation return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))]) def random_number(maxlen): return "+" + "".join([random.choice(string.digits) for i in range(random.randrange(maxlen))]) def random_email(maxlen): symbols = string.ascii_letters + string.digits return "e" + "".join([random.choice(symbols) for i in range(random.randrange(maxlen / 2))]) + "@" + "".join([random.choice(symbols) for i in range(random.randrange(maxlen / 2))]) + ".com" testdata = [ Contact(firstname=name, lastname=lastname, address=random_string("", 20), homephone=random_number(10), mobilephone=random_number(10), workphone=random_number(10), secondaryphone=random_number(10), e_mail=random_email(8)) for name in ["", random_string("name", 7)] for lastname in [random_string("last", 10)]*3 ] @pytest.mark.parametrize("contact", testdata, ids=[repr(y) for y in testdata]) def test_add_contact(app, contact): old_contacts = app.user.get_contacts_list() app.user.create(contact) assert len(old_contacts) + 1 == app.user.count() new_contacts = app.user.get_contacts_list() old_contacts.append(contact) assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def mod_contact(name, lastname, home, email): return Contact(name=name, lastname=lastname, home=home, email=email)
def non_empty_contact_list(db, app): if len(db.get_contact_list()) == 0: app.contact.create(Contact(name="some name")) return app.contact.get_contact_list()
def test_add_contact(app): old_contacts = app.contact.get_contact_list() app.contact.create( Contact(fname="somename", mname="somemname", lname="somelname")) new_contacts = app.contact.get_contact_list() assert len(old_contacts) + 1 == len(new_contacts)
def non_empty_contact_list(app, orm): if len(orm.get_contact_list()) == 0: app.contact.create(Contact(firstname="some name")) return orm.get_contact_list()
def clean_contact(self, contact): return Contact(id=contact.id, firstname=contact.firstname.strip(), lastname=contact.lastname.strip())
def get_contact_from_view_page(self, index): wd = self.app.wd self.open_contact_to_view_by_index(index) text = wd.find_element_by_id("content").text mobile = re.search("M: (.*)", text).group(1) return Contact(mobile=mobile)
sys.exit(2) n = 5 f = "data/contacts.json" for o, a in opts: if o == "-n": n = int(a) elif o == "-f": f = a def random_string(prefix, maxlen): symbols = string.ascii_letters + string.digits + string.punctuation + " " * 10 return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) testdata = [Contact(firstname="", lastname="", email="", mobilephone="")] + [ Contact(firstname=random_string("Name", 10), lastname=random_string("Last name", 10), email=random_string("*****@*****.**", 10), mobilephone=random_string("+79110000000", 10)) for i in range(n) ] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f) with open(file, "w") as out: jsonpickle.set_encoder_options("json", indent=2) out.write(jsonpickle.encode(testdata))
def test_del_first_contact(app): if app.contact.count() == "0": app.contact.create(Contact(firstname="Pre_created_contact")) app.contact.delete_first_contact()
from model.contact import Contact testdata = [ Contact(first_name="first_name1", middle_name="middle_name1", last_name="last_name1", nickname="nickname1", title="title1", company="company1", address="address1", home_number="home_number1", mobile_number="mobile_number1", work_number="work_number1", fax="fax1", email="email1", email2="email2_1", email3="email3_1", homepage="homepage1", byear="byear1", ayear="ayear1", address_2="address_2_1", phone2="phone2_1", notes="notes1"), Contact(first_name="first_name2", middle_name="middle_name2", last_name="last_name2", nickname="nickname2", title="title", company="company2", address="address2", home_number="home_number2",
from model.contact import Contact testdata = [ Contact(firstname="firstname1", middlename="middlename1", lastname="lastname1", nickname="nickname1", title="title1", company="company1", address="address1", homephone="homephone1", mobilephone="mobilephone1", workphone="workphone1", fax="fax1", email="email11", email2="email22", email3="email33", homepage="homepage1", address2="address21", phone2="phone21", notes="notes1"), Contact(firstname="firstname2", middlename="middlename2", lastname="lastname2", nickname="nickname2", title="title2", company="company2", address="address2", homephone="homephone2", mobilephone="mobilephone2", workphone="workphone2",
# -*- coding: utf-8 -*- from model.contact import Contact import pytest import random import string def random_string(prefix, maxlen): # string will be chosen from letters, digits and 10 spaces -- ' '*10 symbols = string.ascii_letters + \ string.digits + string.punctuation + ' '*5 return prefix + ''.join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) testdata = [Contact(firstname='', middlename='', lastname='')] + [ # will generate random string that starts with word 'Name' or 'Header etc and + some more random symbols Contact(firstname=random_string('First name ', (10)), middlename=random_string('Middlename ', (5)), lastname=random_string('Lastname', (7))) for i in range(5) ] @pytest.mark.parametrize('contact', testdata, ids=[repr(x) for x in testdata]) def test_add_contact(app, contact): old_contacts = app.contact.get_contact_list() app.contact.open_add_new_contact_page() app.contact.fill_in_contact_form(contact) assert len(old_contacts) + 1 == app.contact.count() new_contacts = app.contact.get_contact_list() old_contacts.append(contact)
simbols = string.ascii_letters + string.digits # simbols = string.ascii_letters + string.digits + string.punctuation + " "*10 return prefix + "".join( [random.choice(simbols) for i in range(random.randrange(maxlen))]) testdata = [ Contact(firstname="", middlename="", lastname="", nickname="", title="", company="", address="", home="", mobile="", work="", fax="", email="", email2="", email3="", homepage="", address2="", phone2="", notes="") ] + [ Contact(firstname=random_string("firstname", 10), middlename=random_string("middlename", 10), lastname=random_string("lastname", 10), nickname=random_string("nickname", 10), title=random_string("title", 10), company=random_string("company", 10),
def clean(contact): return Contact(id=contact.id, first_name=contact.first_name.strip(), last_name=contact.last_name.strip())
from model.contact import Contact # см урок 6_3_ddt.mp4 constant = [ Contact(firstname="firstname111", middlename="middlename111", lastname="lastname111"), Contact(firstname="firstname222", middlename="middlename222", lastname="lastname222") ] # убрали этот код в уроке 6_5_dynamic_test_generation.mp4 # def random_string(prefix, maxlen): # symbols = string.ascii_letters + string.digits + " " # из за пробелов иногда тест падает! # return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))]) # # # testdata = [Contact(firstname="", middlename="", lastname="")] + [ # Contact(firstname=random_string("firstname", 10), middlename=random_string("middlename", 20), lastname=random_string("lastname", 20)) # for i in range(2) # ]
def non_empty_contact_list(app, db): if len(db.get_contact_list()) == 0: app.contact.add(Contact(firstname="Aneczka", lastname="Szmyd")) return db.get_contact_list()
def convert(contact): return Contact(id=str(contact.id), fname=contact.firstname.strip(), lname=contact.lastname.strip())
def new_contact(firstname, lastname, address, home, mobile): return Contact(firstname=firstname, lastname=lastname, address=address, home=home, mobile=mobile)
def new_contact(self, firstname, lastname): return Contact(firstname=firstname, lastname=lastname)
def test_test_modify_some_contact(app, db, check_ui): if app.contact.count() == 0: app.contact.create( Contact(firstname="Петр", middlename="Петрович", lastname="Петров", nickname="петрич", title="ПЕТООР", company="Петровкакомпания", address="ул.Петров", home="84956521474", mobile="+75641257896", work="89541236545", fax="78444111", email1="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**", homepage="www.petrpetr.ru", bday="1", bmonth="January", byear="1990", aday="2", amonth="February", ayear="2015", address2="Адрес 2", phone2="2", notes="что то")) old_contact = db.get_contact_list() index = randrange(len(old_contact)) contact = Contact(firstname="Иван", middlename="Иванов", lastname="Иванович", nickname="иванич", title="ИВААН", company="Петровкакомпания", address="ул.Петров", home="84956521474", mobile="+75641257896", work="89541236545", fax="78444111", email1="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**", homepage="www.petrpetr.ru", bday="1", bmonth="January", byear="1991", aday="3", amonth="February", ayear="2014", address2="Адрес 2", phone2="1", notes="это") #contact.id = old_contact[index].id app.contact.modify_contact_by_id(contact.id) new_contact = db.get_contact_list() assert len(old_contact) == len(new_contact) old_contact.remove(contact) assert old_contact == new_contact if check_ui: assert sorted(new_contact, key=Contact.id_or_max) == sorted( app.group.get_contact_list(), key=Contact.id_or_max)
from model.contact import Contact testdata = [ Contact(firstname="fname1", lastname="lname1", address="adress1", homephone="+7111111111", mobilephone="+7111111111", workphone="+7111111111", secondaryphone="+7111111111", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**"), Contact(firstname="fname2", lastname="lname2", address="adress2", homephone="+7222222222", mobilephone="+7222222222", workphone="+7222222222", secondaryphone="+7222222222", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**") ]
# -*- coding: utf-8 -*- __autor__ = 'Dmitrii Dubrovskii' from model.contact import Contact testdata = [ Contact(fname="fname1", lname="lname1", nick="nick1", title="title1", company="company1", address="address1", mobile="mobile1", home="home1", work="work1", email="email1", bday='bday1', bmonth='bmonth1', byear='byear1', address2="address21", phone2="phone21", notes="notes1"), Contact(fname="fname2", lname="lname2", nick="nick2", title="title2", company="company2", address="address2", mobile="mobile2", home="home2", work="work2", email="email2",