def test_add_contact_in_group(app):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test_for_add_contact_in_group"))
    if len(db.get_contact_list()) == 0 or len(
            db.create_contactid_list_from_contacts_not_in_group()) == 0:
        app.contact.add_new_contact(
            Contact(first_name="Test",
                    last_name="add contact in group",
                    email="*****@*****.**"))
    group_id = db.create_groupid_list()[0]
    contact_id = db.create_contactid_list_from_contacts_not_in_group()[0]
    app.contact.add_contact_in_group(contact_id, group_id)
    assert len(db.get_contacts_in_group(Group(id=group_id))) > 0
    assert contact_id in db.create_contactid_list_contacts_in_group(
        Group(id=group_id))
def test_add_contact_to_group(app, json_contacts, json_groups):
    groups_container = json_groups
    if len(db.get_group_list()) == 0:
        app.group.create(groups_container)
    groups_n = random.choice(db.get_group_list())
    contacts_container = json_contacts
    if len(db.get_contact_list()) == 0 or len(
            db.get_contacts_not_in_group(Group(id='%s' % groups_n.id))) == 0:
        app.contacts.add(contacts_container)
    list_contacts = db.get_contacts_in_group(Group(id='%s' % groups_n.id))
    contact = random.choice(
        db.get_contacts_not_in_group(Group(id='%s' % groups_n.id)))
    app.contacts.add_to_group(contact.id, groups_n.id)
    list_contacts.append(contact)
    new_list_contacts = db.get_contacts_in_group(Group(id='%s' % groups_n.id))
    assert sorted(list_contacts,
                  key=Contacts.id_or_max) == sorted(new_list_contacts,
                                                    key=Contacts.id_or_max)
示例#3
0
def test_add_random_contact_to_random_group(app):
    orm = ORMFixture(host="127.0.0.1",
                     name="addressbook",
                     user="******",
                     password="")
    groups = orm.get_group_list()
    contacts = orm.get_contact_list()
    if len(contacts) == 0:
        app.contact.create((Contact(firstname="firstname",
                                    middlename="middlename",
                                    lastname="lastname",
                                    nickname="nickname",
                                    title="title",
                                    company="company",
                                    address="address",
                                    homephone="home",
                                    mobilephone="mobile",
                                    workphone="work",
                                    fax="fax",
                                    email="email",
                                    homepage="homepage",
                                    address2="address2",
                                    secondaryphone="phone2",
                                    notes="notes")))
    if len(groups) == 0:
        app.group.create(Group(name="test"))
    app.contact.open_contact_list_page()
    # get random id contact and group
    contact = random.choice(contacts)
    contact_id = contact.id
    group = random.choice(groups)
    group_name = group.name
    group_id = group.id
    # add contact to random group
    old_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id))
    app.contact.add_contact_to_group(contact_id, group_name)
    # verified contact in group
    new_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id))
    if len(old_contacts_in_groups) == len(new_contacts_in_groups):
        print("Contact wasnt' added, randomly choosed same group")
    else:
        assert len(old_contacts_in_groups) + 1 == len(new_contacts_in_groups)
        for contact_in_group in new_contacts_in_groups:
            assert (contact_in_group.id == contact_id)
示例#4
0
def test_del_contact_from_group(app,json_contacts,json_groups):
     groups_container = json_groups
     contact_container = json_contacts
     if len(db.get_group_list()) == 0:
         app.group.create(groups_container)
     if len (db.get_contact_list())==0:
         app.contacts.add(contact_container)
     groups_random = random.choice(db.get_group_list())
     if len(db.get_contacts_in_group(Group(id='%s' % groups_random.id)))==0:
         app.open_home_page()
         empty_contact = random.choice(db.get_contacts_not_in_group(Group(id='%s' % groups_random.id)))
         app.contacts.add_to_group(empty_contact.id, groups_random.id)
     app.contacts.select_group_for_contact_deletion_by_id(groups_random.id)
     list_contacts = db.get_contacts_in_group(Group(id='%s' % groups_random.id))
     contact_s = random.choice(db.get_contacts_in_group(Group(id='%s' % groups_random.id)))
     app.contacts.del_from_group_by_id(contact_s.id)
     list_contacts.remove(contact_s)
     new_list_contacts = db.get_contacts_in_group(Group(id='%s' % groups_random.id))
     assert list_contacts == new_list_contacts
def test_add_contacts_to_group(app, orm):
    with pytest.allure.step('Given a non-empty contact list'):
        if len(orm.get_contact_list()) == 0:
            app.contact.add_new(contact1)
    with pytest.allure.step('Given a non-empty group list'):
        if len(orm.get_group_list()) == 0:
            app.group.create(Group(name="addbeforedel", header="", footer=""))
    # выбираем контакт, который будем добавлять
    with pytest.allure.step('Get a random contact from the contact list'):
        contact_list_fm_db = orm.get_contact_list()
        contact_for_add = random.choice(contact_list_fm_db)
    # составляем список групп, в которых нет этого контакта
    with pytest.allure.step(
            'Get a non-empty group list without the contact %s' %
            contact_for_add):
        group_list_fm_db = orm.get_group_list()
        group_list_without_contact_for_add = []
        for gr in group_list_fm_db:
            if contact_for_add not in orm.get_contacts_in_group(gr):
                group_list_without_contact_for_add.append(gr)
    #print(group_list_without_contact_for_add)
    #print(contact_for_add)
# проверяем список групп, в которых нет выбранного контакта
# и выбираем группу, в которую будем его добавлять
    with pytest.allure.step('Get a random group without the contact'):
        if len(group_list_without_contact_for_add) == 0:
            # если групп без этого контакта нет, выбираем группу из общего списка и удаляем из нее контакт
            group_to_add = random.choice(group_list_fm_db)
            app.contact.del_contact_fm_group_by_id(group_to_add.id,
                                                   contact_for_add.id)
            #print("группа выбрана из общего списка групп")
        else:
            # если такие группы есть, выбираем группу из списка групп, в которых нет контакта
            group_to_add = random.choice(group_list_without_contact_for_add)
            #print("группа выбрана из списка групп, в которых нет контакта")
    # получаем список контактов для группы group_to_add
    with pytest.allure.step('Get contact list for the group %s' %
                            group_to_add):
        cont_in_gr = orm.get_contacts_in_group(group_to_add)
        # проверяем, что в группе нет контакта
        assert contact_for_add not in cont_in_gr
    # контакт добавляем в группу
    with pytest.allure.step('Add contact %s to the group %s' %
                            (contact_for_add, group_to_add)):
        app.contact.add_contact_to_group_by_id(contact_for_add.id,
                                               group_to_add.id)
    # получаем новый список контактов для группы group_to_add
    with pytest.allure.step('Assert that contact added to the group'):
        cont_in_gr = orm.get_contacts_in_group(group_to_add)
        assert contact_for_add in cont_in_gr
示例#6
0
def test_del_group(app):
    group = Group(name='test1')
    old_list = app.groups.get_group_list()
    if len(old_list) == 0:
        app.groups.add_new_group(group)
        old_list = app.groups.get_group_list()
    elif old_list.count(group) == 0:
        app.groups.add_new_group(group)
        old_list = app.groups.get_group_list()
    app.groups.del_first_group_with_name(group)
    new_list = app.groups.get_group_list()
    old_list.remove(group)
    assert sorted(old_list,
                  key=Group.sorted_by_name) == sorted(new_list,
                                                      key=Group.sorted_by_name)
def test_add_contact_to_group(app):
    orm = ORMFixture(host="127.0.0.1",
                     name="addressbook",
                     user="******",
                     password="")
    # Check for available contacts and groups
    if len(orm.get_contact_list()) == 0:
        app.contact.create(
            Contact(firstname="Fname",
                    middlename="Mname",
                    lastname="Lname",
                    nickname="Nick",
                    title="TestTitle",
                    company="TestCompany",
                    address="TestAddress",
                    homephone="1111111",
                    mobilephone="2222222",
                    workphone="3333333",
                    fax="fax",
                    email="*****@*****.**",
                    email2="*****@*****.**",
                    email3="*****@*****.**",
                    homepage="homepage",
                    birth="1980",
                    secondaryaddress="TestAddress2",
                    secondaryphone="4444444"))
    if len(orm.get_group_list()) == 0:
        app.group.create(
            Group(name="test_name", header="test_header",
                  footer="test_footer"))
    # Selection of random group and contact
    contact = random.choice(orm.get_contact_list())
    group = random.choice(orm.get_group_list())
    old_contacts_in_group = orm.get_contacts_in_group(group)
    # Adding of contact to group
    app.contact.add_contact_to_group(contact.id, group.name)
    new_contacts_in_group = orm.get_contacts_in_group(group)
    if len(old_contacts_in_group) == len(new_contacts_in_group):
        print(
            "\n",
            "Same group was chosen for the selected contact, please retry or create more groups"
        )
    else:
        assert len(old_contacts_in_group) + 1 == len(new_contacts_in_group)
        for contact_in_group in new_contacts_in_group:
            assert (contact_in_group.id == contact.id)
            print("\n", "Contact", contact.firstname,
                  "was successfully added to group", group.name)
示例#8
0
def test_del_contacts_from_group(app, orm):
    with pytest.allure.step('Given a non-empty contact list'):
        if len(orm.get_contact_list()) == 0:  # контакты есть
            app.contact.add_new(contact1)
    with pytest.allure.step('Given a non-empty group list'):
        if len(orm.get_group_list()) == 0:  # группы есть
            app.group.create(Group(name="addbeforedel", header="", footer=""))
    with pytest.allure.step('Get db group list'):
        group_list_fm_db = orm.get_group_list()
    with pytest.allure.step('Get random group'):
        group_to_del_cont = random.choice(group_list_fm_db)
    with pytest.allure.step('Get non-empty contact list from group %s' %
                            group_to_del_cont):
        cont_in_gr = orm.get_contacts_in_group(group_to_del_cont)
        # если в выбранной группе нет контактов, добавляем туда контакт (что бы было что удалить)
        if len(cont_in_gr) == 0:
            contact_list_fm_db = orm.get_contact_list()
            contact_for_add = random.choice(contact_list_fm_db)
            app.contact.add_contact_to_group_by_id(contact_for_add.id,
                                                   group_to_del_cont.id)
            cont_in_gr = orm.get_contacts_in_group(group_to_del_cont)
#предусловия соблюдены (есть откуда и что удалять), можно удалять
#выбираем контакт из уже выбранной группы
    with pytest.allure.step('Get random contact from list'):
        cont_to_del = random.choice(cont_in_gr)
        #print(cont_to_del," - ",cont_to_del.id)
        #print(group_to_del_cont," - ",group_to_del_cont.id)
        assert cont_to_del in orm.get_contacts_in_group(group_to_del_cont)
    # метод по удалению котакта по id группы и id контакта
    with pytest.allure.step('Remove contact %s from group %s' %
                            (cont_to_del, group_to_del_cont)):
        app.contact.del_contact_fm_group_by_id(group_to_del_cont.id,
                                               cont_to_del.id)
    with pytest.allure.step(
            'Check contact list of the group that no removed contact'):
        assert cont_to_del not in orm.get_contacts_in_group(group_to_del_cont)
 def clean(group_cl):
     return Group(id=group_cl.id, name=group_cl.name.strip())
def group_for_modify(name, header, footer, random_group):
    return Group(name=name, header=header, footer=footer, id=random_group.id)
def non_empty_group_list(db, app):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="New_group"))
    return db.get_group_list()
def new_group(name, header, footer):
    return Group(name=name, header=header, footer=footer)
from fixture.ORM import ORMfixture
from fixture.group import Group

db = ORMfixture(host='127.0.0.1', name='addressbook', user='******', password='')

try:
    l = db.get_groups_with_contacts(Group(id='192'))
    # cursor.execute("select * from group_list")
    for item in l:
        print(item)
    print(len(l))
finally:
    pass
示例#14
0
 def convert(group):
     return Group(id=str(group.id), name=group.name, header=group.header, footer=group.footer)
from fixture.db import DbFixture
from fixture.orm import ORMFixture
from fixture.group import Group

# db1 = DbFixture(host="127.0.0.1", name="addressbook", user="******", password="")
#
# try:
#     contacts = db1.get_contact_list()
#     for contact in contacts:
#         print(contact)
#     print(len(contacts))
# finally:
#     db1.destroy()

db2 = ORMFixture(host="127.0.0.1",
                 name="addressbook",
                 user="******",
                 password="")

try:
    l = db2.get_contacts_in_group(Group(id="332"))
    for item in l:
        print(item)
    print(len(l))
finally:
    pass
示例#16
0
def test_del_random_contact_from_group(app, db):
    orm = ORMFixture(host="127.0.0.1",
                     name="addressbook",
                     user="******",
                     password="")
    groups = orm.get_group_list()
    contacts = orm.get_contact_list()
    if len(contacts) == 0:
        app.contact.create((Contact(firstname="firstname",
                                    middlename="middlename",
                                    lastname="lastname",
                                    nickname="nickname",
                                    title="title",
                                    company="company",
                                    address="address",
                                    homephone="home",
                                    mobilephone="mobile",
                                    workphone="work",
                                    fax="fax",
                                    email="email",
                                    homepage="homepage",
                                    address2="address2",
                                    secondaryphone="phone2",
                                    notes="notes")))
    if len(groups) == 0:
        app.group.create(Group(name="test"))
    app.contact.open_contact_list_page()
    # check contacts in group presence
    contacts_in_group = db.get_all_contacts_in_group()
    if len(contacts_in_group) == 0:
        # add contact in group
        contact = random.choice(contacts)
        contact_id = contact.id
        group = random.choice(groups)
        group_name = group.name
        group_id = group.id
        # add contact to random group
        old_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id))
        app.contact.add_contact_to_group(contact_id, group_name)
        # verified contact in group
        new_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id))
        if len(old_contacts_in_groups) == len(new_contacts_in_groups):
            print("Contact wasnt' added, randomly choosed same group")
        else:
            assert len(old_contacts_in_groups) + 1 == len(
                new_contacts_in_groups)
            for contact_in_group in new_contacts_in_groups:
                assert (contact_in_group.id == contact_id)

    # delete random contact from group
    contacts_in_group = db.get_all_contacts_in_group()
    contact_in_group = random.choice(contacts_in_group)
    contact_id = contact_in_group.id
    group_id = contact_in_group.group_id
    # get group name
    group_name = None
    for g in groups:
        if str(g.id) == str(group_id):
            group_name = g.name
    if group_name == None:
        raise ValueError("Can't find group_id")
    print("-------> " + str(group_name))
    app.contact.delete_contact_from_group(contact_id, group_name)
    contacts_in_groups_after_deletion = db.get_all_contacts_in_group()
    assert len(contacts_in_group) - 1 == len(contacts_in_groups_after_deletion)