def test_edit_contact_first_name(app): if app.contact.count_contact() == 0: app.contact.create_new_contact(AddNewForm(first_name="Vladimir")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = AddNewForm(first_name="Vlad") app.contact.edit_contact_by_index(index, contact) contact.id = old_contacts[index].id new_contacts = app.contact.get_contact_list() assert len(old_contacts) == app.contact.count_contact() old_contacts[index] = contact assert sorted(old_contacts, key=AddNewForm.id_or_max) == sorted(new_contacts, key=AddNewForm.id_or_max)
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.open_home_page() self.select_editable_contact_by_index(index) first_name = wd.find_element_by_name("firstname").get_attribute( "value") last_name = 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 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 AddNewForm(first_name=first_name, last_name=last_name, id=id, email=email, email2=email2, email3=email3, address=address, homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone)
def get_contact_list_version2(self): if self.contact_cashe is None: wd = self.app.wd self.open_home_page() self.contact_cashe = [] for element in wd.find_elements_by_css_selector( "tr[name='entry']"): id = element.find_element_by_name("selected[]").get_attribute( "id") last_name = element.find_element_by_css_selector( "td:nth-child(2)").text first_name = element.find_element_by_css_selector( "td:nth-child(3)").text address = element.find_element_by_css_selector( "td:nth-child(4)").text all_phones = element.find_element_by_css_selector( "td:nth-child(6)").text all_emails = element.find_element_by_css_selector( "td:nth-child(5)").text self.contact_cashe.append( AddNewForm(last_name=last_name, first_name=first_name, address=address, id=id, all_emails_from_home_page=all_emails, all_phones_from_home_page=all_phones)) return list(self.contact_cashe)
def get_contact_list(self): if self.contact_cashe is None: wd = self.app.wd self.open_home_page() self.contact_cashe = [] for element in wd.find_elements_by_css_selector( "tr[name='entry']"): id = element.find_element_by_name("selected[]").get_attribute( "id") last_name = element.find_element_by_css_selector( "td:nth-child(2)").text first_name = element.find_element_by_css_selector( "td:nth-child(3)").text address = element.find_element_by_css_selector( "td:nth-child(4)").text all_phones = element.find_element_by_css_selector( "td:nth-child(6)").text.split() self.contact_cashe.append( AddNewForm(last_name=last_name, first_name=first_name, address=address, id=id, homephone=all_phones[0], mobilephone=all_phones[1], workphone=all_phones[2], secondaryphone=all_phones[3])) return list(self.contact_cashe)
def test_delete_contact(app, db): if db.get_contact_list() == 0: app.contact.create_new_contact(AddNewForm(first_name="Vladimir")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) app.contact.delete_contact_by_id(contact.id) new_contacts = db.get_contact_list() assert len(old_contacts) - 1 == app.contact.count_contact() old_contacts.remove(contact) assert old_contacts == new_contacts
def get_contact_info_from_view_page(self, index): wd = self.app.wd self.open_home_page() self.open_contact_view_by_index(index) text = wd.find_element_by_css_selector("div#content").text homephone = re.search("H: (.*)", text).group(1) mobilephone = re.search("M: (.*)", text).group(1) workphone = re.search("W: (.*)", text).group(1) secondaryphone = re.search("P: (.*)", text).group(1) return AddNewForm(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, address, email from addressbook" ) for row in cursor: (id, firstname, lastname, address, email) = row list.append( AddNewForm(id=str(id), first_name=firstname, last_name=lastname, address=address, email=email)) finally: cursor.close() return list
n = 5 f = "resourses/contact.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 + " " * 10 return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) test_contact_data = [ AddNewForm(first_name="", last_name="", address="", email="") ] + [ AddNewForm(first_name=random_string("first_name:", 10), last_name=random_string("last_name:", 10), address=random_string("address:", 10), email=random_string("email:", 10)) 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(test_contact_data))