def test_edit_contact_firstname(app): if app.contact.count_c() == 0: app.contact.create_c(Contact(userfirstname="name_modify")) app.contact.editing_first_contact(Contact(userfirstname="NewName")) old_contacts = app.contact.get_contact_list() contact = Contact(userfirstname="NewName") contact.id = old_contacts[0].id app.contact.editing_first_contact(contact) new_contacts = app.contact.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[0] = contact assert sorted(old_contacts, key=Contact.id_or_maxc) == sorted(new_contacts, key=Contact.id_or_maxc)
def test_edit_firstname_random_contact(app): if app.contact.count_c() == 0: app.contact.create_c(Contact(userfirstname="name_modify")) old_contacts = app.contact.get_contact_list() index = randrange(len(old_contacts)) contact = Contact(userfirstname="NewName") contact.id = old_contacts[index].id app.contact.editing_contact_by_index(index, contact) new_contacts = app.contact.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[index] = contact assert sorted(old_contacts, key=Contact.id_or_maxc) == sorted(new_contacts, key=Contact.id_or_maxc)
def test_add_contact(app, db, orm): if len(db.get_contact_list()) == 0: app.contact.create( Contact(firstname="test1", lastname="test2", address="test3", homephone="test4", email="test5")) if len(db.get_group_list()) == 0: app.group.create(Group(name="test1", header="test11", footer="test111")) groups = db.get_group_list() for group in groups: list_group = orm.get_contacts_not_in_group(Group(id=group.id)) if len( list_group ) > 0: # если есть контакты, не состоящие в группе, выбираем любой и добавляем его в группу contact = random.choice(list_group) app.contact.add_contact_to_group(contact.id, group.id) break elif len(list_group) == 0: if group != groups[ -1]: # если элемент не последний в списке, то берем следующую группу continue else: # если это была последняя группа, то создаем новую и добавляем в нее любой существующий контакт app.group.create( Group(name="test_name", header="test_header", footer="test_footer")) groups = sorted(db.get_group_list(), key=Group.id_or_max) group = groups[-1] contact = random.choice(db.get_contact_list()) app.contact.add_contact_to_group(contact.id, group.id) list_in_group = orm.get_contacts_in_group(Group(id=group.id)) assert contact in list_in_group
def test_remove_contact_from_group(app, db, orm): if len(db.get_contact_list()) == 0: app.contact.create( Contact(firstname="test1", lastname="test2", address="test3", homephone="test4", email="test5")) if len(db.get_group_list()) == 0: app.group.create(Group(name="test1", header="test11", footer="test111")) contacts = db.get_contact_list() contact = random.choice(contacts) groups = db.get_group_list() group = random.choice(groups) list1 = orm.get_contacts_in_group(Group(id=group.id)) if contact in list1: #проверяем, что контакт состоит в группе app.contact.remove_contact_from_group(contact.id, group.id) else: app.contact.add_contact_to_group( contact.id, group.id) # если контакт не в группе, добавляем его app.contact.remove_contact_from_group( contact.id, group.id) # а потом удаляем из группы list2 = orm.get_contacts_not_in_group(Group(id=group.id)) assert contact in list2
def get_contact_info_from_edit_page(self, index): wd = self.app.wd # открытие страницы редактирования контакта self.return_to_home() self.select_edit_contact_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").text homephone = wd.find_element_by_name("home").get_attribute("value") workphone = wd.find_element_by_name("work").get_attribute("value") mobilephone = wd.find_element_by_name("mobile").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") return Contact(firstname=firstname, lastname=lastname, id=id, address=address, homephone=homephone, workphone=workphone, mobilephone=mobilephone, secondaryphone=secondaryphone, email=email, email2=email2, email3=email3)
def get_contact_list(self): wd = self.app.wd self.open_home_page() contact = [] for element in wd.find_elements_by_css_selector("span.contact"): text = element.text id = element.find_element_by_name("selected[]").get_attribute( "value") contact.append(Contact(firstname=text, lastname=text, id=id)) return contact
def test_delete_contact(app): if app.contact.count_c() == 0: app.contact.create_c(Contact(userfirstname="name_del")) old_contacts = app.contact.get_contact_list() index_con = randrange(len(old_contacts)) app.contact.delete_contact_by_index(index_con) new_contacts = app.contact.get_contact_list() assert len(old_contacts) - 1 == len(new_contacts) old_contacts[index_con:index_con + 1] = [] assert old_contacts == new_contacts
def test_edit_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create( Contact(firstname="Alexandr", lastname="Gubanov", nickname="Guban", address="Street", homephone="+790999999", mobilephone="+7909123456", workphone="+89891234567", secondaryphone="+79876654432", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**")) old_contacts = db.get_contact_list() edit_contact = random.choice(old_contacts) contact = Contact(firstname="Alexandr_QA", lastname="Gubanov", nickname="Guban", address="Street", homephone="+790999999", mobilephone="+7909123456", workphone="+89891234567", secondaryphone="+79876654432", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**") contact.id = edit_contact.id app.contact.edit_contact_by_id(edit_contact.id, contact) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts.remove(edit_contact) old_contacts.append(contact) assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max) assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max) if check_ui: assert sorted(new_contacts, key=Contact.id_or_max) == sorted( app.contact.get_contact_list(), key=Contact.id_or_max)
def test_add_contact(app): old_contacts = app.contact.get_contact_list() contact = Contact(userfirstname="Edyta", usermiddlename="EK", userlastname="Karpinska", nick="EiKi", title="Title", company="Python", address="My address", home="Home", mobile="789456123", workphone="85965784", fax="879654", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**", homepage="homepage", birthyear="1990", anniversaryyear="2015", secondaddres="Secondary address", homephone="Second home", notes="Note") app.contact.create_c(contact) # do usuniecia new_contacts = app.contact.get_contact_list() assert len(old_contacts) + 1 == app.contact.count_c() new_contacts = app.contact.get_contact_list() old_contacts.append(contact) assert sorted(old_contacts, key=Contact.id_or_maxc) == sorted(new_contacts, key=Contact.id_or_maxc)
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.open_return_contacts_page() self.contact_cache = [] for element in wd.find_elements_by_name("entry"): text = element.find_element_by_xpath("td[3]").text id = element.find_element_by_name("selected[]").get_attribute( "value") self.contact_cache.append(Contact(userfirstname=text, id=id)) return list(self.contact_cache)
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 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 Contact(homephone=homephone, workphone=workphone, mobilephone=mobilephone, secondaryphone=secondaryphone)
def get_contact_list(self): contact_list = [] with self.connection.cursor() as cursor: cursor.execute( "select id, firstname, lastname, address, home, mobile, work, email, email2, email3, phone2 from " "addressbook where deprecated='0000-00-00 00:00:00'") for row in cursor: (id, firstname, lastname, address, home, mobile, work, email, email2, email3, phone2) = row contact_list.append( Contact(id=str(id), firstname=firstname, lastname=lastname, address=address, homephone=home, mobilephone=mobile, workphone=work, secondaryphone=phone2, email=email, email2=email2, email3=email3)) return contact_list
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.return_to_home() self.contact_cache = [] for row in wd.find_elements_by_name("entry"): cells = row.find_elements_by_tag_name("td") lastname = cells[1].text firstname = cells[2].text id = cells[0].find_element_by_name("selected[]").get_attribute( "value") address = cells[3].text all_emails = cells[4].text all_phones = cells[5].text self.contact_cache.append( Contact(firstname=firstname, lastname=lastname, id=id, address=address, all_emails_from_home_page=all_emails, all_phones_from_home_page=all_phones)) return list(self.contact_cache)
from model.group import Contact testdata = [ Contact(firstname="firstname1", lastname="lastname1", address="address1", homephone="1234", email="*****@*****.**") ] """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))]) testdata = [Contact(firstname="", lastname="", address="", homephone="", email="")] + [ Contact(firstname=random_string("firstname", 5), lastname=random_string("lastname", 10), address=random_string("address", 20), homephone=(random_string("homephone", 10)), email=(random_string("email", 7))) for i in range(5) ]"""
def convert(contact): return Contact(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname)
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, maxlen): symbols = string.ascii_letters + string.digits + " " * 10 return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) testdata = [ Contact(firstname="", lastname="", address="", homephone="", email="") ] + [ Contact(firstname=random_string("firstname", 5), lastname=random_string("lastname", 10), address=random_string("address", 20), homephone=(random_string("homephone", 10)), email=(random_string("email", 7))) 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))
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))]) testdata = [ Contact(firstname="", lastname="", company="", address="", email="", homepage="") ] + [ Contact(firstname=random_string("firstname", 10), lastname=random_string("lastname", 15), company=random_string("company", 10), address=random_string("address", 20), email=random_string("email", 10), homepage=random_string("homepage", 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)