Ejemplo n.º 1
0
def test_modify_first_contact(app, db):

    if app.contact.count() == 0:
        app.contact.add_new_contact(
            Contact(firstname="tester", lastname="tester"))
    old_contacts = db.get_contact_list()
    old_contact = random.choice(old_contacts)
    contact = Contact(firstname="roman", lastname="erotoman")
    contact.id = old_contact.id
    app.contact.modify_contact_by_id(old_contact.id, contact)
    new_contacts = db.get_contact_list()
    assert sorted(old_contacts,
                  key=Contact.id_or_max) == sorted(new_contacts,
                                                   key=Contact.id_or_max)
Ejemplo n.º 2
0
 def get_contact_info_from_edit_page(self, index):
     wd = self.app.wd
     self.open_contact_to_edit_by_index(index)
     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")
     secondaryphone = wd.find_element_by_name("phone2").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")
     address = wd.find_element_by_name("address").get_attribute("value")
     return Contact(firstname=firstname,
                    lastname=lastname,
                    id=id,
                    homephone=homephone,
                    mobilephone=mobilephone,
                    workphone=workphone,
                    secondaryphone=secondaryphone,
                    email=email,
                    email2=email2,
                    email3=email3,
                    address=address)
Ejemplo n.º 3
0
def test_delete_random_contact(app, db):
    if app.contact.count() == 0:
        app.contact.add_new_contact(
            Contact(firstname="tester", lastname="tester"))
    old_contacts = db.get_contact_list()
    contact = random.choice(old_contacts)
    app.contact.delete_contact_by_id(contact.id)
    new_contacts = db.get_contact_list()
    old_contacts.remove(contact)
    assert old_contacts == new_contacts
Ejemplo n.º 4
0
 def get_contact_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)
     workphone = re.search("W: (.*)", text).group(1)
     mobilephone = re.search("M: (.*)", text).group(1)
     secondaryphone = re.search("P: (.*)", text).group(1)
     return Contact(homephone=homephone,
                    mobilephone=mobilephone,
                    workphone=workphone,
                    secondaryphone=secondaryphone)
Ejemplo n.º 5
0
def test_delete_random_contact(app):

    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    if len(db.get_contacts_in_group(group)) == 0:
        app.contact.add_contact_to_group(
            Contact(firstname="tester", lastname="tester"), group)
    old_contacts = db.get_contacts_in_group(group)
    removed_contacts = db.get_contacts_not_in_group(group)

    def rem_con(old_contacts):
        if old_contacts in removed_contacts:
            return True
        else:
            return False

    filter(rem_con, old_contacts)
    contact = random.choice(old_contacts)
    app.contact.delete_contact_by_id(contact.id)
    new_contacts = old_contacts.remove(contact)
    assert old_contacts == new_contacts
Ejemplo n.º 6
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 row in wd.find_elements_by_name("entry"):
                cells = row.find_elements_by_tag_name("td")
                firstname = cells[2].text
                lastname = cells[1].text
                id = cells[0].find_element_by_tag_name("input").get_attribute(
                    "value")
                all_phones = cells[5].text
                address = cells[3].text
                all_emails = cells[4].text
                self.contact_cache.append(
                    Contact(firstname=firstname,
                            lastname=lastname,
                            id=id,
                            all_phones_from_home_page=all_phones,
                            all_emails_from_home_page=all_emails,
                            address=address))

        return list(self.contact_cache)
Ejemplo n.º 7
0
 def get_contact_list(self):
     list = []
     cursor = self.connection.cursor()
     try:
         cursor.execute(
             "select id, firstname, lastname, address, home, mobile, work, phone2, email, email2  from addressbook where deprecated = '0000-00-00 00:00:00'"
         )
         for row in cursor:
             (id, firstname, lastname, address, home, mobile, work, phone2,
              email, email2) = row
             list.append(
                 Contact(firstname=firstname,
                         lastname=lastname,
                         id=str(id),
                         homephone=home,
                         mobilephone=mobile,
                         workphone=work,
                         secondaryphone=phone2,
                         email=email,
                         email2=email2,
                         address=address))
     finally:
         cursor.close()
     return list
Ejemplo n.º 8
0
def new_contact(firstname, lastname):
    return Contact(firstname=firstname, lastname=lastname)
Ejemplo n.º 9
0
def non_empty_contact_list(db, app):
    if len(db.get_contact_list()) == 0:
        app.contact.add_new_contact(
            Contact(firstname="some name", lastname="lastname"))
    return db.get_contact_list()
Ejemplo n.º 10
0
    getopt.usage()
    sys.exit(2)

n = 5
f = "data/contacts.json"

for o, a in opts:
    if o == "-n":
        n = int(a)
    elif o == "-f":
        f = a


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))])


testdata = [Contact(firstname="", lastname="", adress="")] + [
    Contact(firstname=random_string("firstname", 10),
            lastname=random_string("lastname", 20),
            adress=random_string("address", 20)) for i in range(5)
]

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(testdata))
Ejemplo n.º 11
0
 def convert(contact):
     return Contact(id=str(contact.id), firstname=contact.firstname, lastname=contact.lastname)
Ejemplo n.º 12
0
 def new_contact(self, firstname, lastname):
     return (Contact(firstname=firstname, lastname=lastname))