def get_contact_info_from_edit_page(self, index): self.open_contact_for_edit_by_index(index) wd = self.app.wd firstname = wd.find_element_by_name('firstname').get_attribute('value') lastname = wd.find_element_by_name('lastname').get_attribute('value') address = wd.find_element_by_name('address').get_attribute('value') id = wd.find_element_by_name('id').get_attribute('value') phone = wd.find_element_by_name('home').get_attribute('value') work_phone = wd.find_element_by_name('work').get_attribute('value') mobile = wd.find_element_by_name('mobile').get_attribute('value') secondary_phone = 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') return Contact(name=firstname, last_name=lastname, contact_id=id, phone=phone, work_phone=work_phone, mobile=mobile, secondary_phone=secondary_phone, email=email1, email2=email2, email3=email3, address=address)
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.open_home() self.contact_cache = [] for element in wd.find_elements_by_name('entry'): texts = element.find_elements_by_tag_name('td') contact_id = texts[0].find_element_by_tag_name( 'input').get_attribute('value') last_name = texts[1].text name = texts[2].text all_phones = texts[5].text email_elements = texts[4].find_elements_by_css_selector('a') all_emails = [] for email in email_elements: all_emails.append(email.text) address = texts[3].text self.contact_cache.append( Contact(name=name, last_name=last_name, contact_id=contact_id, all_phones_from_homepage=all_phones, all_emails=' '.join(all_emails), address=address)) return list(self.contact_cache)
def get_contact_info_from_view_page(self, index): self.open_contact_view_by_index(index) wd = self.app.wd text = wd.find_element_by_id('content').text phone = re.search("H: (.*)", text).group(1) work_phone = re.search("W: (.*)", text).group(1) mobile = re.search("M: (.*)", text).group(1) secondary_phone = re.search("P: (.*)", text).group(1) return Contact(phone=phone, work_phone=work_phone, mobile=mobile, secondary_phone=secondary_phone)
def test_modify_contact_name(app, db, check_ui): if app.contact.count() == 0: app.contact.create(Contact(name=random_string('new ', 10))) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) edited_contact = Contact(name=random_string('edited ', 10), last_name=contact.last_name, contact_id=contact.contact_id) app.contact.edit_contact_by_id(contact.contact_id, edited_contact) new_contacts = db.get_contact_list() old_contacts.remove(contact) old_contacts.append(edited_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_contact_list(), key=Contact.id_or_max)
def add_contact(address_book_id): session = Session() address_book = session.query(AddressBook) \ .filter(AddressBook.id == address_book_id) \ .first() contact = Contact( request.form.get('name'), datetime.strptime(request.form.get('birthday'), '%Y-%m-%d').date() ) address_book.contacts.append(contact) session.commit() return redirect('/addressBooks/{}'.format(address_book_id))
def test_populate_database(self): # Stranger Things jane_hopper_contact = Contact('Jane Hopper', datetime.date(1990, 3, 22)) jane_hopper_contact.addresses = [ Address('Hawkins, Indiana, USA', AddressType.HOME), Address('Atlanta, Georgia, USA', AddressType.WORK) ] jane_hopper_contact.telephones = [ Telephone('92467-0501', TelephoneType.MOBILE), Telephone('33455-0123', TelephoneType.LANDLINE) ] dustin_henderson_contact = Contact('Dustin Henderson', datetime.date(1991, 4, 12)) dustin_henderson_contact.addresses = [ Address('Hawkins, Indiana, USA', AddressType.HOME), Address('Atlanta, Georgia, USA', AddressType.WORK) ] dustin_henderson_contact.telephones = [ Telephone('5653-1241', TelephoneType.LANDLINE), Telephone('88874-121', TelephoneType.MOBILE) ] stranger_things_address_book = AddressBook('Stranger Things') stranger_things_address_book.owner = Owner('Will Byers') stranger_things_address_book.contacts = [ jane_hopper_contact, dustin_henderson_contact ] # Back to the Future marty_mcfly_contact = Contact('Marty McFly', datetime.date(1968, 6, 12)) marty_mcfly_contact.addresses = [ Address('Hill Valley, California, USA', AddressType.HOME), Address('Olympic Theater, Los Angeles, USA', AddressType.WORK) ] marty_mcfly_contact.telephones = [ Telephone('36474-2313', TelephoneType.MOBILE), Telephone('82135-0602', TelephoneType.LANDLINE) ] jennifer_parker_contact = Contact('Jennifer Parker', datetime.date(1965, 5, 10)) jennifer_parker_contact.addresses = [ Address('Hill Valley, California, USA', AddressType.HOME), Address('Olympic Theater, Los Angeles, USA', AddressType.WORK) ] jennifer_parker_contact.telephones = [ Telephone('7345-0506', TelephoneType.MOBILE), Telephone('3344-1286', TelephoneType.LANDLINE) ] back_to_the_future_address_book = AddressBook('Back to the Future') back_to_the_future_address_book.owner = Owner('Emmett Brown') back_to_the_future_address_book.contacts = [ marty_mcfly_contact, jennifer_parker_contact ] Session = sessionmaker(bind=self.engine) session = Session() session.add(stranger_things_address_book) session.add(back_to_the_future_address_book) session.commit() session.close()
n = 5 f = 'data/contacts.json' for o, a in opts: if o == '-n': n = int(a) elif o == '-f': f = a test_data = [ Contact(name="", sec_name="", last_name="", nickname="", company="", phone="", mobile="", work_phone="", secondary_phone="", email="") ] + [ Contact(name=random_string('', 10), sec_name=random_string('', 10), last_name=random_string('', 20), nickname=random_string('', 15), company=random_string('', 25), address=random_string('', 100), phone=random_phone(), mobile=random_phone(), work_phone=random_phone(), secondary_phone=random_phone(),