def get_contact_list(self): list = [] cursor = self.connection.cursor() try: cursor.execute( "select id, firstname, middlename, lastname, nickname, company, address, home, work, mobile, " "email, email2, address2, notes from addressbook where deprecated = '0000-00-00 00:00:00'" ) for row in cursor: (id, firstname, middlename, lastname, nickname, company, address, home, work, mobile, email, email2, address2, notes) = row # if deprecated is '0000-00-00 00:00:00': list.append( ContactGroup(id=str(id), firstname=firstname, middlename=middlename, lastname=lastname, nickname=nickname, company=company, address=address, home=home, work=work, mobile=mobile, email=email, email2=email2, address2=address2, notes=notes)) finally: cursor.close() return list
def get_contact_from_view_page(self, index): wd = self.app.wd self.open_contact_view_by_index(index) text = wd.find_element_by_id("content").text homephone = re.search("H: (.*)", text).group(1) workphone = re.search("W: (.*)", text).group(1) mobilephone = re.search("M: (.*)", text).group(1) secondaryphone = re.search("P: (.*)", text).group(1) return ContactGroup(homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone)
def test_modify_some_contact(app): if app.contact.count() == 0: app.contact.add_new( ContactGroup(firstname="Ivan", lastname="Ivanov", nickname="goodman", company="TTY", address="Ekaterinburg", email="*****@*****.**", address2="Lenina str 5/7")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = ContactGroup(address="Ufa", address2="1905 str 5/7", middlename="Ivanovich", notes="modified") contact.id = old_contacts[index].id contact.lastname = old_contacts[index].lastname contact.firstname = old_contacts[index].firstname app.contact.modify_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=ContactGroup.id_or_max) == sorted( new_contacts, key=ContactGroup.id_or_max)
def test_modify_some_contact_db(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.add_new( ContactGroup(firstname="Ivan", lastname="Ivanov", nickname="goodman", company="TTY", address="Ekaterinburg", email="*****@*****.**", address2="Lenina str 5/7")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) contact_data = ContactGroup(address="Ufa", address2="1905 str 5/7", middlename="Ivanovich", notes="modified") contact_data.id = old_contacts[id].id contact_data.lastname = old_contacts[id].lastname contact_data.firstname = old_contacts[id].firstname app.contact.modify_by_id(id, contact) new_contacts = app.contact.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[index] = contact assert sorted(old_contacts, key=ContactGroup.id_or_max) == sorted( new_contacts, key=ContactGroup.id_or_max) if check_ui: assert sorted(new_contacts, key=ContactGroup.id_or_max) == sorted( app.contact.get_contact_list(), key=ContactGroup.id_or_max)
def get_contact_list(self): if self.contact_cash is None: wd = self.app.wd self.open_contacts_page() self.contact_cash = [] for element in wd.find_elements_by_xpath("//tbody/tr[@name='entry']"): firstname = element.find_element_by_xpath("td[3]").text lastname = element.find_element_by_xpath("td[2]").text id = element.find_element_by_name("selected[]").get_attribute("value") all_phones = element.find_element_by_xpath("td[6]").text all_emails = element.find_element_by_xpath("td[5]").text address = element.find_element_by_xpath("td[4]").text self.contact_cash.append(ContactGroup(firstname=firstname, lastname=lastname, id=id, address=address, all_emails_from_home_page=all_emails, all_phones_from_home_page=all_phones)) return list(self.contact_cash)
def test_add_defined_contact(app): old_contacts = app.contact.get_contact_list() contact = ContactGroup(firstname="test6", lastname="Ivanov", nickname="goodman", company="TTY", address="Ekaterinburg", email="*****@*****.**", address2="Lenina str 5/7") app.contact.add_new(contact) new_contacts = app.contact.get_contact_list() assert len(old_contacts) + 1 == len(new_contacts) old_contacts.append(contact) assert sorted(old_contacts, key=ContactGroup.id_or_max) == sorted( new_contacts, key=ContactGroup.id_or_max)
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.open_contact_to_edit_by_index(index) firstname = wd.find_element_by_name("firstname").get_attribute("value") lastname = wd.find_element_by_name("lastname").get_attribute("value") id = wd.find_element_by_name("id").get_attribute("value") address = wd.find_element_by_name("address").text homephone = wd.find_element_by_name("home").get_attribute("value") workphone = wd.find_element_by_name("work").get_attribute("value") mobilephone = wd.find_element_by_name("mobile").get_attribute("value") secondaryphone = wd.find_element_by_name("phone2").get_attribute("value") email = wd.find_element_by_name("email").get_attribute("value") email2 = wd.find_element_by_name("email2").get_attribute("value") email3 = wd.find_element_by_name("email3").get_attribute("value") return ContactGroup(firstname=firstname, lastname=lastname, id=id, address=address, homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone, email=email, email2=email2, email3=email3)
def test_delete_first_contact(app): if app.contact.count() == 0: app.contact.add_new( ContactGroup(firstname="test9", lastname="Ivanov", nickname="goodman", company="TTY", address="Ekaterinburg", email="*****@*****.**", address2="Lenina str 5/7")) old_contacts = app.contact.get_contact_list() app.contact.delete_first() new_contacts = app.contact.get_contact_list() assert len(old_contacts) - 1 == len(new_contacts) old_contacts[0:1] = [] assert old_contacts == new_contacts
def test_delete_some_contact_db(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.add_new( ContactGroup(firstname="test9", lastname="Ivanov", nickname="goodman", company="TTY", address="Ekaterinburg", email="*****@*****.**", address2="Lenina str 5/7")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) app.contact.delete_by_id(contact.id) time.sleep(4) new_contacts = db.get_contact_list() assert len(old_contacts) - 1 == len(new_contacts) old_contacts.remove(contact) assert old_contacts == new_contacts if check_ui: assert sorted(new_contacts, key=ContactGroup.id_or_max) == sorted( app.contact.get_contact_list(), key=ContactGroup.id_or_max)
def convert(contact): return ContactGroup(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname)
f = a def random_string(prefix, maxlen): #symbols = string.ascii_letters + string.digits + string.punctuation + " "*10 symbols = string.ascii_letters + string.digits + " " * 1 return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) testdata = [ ContactGroup(firstname="", lastname="", middlename="", company="TTY", address="Ekaterinburg", home="", work="", mobile="", email="") ] + [ ContactGroup(firstname=random_string("firstname", 10), lastname=random_string("lastname", 10), middlename=random_string("middlename", 10), company=random_string("company", 20), address=random_string("address", 30), home=random_string("home", 10), work=random_string("work", 10), mobile=random_string("mobile", 10), email=random_string("email", 10), email2=random_string("email2", 10)) for i in range(n)
from model.contact import ContactGroup constant = [ ContactGroup(firstname="firstname1", lastname="lastname1", middlename="middlename1", company="company1", address="address1", home="home1", work="work1", mobile="mobile1", email="email"), ContactGroup(firstname="firstname2", lastname="lastname2", middlename="middlename2", company="company2", address="address2", home="home2", work="work2", mobile="mobile2", email="emai2") ]