def test_add_contact_to_group(app, orm): if len(orm.get_contact_list()) == 0: app.contact.init_new_contact() app.contact.fill_contact_base_data(ContactBaseData(firstname="test")) app.contact.submit_contact() if len(orm.get_group_list()) == 0: app.group.create(Group(name="test")) # choose random contact and group for test contact_to_test = random.choice(orm.get_contact_list()) group_to_test = random.choice(orm.get_group_list()) old_contacts_in_group = orm.get_contacts_in_group(group_to_test) app.contact.add_contact_to_group(contact_to_test.id, group_to_test.id) # veryfication if the contact was already in the group was = False for contact in old_contacts_in_group: if contact == contact_to_test: was = True break else: was = False if was == False: old_contacts_in_group.append(contact_to_test) new_contacts_in_group = orm.get_contacts_in_group(group_to_test) assert sorted(old_contacts_in_group, key=ContactBaseData.id_or_max) == sorted( new_contacts_in_group, key=ContactBaseData.id_or_max)
def test_delete_contact_from_group(app, orm): # condition for lack of contacts or groups if len(orm.get_contact_list()) == 0: app.contact.init_new_contact() app.contact.fill_contact_base_data(ContactBaseData(firstname="test")) app.contact.submit_contact() if len(orm.get_group_list()) == 0: app.group.create(Group(name="test")) # veri=yfication and condition for lack of groups having any contacts groups = orm.get_group_list() groups_with_contacts = [] for group in groups: if len(orm.get_contacts_in_group(group)) > 0: groups_with_contacts.append(group) if len(groups_with_contacts) == 0: contact_to_add = random.choice(orm.get_contact_list()) group_to_add = random.choice(groups) app.contact.add_contact_to_group(contact_to_add.id, group_to_add.id) groups_with_contacts.append(group_to_add) # choosing group and contacts to delete group_to_test = random.choice(groups_with_contacts) contact_to_test = random.choice(orm.get_contacts_in_group(group_to_test)) old_contacts_in_group = orm.get_contacts_in_group(group_to_test) # deleting app.contact.delete_contact_from_group(contact_to_test.id, group_to_test.id) old_contacts_in_group.remove(contact_to_test) new_contacts_in_group = orm.get_contacts_in_group(group_to_test) assert sorted(old_contacts_in_group, key=ContactBaseData.id_or_max) == sorted( new_contacts_in_group, key=ContactBaseData.id_or_max)
def clean(contact): return ContactBaseData( id=contact.contactBaseData.id, firstname=adjustments.clear_multiple_spaces( contact.contactBaseData.firstname).strip(), lastname=adjustments.clear_multiple_spaces( contact.contactBaseData.lastname).strip())
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.init_by_index_contact_edition(index) id = wd.find_element_by_name('id').get_attribute('value') 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') 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') additionalphone = 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 ContactBaseData(firstname=firstname, lastname=lastname, id=id, homephone=homephone, workphone=workphone, mobilephone=mobilephone, additionalphone=additionalphone, email1=email1, email2=email2, email3=email3, address=address)
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_id('content').text if re.search('H:\s(.*)', text) is not None: homephone = re.search('H:\s(.*)', text).group(1) else: homephone = None if re.search('W:\s(.*)', text) is not None: workphone = re.search('W:\s(.*)', text).group(1) else: workphone = None if re.search('M:\s(.*)', text) is not None: mobilephone = re.search('M:\s(.*)', text).group(1) else: mobilephone = None if re.search('P:\s(.*)', text) is not None: additionalphone = re.search('P:\s(.*)', text).group(1) else: additionalphone = None # allEmails = wd.find_elements_by_xpath("//a[starts-with(@href, 'mailto:')]") allEmails = [] for i in range( 0, len( wd.find_elements_by_xpath( "//a[starts-with(@href, 'mailto:')]"))): allEmails.append( wd.find_elements_by_xpath("//a[starts-with(@href, 'mailto:')]") [i].text) return ContactBaseData(homephone=homephone, workphone=workphone, mobilephone=mobilephone, additionalphone=additionalphone, allEmailsFromHomePage=allEmails)
def test_del_contact_from_the_list(app, db, check_ui): if app.contact.count() == 0: app.contact.init_new_contact() app.contact.fill_contact_base_data(ContactBaseData(firstname="test")) app.contact.submit_contact() old_contacts = db.get_contact_list() contact_to_delete = random.choice(old_contacts) app.contact.delete_contact_by_id(contact_to_delete.contactBaseData.id) app.contact.open_main_page() new_contacts = db.get_contact_list() assert len(old_contacts) - 1 == len(new_contacts) old_contacts.remove(contact_to_delete) assert new_contacts == old_contacts if check_ui: def clean(contact): return ContactBaseData( id=contact.contactBaseData.id, firstname=adjustments.clear_multiple_spaces( contact.contactBaseData.firstname).strip(), lastname=adjustments.clear_multiple_spaces( contact.contactBaseData.lastname).strip()) clear_new_contacts = map(clean, new_contacts) assert sorted(clear_new_contacts, key=ContactBaseData.id_or_max) == sorted( app.contact.get_contact_list(), key=ContactBaseData.id_or_max)
def get_contact_list(self): wd = self.app.wd self.open_main_page() self.contact_cache = [] for row in wd.find_elements_by_name('entry'): cells = row.find_elements_by_tag_name('td') id = cells[0].find_element_by_tag_name('input').get_attribute( 'value') # . przed // oznacza relatywne użycie xpatha - jakby tworzyła nowy dom w ramach wiersza # text1 = element.find_element_by_xpath(".//td[2]").text # text2 = element.find_element_by_xpath(".//td[3]").text # lastName = row.find_element_by_css_selector('*>td:nth-of-type(2)').text # firstName = row.find_element_by_css_selector('*>td:nth-of-type(3)').text firstName = cells[2].text lastName = cells[1].text allPhones = cells[5].text allEmails = cells[4].text address = cells[3].text self.contact_cache.append( ContactBaseData(firstname=firstName, lastname=lastName, id=id, address=address, allPhonesFromHomePage=allPhones, allEmailsFromHomePage=allEmails)) return list(self.contact_cache)
def test_contact_on_the_home_page_from_edit_page(app): if app.contact.count() == 0: app.contact.init_new_contact() app.contact.fill_contact_base_data( ContactBaseData(firstname="Testowe Imie", lastname='Testowe-Nazwisko')) app.contact.fill_emails( Emails(email1='*****@*****.**', email3='*****@*****.**')) app.contact.fill_personal_data( PersonalData(address='ul. Wejhera 3/11/nGdansk 80-390')) app.contact.fill_phone_number( PhoneNumbers(home='(+48)888-558-147', work='dgdfh')) app.contact.fill_additional_data(AdditionalData(phone='*$@')) app.contact.submit_contact() contact_list = app.contact.get_contact_list() index = randrange(len(contact_list)) contactFromHomePage = app.contact.get_contact_list()[index] contactFromEditPage = app.contact.get_contact_info_from_edit_page(index) assert contactFromHomePage.lastname == adjustments.clear_multiple_spaces( contactFromEditPage.lastname).strip() assert contactFromHomePage.firstname == adjustments.clear_multiple_spaces( contactFromEditPage.firstname).strip() assert contactFromHomePage.address == adjustments.clear_multiple_spaces( contactFromEditPage.address).strip() assert contactFromHomePage.allEmailsFromHomePage == merge_emails_like_on_home_page( contactFromEditPage).strip() assert contactFromHomePage.allPhonesFromHomePage == merge_phones_like_on_home_page( contactFromEditPage).strip()
def test_contact_on_the_home_page_from_db(app, db): if app.contact.count() == 0: app.contact.init_new_contact() app.contact.fill_contact_base_data( ContactBaseData(firstname="Testowe Imie", lastname='Testowe-Nazwisko')) app.contact.fill_emails( Emails(email1='*****@*****.**', email3='*****@*****.**')) app.contact.fill_personal_data( PersonalData(address='ul. Wejhera 3/11/nGdansk 80-390')) app.contact.fill_phone_number( PhoneNumbers(home='(+48)888-558-147', work='dgdfh')) app.contact.fill_additional_data(AdditionalData(phone='*$@')) app.contact.submit_contact() contact_list_fromHomePage = app.contact.get_contact_list() contact_list_fromDB = db.get_contact_list() clear_contact_list_fromDB = map(clean, contact_list_fromDB) sorted_contact_list_fromHomePage = sorted(contact_list_fromHomePage, key=ContactBaseData.id_or_max) sorted_contact_list_fromDB = sorted(clear_contact_list_fromDB, key=ContactBaseData.id_or_max) assert sorted_contact_list_fromHomePage == sorted_contact_list_fromDB for contact in range(len(sorted_contact_list_fromDB)): assert sorted_contact_list_fromDB[contact].address == \ adjustments.clear_multiple_spaces(sorted_contact_list_fromHomePage[contact].address) assert merge_emails_like_on_home_page(sorted_contact_list_fromDB[contact]).strip() == \ sorted_contact_list_fromHomePage[contact].allEmailsFromHomePage assert merge_phones_like_on_home_page(sorted_contact_list_fromDB[contact]).strip() == \ sorted_contact_list_fromHomePage[contact].allPhonesFromHomePage
def convert(contact): return ContactBaseData(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname, address=contact.address, homephone=contact.homephone, mobilephone=contact.mobilephone, workphone=contact.workphone, email1=contact.email1, email2=contact.email2, email3=contact.email3)
def test_phones_on_home_page(app): if app.contact.count() == 0: app.contact.init_new_contact() app.contact.fill_contact_base_data(ContactBaseData(firstname="test")) app.contact.fill_phone_number( PhoneNumbers(home='(+48)888-558-147', work='dgdfh')) app.contact.fill_additional_data(AdditionalData(phone='*$@')) app.contact.submit_contact() contactFromHomePage = app.contact.get_contact_list()[0] contactFromEditPage = app.contact.get_contact_info_from_edit_page(0) assert contactFromHomePage.allPhonesFromHomePage == merge_phones_like_on_home_page( contactFromEditPage)
def test_emails_on_home_page(app): if app.contact.count() == 0: app.contact.init_new_contact() app.contact.fill_contact_base_data(ContactBaseData(firstname="test")) app.contact.fill_emails( Emails(email1='*****@*****.**', email3='*****@*****.**')) app.contact.submit_contact() contactFromHomePage = app.contact.get_contact_list()[0] contactFromEditPage = app.contact.get_contact_info_from_edit_page(0) assert contactFromHomePage.allEmailsFromHomePage == merge_emails_like_on_home_page( contactFromEditPage)
def clean(contact): return ContactBaseData( id=contact.contactBaseData.id, firstname=adjustments.clear_multiple_spaces( contact.contactBaseData.firstname).strip(), lastname=adjustments.clear_multiple_spaces( contact.contactBaseData.lastname).strip(), address=adjustments.clear_multiple_spaces( contact.contactBaseData.address).strip(), homephone=contact.contactBaseData.homephone, mobilephone=contact.contactBaseData.mobilephone, workphone=contact.contactBaseData.workphone, additionalphone=contact.contactBaseData.additionalphone, email1=contact.contactBaseData.email1.strip(), email2=contact.contactBaseData.email2.strip(), email3=contact.contactBaseData.email3.strip())
def get_contact_list(self): list = [] cursor = self.connection.cursor() # sprawdzić czy można zamiast poniższego użyć kontrukcji with try: cursor.execute( 'select id, firstname, lastname, address, home, mobile, work, phone2, email, email2, email3 from addressbook where deprecated="0000-00-00 00:00:00"' ) for row in cursor: (id, firstname, lastname, address, homephone, mobilephone, workphone, additionalphone, email1, email2, email3) = row contactBaseData = ContactBaseData( id=str(id), firstname=firstname, lastname=lastname, address=address, homephone=homephone, mobilephone=mobilephone, workphone=workphone, additionalphone=additionalphone, email1=email1, email2=email2, email3=email3) list.append( ContactAllData(contactBaseData=contactBaseData, personalData='', phoneNumbers='', emails='', www='', additionalData='', notes='', birthDate='', anniversaryDate='')) finally: cursor.close() return list
def random_day(): return random.randrange(1, 31) def random_month(): return random.randrange(1, 12) def random_year(): symbols = string.digits return ''.join([random.choice(symbols) for i in range(4)]) testData = [ContactAllData(contactBaseData=ContactBaseData(firstname=random_string(10), lastname=random_string(18)), personalData=PersonalData(middlename=random_string(10), nickname=random_string(10), title=random_string(10), company=random_string(20), address=random_string_with_new_line('Adres podstawowy: ', 30)), phoneNumbers=PhoneNumbers(home=random_phone_number(12), mobile=random_phone_number(16), work=random_phone_number(12), fax=random_phone_number(10)), emails=Emails(email1=random_email(8), email2=random_email(5), email3=random_email(6)), www=Www(www=random_www(30)), birthDate=BirthDate(day=random_day(), month=random_month(), year=random_year()), anniversaryDate=AnniversaryDate(day=random_day(), month=random_month(), year=random_year()), additionalData=AdditionalData(address=random_string_with_new_line('Adres dodatkowy: ', 30) , phone=random_phone_number(12)), notes=Notes(notes=random_string_with_new_line('n', 100))) for i in range(n)]\ + \ [ContactAllData(contactBaseData=ContactBaseData(firstname='', lastname=''),