コード例 #1
0
def test_edit_contact(app, db, check_ui):
    if len(db.get_contact_list()) == 0:
        app.contact.create(
            ContactAdd("Контакт для теста", "Petrov", "Petrov2", "Petr",
                       "title test", "cjmpany222", "Svobod1", "348758937",
                       "234234324", "34534534", "345345345", "*****@*****.**",
                       "*****@*****.**", "*****@*****.**", "jhjhj.re", "11",
                       "September", "1990", "11", "March", "2000", "flhrtccx",
                       "Ferabd,2", "ytn"))
    old_contact = db.get_contact_list()
    contact = ContactAdd("Редактирование", "Petrov", "Petrov2", "Petr",
                         "title test", "cjmpany222", "Svobod1", "348758937",
                         "234234324", "34534534", "345345345",
                         "*****@*****.**", "*****@*****.**", "*****@*****.**",
                         "jhjhj.re", "11", "September", "1990", "11", "March",
                         "2000", "flhrtccx", "Ferabd,2", "ytn")
    contact_old = random.choice(old_contact)
    contact.id = contact_old.id
    app.contact.edit_contact_by_id(contact, int(contact.id))
    new_contact = db.get_contact_list()
    old_contact[old_contact.index(contact_old)] = contact
    assert sorted(old_contact,
                  key=ContactAdd.id_or_max) == sorted(new_contact,
                                                      key=ContactAdd.id_or_max)
    if check_ui:
        assert sorted(map(app.contact.clean_gap_from_contact, old_contact),
                      key=ContactAdd.id_or_max) == sorted(
                          app.contact.get_contact_list(),
                          key=ContactAdd.id_or_max)
コード例 #2
0
 def get_contact_info_from_edit_page(self, index):
     wd = self.app.wd
     self.open_contact_to_edit_by_index(0)
     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")
     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")
     secondphone = wd.find_element_by_name("phone2").get_attribute("value")
     address = wd.find_element_by_name("address").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 ContactAdd(firstname=firstname,
                       lastname=lastname,
                       id=id,
                       home=homephone,
                       work=workphone,
                       mobile=mobilephone,
                       phone2=secondphone,
                       address=address,
                       email=email,
                       email2=email2,
                       email3=email3)
コード例 #3
0
 def get_contact_list(self):
     if self.contact_cache is None:
         wd = self.app.wd
         self.app.open_home_page()
         self.contact_cache = []
         for element in wd.find_elements_by_css_selector(
                 'tr[name="entry"]'):
             text = element.find_element_by_css_selector(
                 "td:nth-child(2)").text
             text1 = element.find_element_by_css_selector(
                 "td:nth-child(3)").text
             id = element.find_element_by_name("selected[]").get_attribute(
                 'value')
             address = element.find_element_by_css_selector(
                 "td:nth-child(4)").text
             all_phones = element.find_element_by_css_selector(
                 "td:nth-child(6)").text
             all_email = element.find_element_by_css_selector(
                 "td:nth-child(5)").text
             self.contact_cache.append(
                 ContactAdd(firstname=text1,
                            lastname=text,
                            id=id,
                            address=address,
                            all_phones_from_home_page=all_phones,
                            all_email_from_home_page=all_email))
     return list(self.contact_cache)
コード例 #4
0
def test_add_contact_in_group(app, orm):
    if len(orm.get_group_list()) == 0:
        app.group.create(Group(name="тест test_add_contact_in_group"))
    if len(orm.get_contact_list()) == 0:
        app.contact.create(ContactAdd(firstname="новый контакт"))
    groups = orm.get_group_list()
    group = random.choice(groups)
    if not (orm.get_contacts_not_in_group(group)):
        app.contact.create(ContactAdd(firstname="новый контакт"))
    contact = random.choice(orm.get_contact_list())
    list_contacts_old = orm.get_contacts_in_group(group)
    while list_contacts_old.count(contact) > 0:
        contact = random.choice(orm.get_contact_list())
    app.commonDef.add_contact_in_group(contactIndex=contact.id,
                                       groupId=group.id)
    list_contacts_new = orm.get_contacts_in_group(group)
    list_contacts_old.append(contact)
    assert sorted(list_contacts_old,
                  key=ContactAdd.id_or_max) == sorted(list_contacts_new,
                                                      key=ContactAdd.id_or_max)
コード例 #5
0
 def get_contact_list_from_view_page(self, index):
     wd = self.app.wd
     self.open_contact_view_page_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)
     secondphone = re.search("P: (.*)", text).group(1)
     return ContactAdd(home=homephone,
                       work=workphone,
                       mobile=mobilephone,
                       phone2=secondphone)
コード例 #6
0
def test_delete_contact(app, db, check_ui):
    if len(db.get_contact_list()) == 0:
        app.contact.create(ContactAdd(firstname="Удаление контакта"))
    old_contact = db.get_contact_list()
    contact = random.choice(old_contact)
    app.contact.delete_contact_by_index(int(contact.id))
    new_contact = db.get_contact_list()
    old_contact.remove(contact)
    assert sorted(old_contact,
                  key=ContactAdd.id_or_max) == sorted(new_contact,
                                                      key=ContactAdd.id_or_max)
    if check_ui:
        assert sorted(map(app.contact.clean_gap_from_contact, old_contact),
                      key=ContactAdd.id_or_max) == sorted(
                          app.contact.get_contact_list(),
                          key=ContactAdd.id_or_max)
コード例 #7
0
def test_remove_contact_in_group(app, db, orm):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="Удаление контакта"))
    if len(db.get_contact_list()) == 0:
        app.contact.create(ContactAdd(firstname="Удаление контакта"))
    if len(db.get_group_id_with_contact()) == 0:
        group = random.choice(orm.get_group_list())
        contact_add = random.choice(orm.get_contact_list())
        app.commonDef.add_contact_in_group(contactIndex=contact_add.id, groupId=group.id)
        id_group = group.id
    else:
        id_group=random.choice(db.get_group_id_with_contact())[0]
    list_contacts_old = orm.get_contacts_in_group(Group(id=str(id_group)))
    contact = random.choice(list_contacts_old)
    app.commonDef.remove_contact_in_group(contactIndex=contact.id, groupId=id_group)
    list_contacts_new=orm.get_contacts_in_group(Group(id=str(id_group)))
    list_contacts_old.remove(contact)
    assert sorted(list_contacts_old, key=ContactAdd.id_or_max) == sorted(list_contacts_new, key=ContactAdd.id_or_max)
コード例 #8
0
 def clean_gap_from_contact(self, contact):
     return ContactAdd(id=contact.id,
                       firstname=contact.firstname.strip(),
                       lastname=contact.lastname.strip())
コード例 #9
0

def random_string_for_phone(maxlen):
    symbols = string.digits + "-" + "+" + "(" + ")"
    return "".join(
        [random.choice(symbols) for i in range(random.randrange(maxlen))])


def random_month():
    return random.choice([
        "January", "February", "March", "April", "May", "June", "July",
        "August", "September", "October", "November", "December"
    ])


testdata = [ContactAdd(firstname="", middlename="", lastname="")] + [
    ContactAdd(firstname=random_string_for_textarea("name", 5),
               middlename=random_string_for_textarea("", 5),
               lastname=random_string_for_textarea("lastname", 5),
               nickname=random_string_for_textarea("", 5),
               title=random_string_for_textarea("", 5),
               company=random_string_for_textarea("", 5),
               address=random_string_for_textarea("", 5),
               home=random_string_for_phone(9),
               mobile=random_string_for_phone(8),
               work=random_string_for_phone(8),
               fax=random_string_for_phone(5),
               email=random_string_for_textarea("email", 5),
               email2=random_string_for_textarea("email", 5),
               email3=random_string_for_textarea("email", 5),
               homepage=random_string_for_textarea("email", 5),