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") id = wd.find_element_by_name("id").get_attribute("value") telhome = wd.find_element_by_name("home").get_attribute("value") mobile = wd.find_element_by_name("mobile").get_attribute("value") telwork = wd.find_element_by_name("work").get_attribute("value") telhome2 = wd.find_element_by_name("phone2").get_attribute("value") email1 = 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") address1 = wd.find_element_by_name("address").get_attribute("value") return Details(firstname=firstname, lastname=lastname, id=id, telhome=telhome, mobile=mobile, telwork=telwork, telhome2=telhome2, email1=email1, email2=email2, email3=email3, address1=address1)
def test_add_new_project(app): app.session.login("administrator", "root") old_list = app.project.get_project_list() app.project.create( Details(projectname=randomString(8), description=randomString(15))) new_list = app.project.get_project_list() assert len(new_list) == len(old_list) + 1
def test_delete_first_contact(app): if app.contact.count() == 0: app.contact.create( Details(firstname="first name", middlename="test del")) old_contacts = app.contact.get_contact_list() app.contact.delete_first_contact() new_contacts = app.contact.get_contact_list() assert len(old_contacts) - 1 == len(new_contacts) old_contacts[0:1] = [] assert old_contacts == new_contacts
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 telhome = re.search("H: (.*)", text).group(1) mobile = re.search("M: (.*)", text).group(1) telwork = re.search("W: (.*)", text).group(1) telhome2 = re.search("P: (.*)", text).group(1) return Details(telhome=telhome, mobile=mobile, telwork=telwork, telhome2=telhome2)
def test_contact_on_home_page(app): if app.contact.count() == 0: app.contact.create(Details(firstname="first name", middlename="test")) contacts = app.contact.get_contact_list() index = randrange(len(contacts)) contact_from_home_page = app.contact.get_contact_list()[index] contact_from_edit_page = app.contact.get_contact_info_from_edit_page(index) assert contact_from_home_page.firstname == contact_from_edit_page.firstname assert contact_from_home_page.lastname == contact_from_edit_page.lastname assert contact_from_home_page.address1 == contact_from_edit_page.address1 assert contact_from_home_page.all_phones_from_home_page == merge_phones_like_on_home_page( contact_from_edit_page) assert contact_from_home_page.all_emails_from_home_page == merge_emails_like_on_home_page( contact_from_edit_page)
def get_project_list(self): if self.project_cache is None: wd = self.app.wd wd.find_element_by_link_text("Manage").click() wd.find_element_by_link_text("Manage Projects").click() self.project_cache = [] for row in wd.find_elements_by_tag_name("tr"): cell = row.find_elements_by_xpath( "//*[@id='content']/div[2]/table/tbody/tr/td") text_projectname = cell[0].text text_description = cell[4].text self.project_cache.append( Details(projectname=text_projectname, description=text_description)) return list(self.project_cache)
def test_delete_contact_from_group(app, db): if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) group_list = db.get_group_list() group = random.choice(group_list) contact_list = dba.get_contacts_in_group(Group(id=group.id)) if len(contact_list) == 0: app.contact.create( Details(firstname="firstname", middlename="middlename", lastname="test", nickname="test")) contact = random.choice(contact_list) app.contact.delete_contact_from_group(contact.id, group.id) new_contact_list = list(dba.get_contacts_in_group(Group(id=group.id))) assert contact not in new_contact_list
def test_add_contact_to_group(app, db): if len(db.get_contact_list()) == 0: app.contact.create( Details(firstname="firstname", middlename="middlename", lastname="test", nickname="test")) old_contacts = db.get_contact_list() if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) contact = random.choice(old_contacts) group_list = db.get_group_list() group = random.choice(group_list) app.contact.add_contact_to_group(contact.id, group.id) new_group_list = list(dba.get_contacts_in_group(Group(id=group.id))) assert contact in new_group_list
def test_delete_some_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create( Details(firstname="first name", middlename="test del")) old_contacts = db.get_contact_list() contacts_on_hp = app.contact.get_contact_list() assert sorted(old_contacts, key=Details.id_or_max) == sorted(contacts_on_hp, key=Details.id_or_max) contact = random.choice(old_contacts) app.contact.delete_contact_by_id(contact.id) new_contacts = db.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=Details.id_or_max) == sorted( app.contact.get_contact_list(), key=Details.id_or_max)
def test_edit_first(app): app.contact.edit_first( Details(firstname="edited name", middlename=random.choice(MyData.name), lastname=random.choice(MyData.lastname), nickname=random.choice(MyData.nickname), title=" edited title", company="edited company", address1="edited address1", telhome=random.choice(MyData.phone), mobile=random.choice(MyData.phone), telwork=random.choice(MyData.phone), fax=random.choice(MyData.phone), email1=random.choice(MyData.email), email2=random.choice(MyData.email), email3=random.choice(MyData.email), homepage="www.homepage edited.com", address2="address edited", telhome2=random.choice(MyData.phone), notes="edited notes"))
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.open_contacts_page() self.contact_cache = [] for row in wd.find_elements_by_name("entry"): cell = row.find_elements_by_tag_name("td") text_lastname = cell[1].text text_firstname = cell[2].text id_contact = cell[0].find_element_by_tag_name( "input").get_attribute("value") all_phones = cell[5].text all_emails = cell[4].text text_address = cell[3].text self.contact_cache.append( Details(lastname=text_lastname, firstname=text_firstname, id=id_contact, all_phones_from_home_page=all_phones, all_emails_from_home_page=all_emails, address1=text_address)) return list(self.contact_cache)
def convert(contact): return Details(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname)
from model.details import Details constant = [ Details(firstname="f1", middlename="m1", lastname="l1", nickname="n1", title="t1", company="c1", address1="", telhome="", mobile="", telwork="", fax="", email1="", email2="", email3="", homepage="", address2="", telhome2="", notes=""), Details(firstname="f2", middlename="m2", lastname="l2", nickname="n2", title="t2", company="c2", address1="", telhome="", mobile="", telwork="",