def test_edit_contact(app, db, check_ui): if app.contact.count() == 0: app.contact.create_cont( Properties(firstname="QQQ", middlename="WWW", lastname="EEE", nickname="SSS", company="CCC", address="GGG", title="111", home="zzz", mobile="VVV", email="TTT", work="9371992", fax="123", email2="eee", email3="PPP", address2="ddd", phone2="123", notes="eee", homepage='TATATA')) #app.contact.edit_contact(Properties(firstname="DIMITRASH")) old_clist = db.get_contact_list() cont = random.choice(old_clist) inq = old_clist.index(cont) clist = Properties(firstname="FAFAFAFAFAFAFAFAFFAFAF") clist.id = old_clist[inq].id app.contact.edit_contact_by_id(clist.id, clist) new_clist = db.get_contact_list() assert len(old_clist) == app.contact.count() if check_ui: assert sorted(old_clist, key=Properties.id_or_max) == sorted( new_clist, key=Properties.id_or_max)
def get_contact_by_id(self, id_in): cursor = self.connection.cursor() try: cursor.execute( "SELECT id, firstname, lastname, middlename, nickname, company, " "title, address, email, email2, email3, home, mobile, work, phone2 " "FROM addressbook WHERE deprecated='0000-00-00 00:00:00' and id='%s'" % id_in) (id, firstname, lastname, middlename, nickname, company, title, address, email, email2, email3, home, mobile, work, phone2) = cursor.fetchone() contact_return = Properties(id=str(id), firstname=firstname, lastname=lastname, middlename=middlename, nickname=nickname, company=company, title=title, address=address, email=email, email2=email2, email3=email3, homephone=home, mobilephone=mobile, workphone=work, secondaryphone=phone2) finally: cursor.close() return contact_return
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") 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") address = wd.find_element_by_name("address").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 Properties(firstname=firstname, lastname=lastname, id=id, homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone, address=address, email=email, email2=email2, email3=email3)
def test_delete_contact(app, db, check_ui): if app.contact.count() == 0: app.contact.create_cont( Properties(firstname="QQQ", middlename="WWW", lastname="EEE", nickname="SSS", company="CCC", address="GGG", title="111", home="zzz", mobile="VVV", email="TTT", work="9371992", fax="123", email2="eee", email3="PPP", address2="ddd", phone2="123", notes="eee", homepage='TATATA')) old_clist = db.get_contact_list() contact = random.choice(old_clist) app.contact.delete_contact_by_id(contact.id) new_clist = db.get_contact_list() assert len(old_clist) - 1 == len(new_clist) old_clist.remove(contact) assert old_clist == new_clist if check_ui: assert sorted(old_clist, key=Properties.id_or_max) == sorted( new_clist, key=Properties.id_or_max)
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 Properties(homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone)
def get_contact_list(self): list = [] cursor = self.connection.cursor() try: cursor.execute( "select id, firstname, lastname from addressbook where deprecated = '0000-00-00 00:00:00' " ) for row in cursor: (id, firstname, lastname) = row # помещаем объект в список list.append( Properties(id=str(id), firstname=firstname, lastname=lastname)) finally: cursor.close() return list
def get_contacts_list(self): if self.contact_cache is None: wd = self.app.wd self.app.open_home_page() self.contact_cache = [] for row in wd.find_elements_by_name("entry"): cells = row.find_elements_by_tag_name("td") lastname = cells[1].text firstname = cells[2].text id = cells[0].find_element_by_tag_name("input").get_attribute( "value") all_phones = cells[5].text all_addreses = cells[3].text all_emails = cells[4].text self.contact_cache.append( Properties(firstname=firstname, lastname=lastname, id=id, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails, address=all_addreses))
def get_contact_list(self): if self.clist is None: wd = self.app.wd self.Open_home_page() self.clist = [] for element in wd.find_elements_by_xpath("//*[@name = 'entry']"): cells = element.find_elements_by_tag_name("td") id = cells[0].find_element_by_name("selected[]").get_attribute( "value") all_phones = cells[5].text all_emails = cells[4].text all_addreses = cells[3].text lastname = cells[1].text firstname = cells[2].text self.clist.append( Properties(id=id, lastname=lastname, address=all_addreses, firstname=firstname, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails)) return list(self.clist)
def test_add_contact_in_group(app, db, orm, json_groups): if len(db.get_group_list()) == 0: app.group.create(Group(name="FTP", header="gasd", footer="qed")) if len(db.get_contact_list()) == 0: app.contact.create_cont(Properties(firstname="test")) groups = db.get_group_list() available_groups = [] for group in groups: x=orm.get_contacts_not_in_group(group) if len(orm.get_contacts_not_in_group(group)) != 0: available_groups.append(group) if len(available_groups) == 0: group = json_groups app.group.create(group) group.id = orm.get_id_of_new_group() else: group = random.choice(available_groups) contact = random.choice(orm.get_contacts_not_in_group(group)) group_id = group.id contact_id = contact.id app.contact.add_contact_in_group(group_id, contact_id) assert orm.verify_contact_in_group(group, contact) is True
def test_del_contact_from_group(app, db, orm): if len(db.get_group_list()) == 0: app.group.create(Group(name="New_group_for_test")) if len(db.get_contact_list()) == 0: app.contact.create_cont(Properties(firstname="Firstname_test")) id_group_list = [] id_group_list_with_contacts = [] groups_list = db.get_group_list() for group in groups_list: id_group_list.append(group.id) for id_group in id_group_list: if len(orm.get_contacts_in_group(Group(id=id_group))) != 0: id_group_list_with_contacts.append(id_group) if len(id_group_list_with_contacts) == 0: id_contact = random.choice(db.get_contact_list()).id id_group = random.choice(db.get_group_list()).id app.contact.add_contact_in_group(id_group, id_contact) id_group_list_with_contacts.append(id_group) id_group = random.choice(id_group_list_with_contacts) id_contact = random.choice(orm.get_contacts_in_group( Group(id=id_group))).id app.contact.dellete_contact_from_group(id_group, id_contact) assert db.get_contact_by_id(id_contact) not in orm.get_contacts_in_group( Group(id=id_group))
def convert(contact): return Properties(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname)
def random_string(prefix, maxlen): symbol = string.ascii_letters + string.digits + " " return prefix + "".join( [random.choice(symbol) for i in range(random.randrange(maxlen))]) testdata = [ Properties(firstname="", middlename="", lastname="", nickname="", company="", address="", title="", home="", mobile="", email="", work="", fax="", email2="", email3="", address2="", phone2="", notes="", homepage="") ] + [ Properties(firstname=random_string("firstname", 10), middlename=random_string("middlename", 10), lastname=random_string("lastname", 10), nickname=random_string("nickname", 10), company=random_string("company", 10), address=random_string("address", 10),