def test_edit_random_contact(app): if app.contact.count() < 1: app.contact.add_contact(Contact()) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) new_contact = Contact(first_name="New F_Name Edit", last_name="New L_Name Edit") new_contact.id = old_contacts[index].id app.contact.edit_by_index(index, new_contact) assert len(old_contacts) == app.contact.count() new_contacts = app.contact.get_contact_list() old_contacts[index] = new_contact assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def preparation_several_contacts(self, quantity: int) -> []: contacts = [] for number in range(quantity): contact = Contact() contacts.append(contact) self.add_contact(contact) return contacts
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.open_contact_edit_by_index(index) id_contact = wd.find_element_by_name("id").get_attribute("value") first_name = wd.find_element_by_name("firstname").get_attribute( "value") last_name = wd.find_element_by_name("lastname").get_attribute("value") address = wd.find_element_by_name("address").get_attribute("value") phone_home = wd.find_element_by_name("home").get_attribute("value") phone_work = wd.find_element_by_name("work").get_attribute("value") phone_mobile = wd.find_element_by_name("mobile").get_attribute("value") phone_fax = wd.find_element_by_name("fax").get_attribute("value") phone_2 = wd.find_element_by_name("phone2").get_attribute("value") email_1 = wd.find_element_by_name("email").get_attribute("value") email_2 = wd.find_element_by_name("email2").get_attribute("value") email_3 = wd.find_element_by_name("email3").get_attribute("value") return Contact(id_contact=id_contact, first_name=first_name, last_name=last_name, address=address, phone_home=phone_home, phone_work=phone_work, phone_mobile=phone_mobile, phone_fax=phone_fax, phone_2=phone_2, email_one=email_1, email_two=email_2, email_three=email_3)
def test_add_user_with_group(app): group_name = app.group.preparation_group() old_contacts = app.contact.get_contact_list() contact = Contact(group=group_name) app.contact.add_contact(contact) assert len(old_contacts) + 1 == app.contact.count() new_contacts = app.contact.get_contact_list() old_contacts.append(contact) assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def get_contact_info_from_view_page(self, index): wd = self.app.wd self.open_contact_view_by_index(index) view_text = wd.find_element_by_id("content").text phone_home = re.search("H: (.*)", view_text).group(1) phone_work = re.search("W: (.*)", view_text).group(1) phone_mobile = re.search("M: (.*)", view_text).group(1) phone_2 = re.search("P: (.*)", view_text).group(1) return Contact(phone_home=phone_home, phone_work=phone_work, phone_mobile=phone_mobile, phone_2=phone_2)
def test_delete_random_contact(app): if app.contact.count() < 1: app.contact.add_contact(Contact()) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) app.contact.delete_by_index(index) assert len(old_contacts) - 1 == app.contact.count() new_contacts = app.contact.get_contact_list() old_contacts.pop(index) assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.menu_home() self.contact_cache = [] for row in wd.find_elements_by_css_selector("tr[name='entry']"): cells = row.find_elements_by_tag_name("td") id_contact = cells[0].find_element_by_tag_name( "input").get_attribute("value") last_name = cells[1].text first_name = cells[2].text address = cells[3].text all_emails = cells[4].text all_phones = cells[5].text all_phones_list = all_phones.splitlines() phone_home, phone_mobile, phone_work, phone_2 = None, None, None, None for index in range(0, len(all_phones_list)): if index == 0: phone_home = all_phones_list[0] if index == 1: phone_mobile = all_phones_list[1] if index == 2: phone_work = all_phones_list[2] if index == 3: phone_2 = all_phones_list[3] self.contact_cache.append( Contact(last_name=last_name, first_name=first_name, id_contact=id_contact, address=address, all_emails_from_home_page=all_emails, all_phones_from_home_page=all_phones, phone_home=phone_home, phone_work=phone_work, phone_mobile=phone_mobile, phone_2=phone_2, all_none=True)) return list(self.contact_cache)
def test_edit_by_last_first_name(app): current_contact = Contact() app.contact.add_contact(current_contact) old_contacts = app.contact.get_contact_list() new_contact = Contact(first_name="F_Name Edit", last_name="L_Name Edit") new_contact.id = Contact.found_by_name_in_list( first_name=current_contact.first_name, last_name=current_contact.last_name, list_contacts=old_contacts).id app.contact.search( f"{current_contact.last_name} {current_contact.first_name}") app.contact.edit_first(new_contact) assert len(old_contacts) == app.contact.count() new_contacts = app.contact.get_contact_list() old_contacts = Contact.update_list_by_id(new_contact, old_contacts) assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
number = 5 file = "data/contacts.json" for o, a in opts: if o == "-n": number = int(a) elif o == "-f": file = a def random_string(prefix, max_len): symbol = string.digits + string.ascii_letters + " " * 10 return prefix + "".join( [random.choice(symbol) for i in range(random.randrange(max_len))]) test_data = [Contact(first_name="", last_name="", middle_name="")] + [ Contact(first_name=random_string("first_name", 15), last_name=random_string("last_name", 15), middle_name=random_string("middle_name", 15)) for i in range(number) ] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", file) with open(file, "w") as file_json: # file_json.write(json.dumps(test_data, default=lambda x: x.__dict__, indent=2)) jsonpickle.set_encoder_options("json", indent=2) file_json.write(jsonpickle.encode(test_data))
# -*- coding: utf-8 -*- import random import string from model.dto_contact import Contact constant_data = [ Contact(first_name="first_name_1", last_name="last_name_1", middle_name="middle_name_1"), Contact(first_name="first_name_2", last_name="last_name_2", middle_name="middle_name_2"), ] def random_string(prefix, max_len): symbol = string.digits + string.ascii_letters + " " * 10 return prefix + "".join( [random.choice(symbol) for i in range(random.randrange(max_len))]) test_data = [Contact(first_name="", last_name="", middle_name="")] + [ Contact(first_name=random_string("first_name", 15), last_name=random_string("last_name", 15), middle_name=random_string("middle_name", 15)) for i in range(5) ]