def test_add_contact_to_group(app, db):
    # Get groups and contacts list, make sure they are not empty
    db_groups_list = db.get_db_groups_list()
    db_contacts_list = db.get_db_contacts_list()
    if not db_groups_list:
        app.group.create(GroupForm(group_name="AutocreatedGroup"))
        db_groups_list = db.get_db_groups_list()
    if not db_contacts_list:
        app.contact.create(ContactForm(contact_name="AutocreatedContact"))
        db_contacts_list = db.get_db_contacts_list()
    # Choose random group and contact
    group = random.choice(db_groups_list)
    contact = random.choice(db_contacts_list)
    # Check if the contact is not in the group. Options:
    # 1. The contact is not in the group - add it to the group.
    # 2. The contact is in the group - ok, choose another one, which is not in the group.
    # 3. All other contacts are also in the group, list db_contacts_not_in_group is empty - create contact and
    # add it to the group.
    db_contacts_in_group = orm.get_db_contacts_in_group(GroupForm(group_id=group.group_id))
    db_contacts_not_in_group = orm.get_db_contacts_not_in_group(GroupForm(group_id=group.group_id))
    if contact not in db_contacts_in_group:
        app.contact.add_contact_to_group(contact.contact_id, group.group_id)
    else:
        if db_contacts_not_in_group:
            contact = random.choice(db_contacts_not_in_group)
            app.contact.add_contact_to_group(contact.contact_id, group.group_id)
        else:
            if not db_contacts_not_in_group:
                contact = ContactForm(contact_name="AutocreatedContact")
                app.contact.create(contact)
                contact = db.get_db_contacts_list()[-1]
                app.contact.add_contact_to_group(contact.contact_id, group.group_id)
    # db - check the contact was added in the group
    db_contacts_in_group = orm.get_db_contacts_in_group(GroupForm(group_id=group.group_id))
    assert contact in db_contacts_in_group
Exemple #2
0
 def get_contact_info_from_edit_page(self, index):
     wd = self.app.wd
     self.open_contact_to_edit_by_index(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").text
     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")
     homephone = wd.find_element_by_name("home").get_attribute("value")
     mobile = wd.find_element_by_name("mobile").get_attribute("value")
     workphone = wd.find_element_by_name("work").get_attribute("value")
     secondary_phone = wd.find_element_by_name("phone2").get_attribute(
         "value")
     return ContactForm(contact_name=firstname,
                        contact_lastname=lastname,
                        contact_address=address,
                        contact_email=email,
                        contact_email2=email2,
                        contact_email3=email3,
                        contact_homephone=homephone,
                        contact_mobile=mobile,
                        contact_workphone=workphone,
                        contact_secondary_phone=secondary_phone,
                        contact_id=id)
Exemple #3
0
 def get_contacts_list(self):
     if self.contact_cache is None:
         wd = self.app.wd
         # Get list of contacts on home page
         self.navigate_to_home_page()
         self.contact_cache = []
         # Find rows in table
         for row in wd.find_elements_by_name("entry"):
             # Find cell in row
             cells = row.find_elements_by_tag_name("td")
             id = cells[0].find_element_by_name("selected[]").get_attribute(
                 "value")
             firstname = cells[2].text
             lastname = cells[1].text
             address = cells[3].text
             all_emails = cells[4].text
             all_phones = cells[5].text
             self.contact_cache.append(
                 ContactForm(contact_id=id,
                             contact_name=firstname,
                             contact_lastname=lastname,
                             contact_address=address,
                             all_emails_from_home_page=all_emails,
                             all_phones_from_home_page=all_phones))
     contacts_list = list(self.contact_cache)
     return contacts_list
Exemple #4
0
 def get_db_contacts_list(self):
     db_contacts_list = []
     cursor = self.connection.cursor()
     try:
         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.fetchall():
         #     print(row)
         for row in cursor:
             (id, firstname, lastname, address, home, mobile, work, email,
              email2, email3, phone2) = row
             db_contacts_list.append(
                 ContactForm(contact_id=str(id),
                             contact_name=firstname,
                             contact_lastname=lastname,
                             contact_address=address,
                             contact_homephone=home,
                             contact_mobile=mobile,
                             contact_workphone=work,
                             contact_email=email,
                             contact_email2=email2,
                             contact_email3=email3,
                             contact_secondary_phone=phone2))
     finally:
         cursor.close()
     return db_contacts_list
Exemple #5
0
def test_contact_info(app, db):
    # Check in DB if any contact exist, and if not - create one
    db_contacts_list = db.get_db_contacts_list()
    if not db_contacts_list:
        app.contact.create(ContactForm(contact_name="TestName", contact_lastname="TestLastName",
                                       contact_address="TestAddress", contact_email="TestEmail",
                                       contact_email2="TestEmail2", contact_email3="TestEmail3",
                                       contact_homephone="+14250000000", contact_mobile="+14250000001",
                                       contact_workphone="+14250000002", contact_secondary_phone="+14250000004"))
        db_contacts_list = db.get_db_contacts_list()
    # Get contacts from UI home page
    ui_contacts_list = app.contact.get_contacts_list()
    # Compare len of the lists
    assert len(db_contacts_list) == len(ui_contacts_list)
    # Sort and clear
    db_contacts_list = sorted([clear_object(x) for x in db_contacts_list], key=ContactForm.id_or_max)
    ui_contacts_list = sorted([clear_object(x) for x in ui_contacts_list], key=ContactForm.id_or_max)
    # Compare the lists
    for i in range(len(ui_contacts_list)):
        assert ui_contacts_list[i].contact_name == db_contacts_list[i].contact_name
        assert ui_contacts_list[i].contact_lastname == db_contacts_list[i].contact_lastname
        assert ui_contacts_list[i].contact_address == db_contacts_list[i].contact_address
        merged_phones = get_merged_contact_phones(db_contacts_list[i])
        merged_emails = get_merged_contact_emails(db_contacts_list[i])
        assert ui_contacts_list[i].all_phones_from_home_page == merged_phones
        assert ui_contacts_list[i].all_emails_from_home_page == merged_emails
Exemple #6
0
 def get_contact_phones_from_view_page(self, index):
     wd = self.app.wd
     self.open_contact_to_view_by_index(index)
     text = wd.find_element_by_id("content").text
     homephone = re.search("H: (.*)", text).group(1)
     mobile = re.search("M: (.*)", text).group(1)
     workphone = re.search("W: (.*)", text).group(1)
     secondary_phone = re.search("P: (.*)", text).group(1)
     return ContactForm(contact_homephone=homephone,
                        contact_mobile=mobile,
                        contact_workphone=workphone,
                        contact_secondary_phone=secondary_phone)
def test_mod_contact_name(app, db, check_ui):
    # Check if any contact exist, and if not - create one, insert name
    old_contacts_list = db.get_db_contacts_list()
    if not old_contacts_list:
        app.contact.create(ContactForm(contact_name="AutocreatedContact"))
        old_contacts_list = db.get_db_contacts_list()
    contact_selected = random.choice(old_contacts_list)
    contact = ContactForm(contact_name="TestModContactName1")
    # Ensure other parameters of the modified item will remain
    contact.contact_id = contact_selected.contact_id
    contact.contact_lastname = contact_selected.contact_lastname
    app.contact.mod_by_id(contact.contact_id, contact)
    new_contacts_list = db.get_db_contacts_list()
    # First check if contact was modified meaning len is the same
    assert len(old_contacts_list) == len(new_contacts_list)
    # Compare result in UI and DB
    if check_ui:
        sorted_db_new_contacts_list = sorted(
            [clear(x) for x in new_contacts_list], key=ContactForm.id_or_max)
        sorted_ui_new_contacts_list = sorted(
            [clear(x) for x in app.contact.get_contacts_list()],
            key=ContactForm.id_or_max)
        assert sorted_db_new_contacts_list == sorted_ui_new_contacts_list
def testdata_create_3_contacts(app):
    if app.contact.count() != 0:
        app.contact.del_all()
    contact_a_postfix = 1
    contact_b_postfix = int(contact_a_postfix)+1
    contact_c_postfix = int(contact_b_postfix)+1
    contact_a = ContactForm(contact_name=contact_a_postfix,
                            contact_lastname=contact_a_postfix,
                            contact_address=contact_a_postfix,
                            contact_email=contact_a_postfix,
                            contact_mobile=contact_a_postfix)
    contact_b = ContactForm(contact_name=contact_b_postfix,
                            contact_lastname=contact_b_postfix,
                            contact_address=contact_b_postfix,
                            contact_email=contact_b_postfix,
                            contact_mobile=contact_b_postfix)
    contact_c = ContactForm(contact_name=contact_c_postfix,
                            contact_lastname=contact_c_postfix,
                            contact_address=contact_c_postfix,
                            contact_email=contact_c_postfix,
                            contact_mobile=contact_c_postfix)
    app.contact.create(contact_a)
    app.contact.create(contact_b)
    app.contact.create(contact_c)
Exemple #9
0
def test_del_contact(app, db, check_ui):
    # Check if any contact exist, and if not - create one
    old_contacts_list = db.get_db_contacts_list()
    if not old_contacts_list:
        app.contact.create(ContactForm(contact_name="AutocreatedContact"))
        old_contacts_list = db.get_db_contacts_list()
    contact = random.choice(old_contacts_list)
    app.contact.del_by_id(contact.contact_id)
    new_contacts_list = db.get_db_contacts_list()
    # First check - if contact was deleted at all
    assert len(old_contacts_list) - 1 == len(new_contacts_list)
    # Second check - if remained contacts are equal
    old_contacts_list.remove(contact)
    assert old_contacts_list == new_contacts_list
    if check_ui:
        sorted_db_new_contacts_list = sorted([clear(x) for x in new_contacts_list], key=ContactForm.id_or_max)
        sorted_ui_new_contacts_list = sorted([clear(x) for x in app.contact.get_contacts_list()], key=ContactForm.id_or_max)
        assert sorted_db_new_contacts_list == sorted_ui_new_contacts_list
def test_remove_contact_from_group(app, db):
    # Make sure groups and contacts lists are not empty
    db_groups_list = db.get_db_groups_list()
    db_contacts_list = db.get_db_contacts_list()
    if not db_groups_list:
        app.group.create(GroupForm(group_name="AutocreatedGroup"))
        db_groups_list = db.get_db_groups_list()
    if not db_contacts_list:
        app.contact.create(ContactForm(contact_name="AutocreatedContact"))
        db_contacts_list = db.get_db_contacts_list()
    # Choose random group and contact
    group = random.choice(db_groups_list)
    contact = random.choice(db_contacts_list)
    # Make sure the contact is in the group
    db_contacts_in_group = orm.get_db_contacts_in_group(
        GroupForm(group_id=group.group_id))
    if contact not in db_contacts_in_group:
        app.contact.add_contact_to_group(contact.contact_id, group.group_id)
    # Remove the contact from the group
    app.contact.remove_contact_from_group(contact.contact_id, group.group_id)
    assert contact not in db_contacts_in_group
def test_contact_info(app):
    # Check if any contact exist, and if not - create one
    if app.contact.count() == 0:
        app.contact.create(
            ContactForm(contact_name="TestName",
                        contact_lastname="TestLastName",
                        contact_address="TestAddress",
                        contact_email="TestEmail",
                        contact_email2="TestEmail2",
                        contact_email3="TestEmail3",
                        contact_company="TestCompany",
                        contact_homephone="+14250000000",
                        contact_mobile="+14250000001",
                        contact_workphone="+14250000002",
                        contact_fax="+14250000003",
                        contact_secondary_phone="+14250000004"))
    # Choose random contact from contacts table
    contacts_table_list = app.contact.get_contacts_list()
    index = randrange(len(contacts_table_list))
    # Get contact info from contacts table
    contact_info_from_table = app.contact.get_contacts_list()[index]
    # Get contact info from Edit contact page
    contact_info_from_edit_page = app.contact.get_contact_info_from_edit_page(
        index)
    # Compare contact info from contacts table to those on Edit page, plus hidden id
    assert contact_info_from_table.contact_id == contact_info_from_edit_page.contact_id
    assert contact_info_from_table.contact_name == contact_info_from_edit_page.contact_name
    assert contact_info_from_table.contact_lastname == contact_info_from_edit_page.contact_lastname
    assert contact_info_from_table.contact_address == contact_info_from_edit_page.contact_address
    # Compare emails and phone numbers from contacts table with those in Edit page, merged
    all_emails_from_home_page = contact_info_from_table.all_emails_from_home_page
    all_phones_from_home_page = contact_info_from_table.all_phones_from_home_page
    all_emails_from_edit_page = merge_emails_like_on_home_page(
        contact_info_from_edit_page)
    all_phones_from_edit_page = merge_phones_like_on_home_page(
        contact_info_from_edit_page)
    assert all_emails_from_home_page == all_emails_from_edit_page
    assert all_phones_from_home_page == all_phones_from_edit_page
Exemple #12
0
 def convert_contact(contact):
     return ContactForm(contact_id=str(contact.contact_id),
                        contact_name=contact.contact_name, contact_lastname=contact.contact_lastname,
                        contact_homephone=contact.contact_homephone, contact_mobile=contact.contact_mobile,
                        contact_workphone=contact.contact_workphone, contact_email=contact.contact_email,
                        contact_secondary_phone=contact.contact_secondary_phone)
    symbols = string.ascii_letters + string.digits + " " * 10
    # Random choice of symbols, generated for cycle of random length, not higher than max length
    list_random_symbols = [
        random.choice(symbols) for i in range(random.randrange(maxlen))
    ]
    random_string_from_symbols_list = prefix + "".join(list_random_symbols)
    return random_string_from_symbols_list


def random_phone(prefix, maxlen):
    # Additional options: symbols = string.digits*10 + string.punctuation + " "*10
    symbols = string.digits * 10 + " " * 10
    list_random_symbols = [
        random.choice(symbols) for i in range(random.randrange(maxlen))
    ]
    random_string_from_symbols_list = prefix + "".join(list_random_symbols)
    return random_string_from_symbols_list


testdata = [
    ContactForm(contact_name=random_string("CN__", 10),
                contact_lastname=random_string("CLN__", 15),
                contact_email=random_string("CE__@", 20),
                contact_email2=random_string("CE2__@", 20),
                contact_homephone=random_phone("+", 15),
                contact_mobile=random_phone("+", 15),
                contact_workphone=random_phone("+", 15),
                contact_secondary_phone=random_phone("+", 15))
    for i in range(5)
]
from model.contact_form import ContactForm


testdata = [
    ContactForm(contact_name="CN__1", contact_lastname="CLN__1",
                contact_email="*****@*****.**", contact_email2="*****@*****.**",
                contact_homephone="+0(000)000-00-11", contact_mobile="+0(000)000-00-21",
                contact_workphone="+0(000)000-00-31", contact_secondary_phone="+0(000)000-00-41"),
    ContactForm(contact_name="CN__2", contact_lastname="CLN__2",
                contact_email="*****@*****.**", contact_email2="*****@*****.**",
                contact_homephone="+0(000)000-00-12", contact_mobile="+0(000)000-00-22",
                contact_workphone="+0(000)000-00-32", contact_secondary_phone="+0(000)000-00-42"),
    ContactForm(contact_name="CN__3", contact_lastname="CLN__3",
                contact_email="*****@*****.**", contact_email2="*****@*****.**",
                contact_homephone="+0(000)000-00-13", contact_mobile="+0(000)000-00-23",
                contact_workphone="+0(000)000-00-33", contact_secondary_phone="+0(000)000-00-43")
]