def test_mod_contact(app): if app.contact.count() == 0: app.contact.add(Contact(firstname="Hank", lastname="Hill", address="Texas")) old_contacts = app.contact.get_contacts_list() index = randrange(len(old_contacts)) contact = Contact(firstname="Anna", lastname="Frank") contact.id = old_contacts[index].id app.contact.modify_by_index(contact, index) new_contacts = app.contact.get_contacts_list() old_contacts[index] = contact assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def get_contact_info_from_edit_page(self, index): wd = self.wd self.click_edit_contact(index) id = wd.find_element_by_name('id').get_attribute('value') first_name = wd.find_element_by_name('firstname').get_attribute( 'value') last_name = wd.find_element_by_name('lastname').get_attribute('value') nick_name = wd.find_element_by_name('nickname').get_attribute('value') home_phone = wd.find_element_by_name('home').get_attribute('value') mobile_phone = wd.find_element_by_name('mobile').get_attribute('value') work_phone = wd.find_element_by_name('work').get_attribute('value') secondary_phone = 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 Contact(id=id, firstname=first_name, lastname=last_name, nickname=nick_name, home_phone=home_phone, work_phone=work_phone, mobile_phone=mobile_phone, secondary_phone=secondary_phone, email=email, email2=email2, email3=email3, address=address)
def test_modify_first_contact(app): if app.contact.count() == 0: app.contact.create( Contact(firstname="Misha", middlename="MIO", lastname="Ivanov", nickname="MIOBN", title="MR", company="Comp", address="Moscow", home="8495", mobile="8911", work="8812", fax="84951", email="er", email2="qw", email3="yu", homepage="rewti", bday="14", bmonth="November", byear="1986", aday="18", amonth="November", ayear="1996", address2="SPb", phone2="Nevskiy", notes="none")) app.contact.submit_creation_new_contact() app.contact.modify_first_contact()
def test_add_contact(app): app.open_home_page() old_contacts = app.contact.get_contact_list() contact = Contact(firstname="Misha", middlename="MIO", lastname="Ivanov", nickname="MIOBN", title="MR", company="Comp", address="Moscow", home="8495", mobile="8911", work="8812", fax="84951", email="er", email2="qw", email3="yu", homepage="rewti", bday="14", bmonth="November", byear="1986", aday="18", amonth="November", ayear="1996", address2="SPb", phone2="Nevskiy", notes="none") app.contact.fill_form_name(contact) app.contact.submit_creation_new_contact() new_contacts = app.contact.get_contact_list() app.open_home_page() assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)
def test_delete_contact(app): if app.contact.count() == 0: app.contact.add( Contact(firstname="Hank", lastname="Hill", address="Texas")) old_contacts = app.contact.get_contacts_list() index = randrange(len(old_contacts)) app.contact.delete_by_index(index) assert len(old_contacts) - 1 == app.contact.count()
def test_edit_group_data(app): if app.contact.count() == 0: app.contact.create( Contact(firstname='firstname' + str(random.randint(1, 999)), lastname='lastname', nickname='nickname')) before = app.contact.get_contact_list() random_contact = random.randint(0, len(before) - 1) rand_id = str(random.randint(1, 999)) app.contact.edit_data_by_index( random_contact, Contact(firstname='firstname' + rand_id, lastname='lastname', nickname='nickname' + rand_id)) assert app.contact.count() == len(before) after = app.contact.get_contact_list() assert after != before, 'Список контактов не изменился после редактирования контакта'
def get_contact_list(self): wd = self.app.wd self.open_add_new_contact_page() contacts = [] for element in wd.find_elements_by_css_selector("td.center"): text = element.text id = element.find_element_by_xpath("//td/input").get_attribute("value") contacts.append(Contact(firstname=text, middlename=text, id=id)) return contacts
def create_random_contact(self): self.create( Contact(firstname=random_string('firstname', 10), lastname=random_string('lastname', 15), nickname=random_string('nickname', 15), email=random_string('e', 10, 0) + '@mail.ru', home_phone=random_phone(8), mobile_phone=random_phone(8), secondary_phone=random_phone(8), work_phone=random_phone(8)))
def get_contact_list(self): lst = [] cursor = self.connection.cursor() try: cursor.execute('select id, firstname, lastname, nickname from addressbook where deprecated="0000-00-00 00:00:00"') for row in cursor: (id, firstname, lastname, nickname) = row lst.append(Contact(id=str(id), firstname=firstname, lastname=lastname, nickname=nickname)) finally: cursor.close() return lst
def test_delete_contacts(app): if app.contact.count() == 0: app.contact.create( Contact(firstname='firstname' + str(random.randint(1, 999)), lastname='lastname', nickname='nickname')) before = app.contact.get_contact_list() random_contact = random.choice(before) app.contact.delete_by_id(random_contact.id) app.accept_alert() after = app.contact.get_contact_list() assert before != after
def convert_contact(contact): return Contact( id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname, nickname=contact.nickname, home_phone=contact.home_phone, mobile_phone=contact.mobile_phone, work_phone=contact.work_phone, secondary_phone=contact.secondary_phone, email=contact.email, email2=contact.email2, email3=contact.email3 )
def get_contacts_list(self): if self.contacts_cache is None: wd = self.app.wd self.contacts_cache = [] for row in wd.find_elements_by_name("entry"): cells = row.find_elements_by_tag_name("td") firstname = cells[2].text lastname = cells[1].text all_phones = cells[5].text all_emails = cells[4].text id = cells[0].find_element_by_css_selector("input").get_attribute("id") self.contacts_cache.append(Contact(firstname=firstname, lastname=lastname, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails, id=id)) return list(self.contacts_cache)
def get_contact_info_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 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) content = wd.find_element_by_css_selector("div[id='content']") emails = content.find_elements_by_tag_name("a") email = emails[0].text email2 = emails[1].text email3 = emails[2].text return Contact(homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone, email=email, email2=email2, email3=email3, id=id)
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") 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") 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") id = wd.find_element_by_name("id").get_attribute("value") return Contact(firstname=firstname, lastname=lastname, homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone, email=email, email2=email2, email3=email3, id=id)
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.app.open_homepage() self.contact_cache = [] for c in wd.find_elements_by_name('entry'): c_fields = c.find_elements_by_tag_name('td') lastname = c_fields[1].text firstname = c_fields[2].text all_phones = c_fields[5].text all_emails = c_fields[4].text address = c_fields[3].text contact_id = c_fields[0].find_element_by_tag_name( 'input').get_attribute('id') self.contact_cache.append( Contact(id=contact_id, firstname=firstname, lastname=lastname, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails, address=address)) return self.contact_cache
def get_contact_info_from_view_page(self, index): wd = self.wd self.open_contact_view_page(index) text = wd.find_element_by_id('content').text first_last_name = wd.find_element_by_id( 'content').find_element_by_tag_name('b').text try: home_phone = re.search('H: (.*)', text).group(1) except AttributeError: home_phone = '' try: work_phone = re.search('W: (.*)', text).group(1) except AttributeError: work_phone = '' try: mobile_phone = re.search('M: (.*)', text).group(1) except AttributeError: mobile_phone = '' try: secondary_phone = re.search('P: (.*)', text).group(1) except AttributeError: secondary_phone = '' emails = re.findall('[A-Zaa-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}', text) all_mails = '\n'.join(emails) return Contact(firstname=first_last_name.split()[0], lastname=first_last_name.split()[1], home_phone=home_phone, work_phone=work_phone, mobile_phone=mobile_phone, secondary_phone=secondary_phone, all_emails_from_view_page=all_mails)
def random_string(prefix, max_len, spaces=5): symbols = string.ascii_letters + string.digits + " " * spaces return prefix + ''.join( [random.choice(symbols) for i in range(random.randrange(max_len))]) def random_phone(max_len): return '+' + ''.join([ random.choice(string.digits) for i in range(random.randrange(6, max_len)) ]) testdata = [Contact(firstname='', lastname='')] + [ Contact(firstname=random_string('firstname', 10), lastname=random_string('lastname', 15), nickname=random_string('nickname', 15), email=random_string('e', 10, 0) + '@mail.ru', home_phone=random_phone(8), mobile_phone=random_phone(8), secondary_phone=random_phone(8), work_phone=random_phone(8)) for i in range(5) ] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', f_name) with open(file, 'w') as f: jsonpickle.set_encoder_options('json', indent=2) f.write(jsonpickle.encode(testdata))
def random_phone(): return str(randint(10000, 99999)) def random_email(length): symbols = string.ascii_letters + string.digits return "".join(random.choice(symbols) for i in range(random.randrange(1, length))) + "@" + \ "".join(random.choice(symbols) for i in range(random.randrange(1, length))) + ".com" testdata = [ Contact(firstname=random_name(7), lastname=random_name(10), address=random_address(20), homephone=random_phone(), mobilephone=random_phone(), workphone=random_phone(), secondaryphone=random_phone(), email=random_email(5), email2=random_email(6), email3=random_email(7)) for i in range(3) ] @pytest.mark.parametrize("contact", testdata, ids=[repr(x) for x in testdata]) def test_add_contact(app, contact): old_contacts = app.contact.get_contacts_list() app.contact.add(contact) assert len(old_contacts) + 1 == app.contact.count()