def test_modify_contact_db(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Info(firstname="test")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) changed_contact = Info(firstname="111qwerty", lastname="111eeeeeeeeee") changed_contact.id = contact.id app.contact.modify_contact_by_id(contact.id, changed_contact) assert len(old_contacts) == app.contact.count() new_contacts = db.get_contact_list() old_contacts.remove(contact) old_contacts.append(changed_contact) assert sorted(old_contacts, key=Info.id_or_max) == sorted(new_contacts, key=Info.id_or_max) if check_ui: assert sorted(new_contacts, key=Info.id_or_max) == sorted(app.contact.get_contact_list(), key=Info.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") address = wd.find_element_by_name("address").get_attribute("value") id = wd.find_element_by_name("id").get_attribute("value") homedid = wd.find_element_by_name("home").get_attribute("value") workdid = wd.find_element_by_name("work").get_attribute("value") cellular = 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 Info(firstname=firstname, lastname=lastname, id=id, address=address, homedid=homedid, workdid=workdid, cellular=cellular, secondaryphone=secondaryphone, email=email, email2=email2, email3=email3)
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 homedid = re.search("H: (.*)", text).group(1) workdid = re.search("W: (.*)", text).group(1) cellular = re.search("M: (.*)", text).group(1) secondaryphone = re.search("P: (.*)", text).group(1) return Info(homedid=homedid, workdid=workdid, cellular=cellular, secondaryphone=secondaryphone)
def convert(contact): return Info(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname, address=contact.address, homedid=contact.homedid, cellular=contact.cellular, workdid=contact.workdid, secondaryphone=contact.secondaryphone, email=contact.email, email2=contact.email2, email3=contact.email3)
def test_delete_contact_db(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Info(firstname="test")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) app.contact.delete_contact_by_id(contact.id) assert len(old_contacts) - 1 == app.contact.count() new_contacts = db.get_contact_list() old_contacts.remove(contact) assert old_contacts == new_contacts if check_ui: assert sorted(new_contacts, key=Info.id_or_max) == sorted( app.contact.get_contact_list(), key=Info.id_or_max)
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( Info(id=str(id), firstname=firstname, lastname=lastname)) finally: cursor.close() return list
def test_modify_contact_db(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Info(firstname="test")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) changed_contact = Info(firstname="111qwerty", lastname="111eeeeeeeeee") changed_contact.id = contact.id app.contact.modify_contact_by_id(contact.id, changed_contact) assert len(old_contacts) == app.contact.count() new_contacts = db.get_contact_list() old_contacts.remove(contact) old_contacts.append(changed_contact) assert sorted(old_contacts, key=Info.id_or_max) == sorted(new_contacts, key=Info.id_or_max) if check_ui: assert sorted(new_contacts, key=Info.id_or_max) == sorted( app.contact.get_contact_list(), key=Info.id_or_max) # # def test_modify_contact(app): # if app.contact.count() == 0: # app.contact.create(Info(firstname="test")) # old_contacts = app.contact.get_contact_list() # index = randrange(len(old_contacts)) # contact = Info(firstname="111qwerty", lastname="111eeeeeeeeee") # 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=Info.id_or_max) == sorted(new_contacts, key=Info.id_or_max) # # app.contact.modify(Info(firstname="qqq", middlename="www", lastname="eee", nick="ttt", title="rrr", cname="yyy", address="yyy", homedid="111", cellular="222", workdid="333", fax="444", email="kkk", email2="aaa", email3="sss", website="ddd", address2="fff", home="666", notes="zzz"))
def test_add_contact_to_group_db(app, orm): if len(orm.get_contact_list()) == 0: app.contact.create(Info(firstname="test")) if len(orm.get_group_list()) == 0: app.group.create(Group(groupname="test")) groups = orm.get_group_list() group = random.choice(groups) old_contacts = orm.get_contact_list() old_contacts_in_group = orm.get_contacts_in_group(Group(id=group.id)) contact = random.choice(old_contacts) app.contact.add_contact_to_group_by_id(contact.id, group.id) old_contacts_in_group.append(contact) new_contacts_in_group = orm.get_contacts_in_group(Group(id=group.id)) assert sorted(new_contacts_in_group, key=Info.id_or_max) == sorted(old_contacts_in_group, key=Info.id_or_max)
def test_remove_contact_from_group_db(app, orm): if len(orm.get_contact_list()) == 0: app.contact.create(Info(firstname="test")) if len(orm.get_group_list()) == 0: app.group.create(Group(groupname="test")) groups = orm.get_group_list() group = random.choice(groups) old_contacts_in_group = orm.get_contacts_in_group(group) if len(old_contacts_in_group) == 0: selected_contact_to_add = random.choice(orm.get_contact_list()) app.contact.add_contact_to_group_by_id(selected_contact_to_add.id, group.id) old_contacts_in_group = orm.get_contacts_in_group(group) selected_contact = random.choice(old_contacts_in_group) app.contact.remove_contact_from_group_by_id(selected_contact.id, group.id) old_contacts_in_group.remove(selected_contact) new_contacts_in_group = orm.get_contacts_in_group(Group(id=group.id)) assert sorted(new_contacts_in_group, key=Info.id_or_max) == sorted(old_contacts_in_group, key=Info.id_or_max)
def get_list_of_contacts_in_group_by_id(self, group_id): wd = self.app.wd self.app.return_to_home() self.open_group_with_contacts_page(group_id) for element in wd.find_elements_by_css_selector("tr[name='entry']"): id = element.find_element_by_name("selected[]").get_attribute( "value") cells = element.find_elements_by_tag_name("td") l_name = cells[1].text f_name = cells[2].text address = cells[3].text all_phones = cells[5].text all_emails = cells[4].text self.contacts_in_group.append( Info(firstname=f_name, lastname=l_name, id=id, address=address, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails)) return self.contacts_in_group
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.app.return_to_home() self.contact_cache = [] for element in wd.find_elements_by_css_selector( "tr[name='entry']"): id = element.find_element_by_name("selected[]").get_attribute( "value") cells = element.find_elements_by_tag_name("td") l_name = cells[1].text f_name = cells[2].text address = cells[3].text all_phones = cells[5].text all_emails = cells[4].text self.contact_cache.append( Info(firstname=f_name, lastname=l_name, id=id, address=address, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails)) return list(self.contact_cache)
def new_contact(self, firstname, lastname): return Info(firstname=firstname, lastname=lastname)
def modify_contact(app, random_contact, name, last_name): changed_contact = Info(firstname=name, lastname=last_name) app.contact.modify_contact_by_id(random_contact.id, changed_contact)
def non_empty_contact_list(app, db): if len(db.get_contact_list()) == 0: app.contact.create(Info(firstname="Test1")) return db.get_contact_list()
def new_contact(name, last_name, number): return Info(firstname=name, lastname=last_name, homedid=number)
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 = [Info(firstname="", middlename="", lastname="")] + [ Info(firstname=random_string("FN", 10), middlename=random_string("MN", 10), lastname=random_string("LN", 10), address=random_string("ADDRESS", 10), homedid=random_string("HOME", 10)) for i in range(n) ] # testdata = [ # Info(firstname=firstname, middlename=middlename, lastname=lastname) # for firstname in ["", random_string("FN", 10)] # for middlename in ["", random_string("MN", 20)] # for lastname in ["", random_string("LN", 20)] # ] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f)