def contact_from_view_page(self,index): wd = self.app.wd self.open_contact_view_page_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 add_address(homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone)
def test_modify_address_name(app, orm): check_for_address(app) old_contacts = orm.get_contact_list() contact = random.choice(old_contacts) con_obj = add_address(firstname="100", middlename="200", lastname="300", nickname="400") con_obj.id = contact.id old_contacts.remove(contact) old_contacts.append(con_obj) app.address.modify_by_id(con_obj) new_contacts = orm.get_contact_list() assert sorted(old_contacts, key=add_address.id_or_max) == sorted(new_contacts, key=add_address.id_or_max)
def get_contact_list(self): cursor = self.connection.cursor() try: list = [] 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(add_address(id=str(id), firstname=firstname, lastname=lastname)) finally: cursor.close() return list
def test_delete_some_address(app, orm, check_ui): if len(orm.get_contact_list()) == 0: app.address.create(add_address(firstname="111")) old_contacts = orm.get_contact_list() contact = random.choice(old_contacts) app.address.delete_contact_by_id(contact.id) new_contacts = orm.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=add_address.id_or_max) == sorted(app.group.get_group_list(), key=add_address.id_or_max)
def get_address_list(self): if self.address_cache is None: wd = self.app.wd self.app.open_home_page() self.address_cache = [] for element in wd.find_elements_by_xpath("//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") address = element.find_element_by_xpath("./td[4]").text all_phones = element.find_element_by_xpath("./td[6]").text all_email = element.find_element_by_xpath("./td[5]").text self.address_cache.append(add_address(firstname=firstname, lastname=lastname, id=id, address=address, all_phones_from_nome_page=all_phones, all_email_from_nome_page=all_email)) return list(self.address_cache)
def check_for_address(app): if app.address.count() == 0: app.address.create( add_address( firstname="111", middlename="222", lastname="333", nickname="444", title="555", company="666", address="777", homephone="1234567890", mobilephone="1020304050", workphone="987654321", secondaryphone="6070809010", ) )
def get_address_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").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") homephone = wd.find_element_by_name("home").get_attribute("value") mobilephone = wd.find_element_by_name("mobile").get_attribute("value") workphone = wd.find_element_by_name("work").get_attribute("value") secondaryphone = wd.find_element_by_name("phone2").get_attribute("value") return add_address(firstname=firstname, lastname=lastname, id=id, homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone, email=email, email2=email2, email3=email3, address=address)
getopt.usage() 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, maxien): symbols = string.ascii_letters + string.digits + " "*10 return prefix + "".join({random.choice(symbols) for i in range(random.randrange(maxien))}) testdata = [add_address(firstname="", middlename="", lastname="", address="", homephone="", mobilephone="", workphone="", secondaryphone="", email="", email2="", email3="")] + [ add_address(firstname=random_string("firstname", 10), middlename=random_string("middlename", 20), lastname=random_string("lastname", 20), address=random_string("address", 10), homephone=random_string("homephone", 20), mobilephone=random_string("mobilephone", 20), workphone=random_string("workphone", 10), secondaryphone=random_string("secondaryphone", 20), email=random_string("email", 20), email2=random_string("email2", 10), email3=random_string("email3", 20)) 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 check_for_address(app): if app.address.count() == 0: app.address.create(add_address(firstname="test"))
def convert(contact): return add_address(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname, address=contact.address, email=contact.email, email2=contact.email2, email3=contact.email3,homephone=contact.homephone, mobilephone=contact.mobilephone, workphone=contact.workphone, secondaryphone=contact.secondaryphone, )