def test_delete_contact_from_group(app, db): if len(db.get_contacts_list()) == 0: app.contact.create( Contact("Precond name", "Precond last", "Precon address", "00000", " Precond notes notes notes")) if len(db.get_groups_list()) == 0: app.group.create( Group("Precondiction Group name", "Precondition Group header", "Precongition Group footer")) db_orm = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="******") groups = db_orm.get_group_list() for g in groups: if len(db_orm.get_contact_in_group(g)) > 0: contact = random.choice(db_orm.get_contact_in_group(g)) app.contact.delete_contact_from_group(contact, g) assert contact not in db_orm.get_contact_in_group(g) print("IN IF") return else: app.contact.create(Contact(firstname="Contact")) app.navigation.open_contacts() contact = db.get_last_added_contact() group = random.choice(db.get_groups_list()) app.contact.add_contact_to_group(contact, group) #assert str(contact) in str(db_orm.get_contact_in_group(group)) app.contact.delete_contact_from_group(contact, group) assert str(contact) not in str(db_orm.get_contact_in_group(group)) print("IN ELSE")
def get_contacs_list(self): if self.contact_cache is None: wd = self.app.wd self.app.navigation.open_home() self.contact_cache = [] edit_links = [] c_firstnames = [] c_lastnames = [] c_all_phones = [] c_all_emails = [] c_address = [] web_elements_contact = wd.find_elements_by_css_selector("table#maintable input[name='selected[]']") for web_el in web_elements_contact: edit_links.append(web_el.get_attribute("id")) c_all_phones.append(web_el.find_element_by_xpath("./../following-sibling::td[5]").text) c_all_emails.append(web_el.find_element_by_xpath("./../following-sibling::td[4]").text) c_address.append(web_el.find_element_by_xpath("./../following-sibling::td[3]").text) for link in edit_links: wd.find_element_by_css_selector("a[href='edit.php?id=" + link + "']").click() c_firstnames.append(wd.find_element_by_css_selector("input[name=firstname]").get_attribute("value")) c_lastnames.append(wd.find_element_by_css_selector("input[name=lastname]").get_attribute("value")) self.app.navigation.open_home() i = 0 for c_id in edit_links: phones = c_all_phones[i] emails = c_all_emails[i] address = c_address[i] self.contact_cache.append(Contact(id=c_id, firstname=c_firstnames[i], lastname=c_lastnames[i], all_phones_from_home_page=phones, all_emails=emails, address=address)) i = i + 1 return list(self.contact_cache)
def test_mod_contact(app, db, check_ui): if len(db.get_contacts_list()) == 0: app.contact.create( Contact("Precond name", "Precond last", "Precon address", " Precond notes notes notes")) old_contacts = db.get_contacts_list() contact = Contact(" " + str(datetime.now()) + " ", "" + str(datetime.now()) + " ", "" + str(datetime.now()) + " " + " ", " " + str(datetime.now())) modyfied_contact = random.choice(old_contacts) app.contact.modify_by_id(modyfied_contact.id, contact) new_contacts = db.get_contacts_list() old_contacts.remove(modyfied_contact) contact.set_id(modyfied_contact.id) old_contacts.append(contact) 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_contacs_list(), key=Contact.id_or_max)
def get_contact_info_from_view_page(self, index): wd = self.app.wd self.open_contact_view_by_index(index) text = wd.find_element_by_css_selector("div#content").text homephone = re.findall("H: (.*)", text) mobilephone = re.findall("M: (.*)", text) workphone = re.findall("W: (.*)", text) # faxphone = re.findall("F: (.*)", text) email_1 = wd.find_element_by_css_selector("a[href^='mailto']") allphones = homephone + mobilephone + workphone return Contact(all_phones_from_home_page="\n".join([str(elem) for elem in allphones]), email_1=email_1)
def test_del_some_contact(app, db, check_ui): if len(db.get_contacts_list()) == 0: app.contact.create( Contact("Precond name", "Precond last", "Precon address", "00000", " Precond notes notes notes")) old_contacts = db.get_contacts_list() contact = random.choice(old_contacts) app.contact.delete_by_id(contact.id) old_contacts.remove(contact) # after added refresh value ddepracated in database is changed app.navigation.open_home() new_contacts = db.get_contacts_list() assert old_contacts == new_contacts if check_ui: assert sorted(new_contacts, key=Contact.id_or_max) == sorted(app.contact.get_contacs_list(), key=Contact.id_or_max)
def test_data_home_edit_sites(app, db): if len(db.get_contacts_list()) == 0: app.contact.create( Contact("Precond name", "Precond last", "Precon address", "00000", " Precond notes notes notes")) index = len(db.get_contacts_list()) contact_from_home_page = app.contact.get_contacs_list()[random.randint( 0, index - 1)] contact_from_edit_page = app.contact.get_contact_info_from_edit_page( contact_from_home_page.id) # test all phones in file: test_phones.py assert contact_from_home_page.all_emails == merge_emails_like_on_home_page( contact_from_edit_page) # main page cut more than one space " " assert clear_h(contact_from_home_page.address) == clear_h( contact_from_edit_page.address) assert contact_from_home_page.firstname == contact_from_edit_page.firstname assert contact_from_home_page.lastname == contact_from_edit_page.lastname
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.open_contact_edit_by_index(index) id = wd.find_element_by_css_selector("input[name=id]").get_attribute("value") first_name = wd.find_element_by_css_selector("input[name=firstname]").get_attribute("value") last_name = wd.find_element_by_css_selector("input[name=lastname]").get_attribute("value") home_phone = wd.find_element_by_css_selector("input[name=home]").get_attribute("value") mobile_phone = wd.find_element_by_css_selector("input[name=mobile]").get_attribute("value") work_phone = wd.find_element_by_css_selector("input[name=work]").get_attribute("value") email_1 = wd.find_element_by_css_selector("input[name=email]").get_attribute("value") email_2 = wd.find_element_by_css_selector("input[name=email2]").get_attribute("value") email_3 = wd.find_element_by_css_selector("input[name=email3]").get_attribute("value") address = wd.find_element_by_css_selector("textarea[name=address]").get_attribute("value") notes = wd.find_element_by_css_selector("textarea[name=notes]").get_attribute("value") fax_phone = wd.find_element_by_css_selector("input[name=fax]").get_attribute("value") return Contact(id=id, firstname=first_name, lastname=last_name, homephone=home_phone, mobilephone=mobile_phone, workphone=work_phone, email_1=email_1, email_2=email_2, email_3=email_3, address=address, notes=notes)
def add(name, last_name, image_url, address, phone_number, email): """ Add a contact given all its information. :param name: Contact name. :param last_name: Contact last name. :param image_url: Image URL. :param address: Postal address. :param phone_number: Phone number. :param email: Email address. :return: Identifier of the contact added. """ contact = Contact(name=name, last_name=last_name, image_url=image_url, address=address, phone_number=phone_number, email=email) db_session().add(contact) db_session().commit() contact_id = contact.id return contact_id
def get_last_added_contact(self): contacts = [] cursor = self.connection.cursor() try: cursor.execute( "SELECT id, firstname, lastname, address, home, mobile, work, email, notes FROM addressbook where deprecated = '0000-00-00 00:00:00' ORDER BY created DESC LIMIT 1" ) for row in cursor: (id, firstname, lastname, address, home, mobile, work, email, notes) = row contacts.append( Contact(id=str(id), firstname=firstname, lastname=lastname, address=address, homephone=home, mobilephone=mobile, workphone=work, email_1=email, notes=notes)) finally: cursor.close() return contacts[0]
def clean(contact): return Contact(id=contact.id, firstname=contact.firstname.strip())
sys.exit(2) n = 2 f = "data/contacts.json" for o, a in opts: if o == "-n": n = int(a) elif o == "-f": f = a else: assert False, "unhandled option" 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_data = [ Contact(firstname=random_string("name", 10), lastname=random_string("name", 10), homephone="1+1+1 1", mobilephone="2-2-2 2", workphone="(3(3)3) 3", address=random_string("adress", 30), notes=random_string("notes", 50)) 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_data))
from src.model.contact import Contact testdata = [ Contact(firstname="firstname1", lastname="lastname1", homephone="1+1+1 1", mobilephone="2-2-2 2", workphone="(3(3)3) 3", address="adress", notes="notes"), Contact(firstname="?firstname2*", lastname="=lastname2&", homephone="1+1+1 1", mobilephone="2-2-2 2", workphone="(3(3)3) 3", address="*adress?", notes="*notes/") ] # # 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_data= [ # Contact(firstname=random_string("name", 10), lastname=random_string("name", 10), homephone="1+1+1 1", mobilephone="2-2-2 2", # workphone="(3(3)3) 3", address=random_string("adress", 30), notes=random_string("notes", 50)) # for i in range(3)]
def convert(contact): return Contact(id=contact.id, firstname=contact.firstname, lastname=contact.lastname)