def test_modify_some_contact_firstname(app, db): # если нет ни одного контакта - создаем новый if len(db.get_contact_list()) == 0: app.contact.create_contact( Contact(lastname="L0", firstname="F0", address="SPB", email="some_email", home="111", mobile="222", work="333", phone2="444")) old_contacts = db.get_contact_list() # выбираем случайный контакт, который будем редактировать contact = random.choice(old_contacts) # запоминаем какой id был у контакта, который будем изменять и передаем его в контакт, которым будем перезаписывать new_data = Contact(id=contact.id, firstname="new_name") app.contact.modify_contact_by_id(new_data, contact.id) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) # перезаписываем из кода old_contacts.remove(contact) old_contacts.append(new_data) # old_contacts - изменили через код # new_contacts - изменили через тестируемую систему assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max) app.open_home_page()
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 # если не нашлась строка на view page, то присваиваем номеру пустую строку, # т.к. wd из формы edit прочитает пустые поля, как пустые строки home_search = re.search("H: (.*)", text) if home_search is None: home = "" else: home = home_search.group(1) mobile_search = re.search("M: (.*)", text) if mobile_search is None: mobile = "" else: mobile = mobile_search.group(1) work_search = re.search("W: (.*)", text) if work_search is None: work = "" else: work = work_search.group(1) phone2_search = re.search("P: (.*)", text) if phone2_search is None: phone2 = "" else: phone2 = phone2_search.group(1) return Contact(home=home, mobile=mobile, work=work, phone2=phone2)
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.open_contact_to_edit_by_index(index) id = wd.find_element_by_name("id").get_attribute("value") lastname = wd.find_element_by_name("lastname").get_attribute("value") firstname = wd.find_element_by_name("firstname").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") home = wd.find_element_by_name("home").get_attribute("value") mobile = wd.find_element_by_name("mobile").get_attribute("value") work = wd.find_element_by_name("work").get_attribute("value") phone2 = wd.find_element_by_name("phone2").get_attribute("value") return Contact(id=id, lastname=lastname, firstname=firstname, address=address, email=email, email2=email2, email3=email3, home=home, mobile=mobile, work=work, phone2=phone2)
def get_contact_list(self): list = [] cursor = self.connection.cursor() try: cursor.execute( "select id, lastname, firstname from addressbook where deprecated='0000-00-00 00:00:00'" ) for row in cursor: # в переменные присваиваем значения из кортежа, который соответствует строке (id, lastname, firstname) = row # делаем приведение типов для id, т.к. в БД id это int, а из web читаем как str list.append( Contact(id=str(id), lastname=lastname, firstname=firstname)) finally: cursor.close() return list
def test_add_contact_to_group(app, db): if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) group_list = db.get_group_list() rand_group = random.choice(group_list) def generate_new_contact_id(): id_list = db.get_all_contact_id_list() new_id = max(id_list) + 1 return str(new_id) new_contact = Contact(id=generate_new_contact_id(), lastname="lll8", firstname="fff") app.open_home_page() app.contact.create_contact(new_contact, add_to_group=rand_group) orm = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") contacts_in_group = orm.get_contacts_in_group(rand_group) assert new_contact in contacts_in_group
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.app.open_home_page() self.contact_cache = [] rows = wd.find_elements_by_name("entry") print(rows) for element in rows: cells = element.find_elements_by_tag_name("td") lastname_text = cells[1].text firstname_text = cells[2].text id = element.find_element_by_name("selected[]").get_attribute( "value") all_phones = cells[5].text all_emails = cells[4].text address = cells[3].text self.contact_cache.append( Contact(id=id, lastname=lastname_text, firstname=firstname_text, address=address, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails)) return list(self.contact_cache)
if o == "-n": n = int(a) elif o == "-f": f = a def random_string(prefix, maxlen): symbols = string.ascii_letters + string.digits return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) def random_number(maxlen): symbols = string.digits + "-" + "(" + ")" return "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) testdata = [Contact(lastname="", firstname="", address="", email="", home="", mobile="", work="", phone2="")] \ + [Contact(lastname=random_string("lastname", 10), firstname=random_string("firstname", 10), address=random_string("address", 10), email=random_string("email", 10), home=random_number(10), mobile=random_number(10), work=random_number(10), phone2=random_number(10)) for i in range(n)] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f) with open(file, "w") as f: jsonpickle.set_encoder_options("json", indent=2) f.write(jsonpickle.encode(testdata))
def convert(contact): return Contact(id=str(contact.id), lastname=contact.lastname, firstname=contact.firstname)