Beispiel #1
0
def test_add_contact_to_group(app, db):
    #if app.contact.count() == 0:
    # app.contact.add_new(ContactGroup(firstname="test9", lastname="Ivanov", nickname="goodman", company="TTY", address="Ekaterinburg", email="*****@*****.**", address2="Lenina str 5/7"))
    list_contacts = db.get_contact_list()
    list_groups = db.get_group_list()
    contact = random.choice(list_contacts)
    group = random.choice(list_groups)
    print(group)
    db = ORMFixture(host="127.0.0.1",
                    database="addressbook",
                    user="******",
                    password="")
    old_contacts_in_group = db.get_contacts_in_group(Group(id=group.id))
    app.contact.open_contacts_page()
    app.contact.select_contact_by_id(contact.id)
    app.contact.select_add_group_from_list(group.id)
    time.sleep(3)
    new_contacts_in_group = db.get_contacts_in_group(Group(id=group.id))
    for item in new_contacts_in_group:
        print(item)
    print(len(new_contacts_in_group))
    old_contacts_in_group.append(contact)
    assert sorted(old_contacts_in_group, key=ContactGroup.id_or_max) == sorted(
        new_contacts_in_group, key=ContactGroup.id_or_max)
    # now try to delete contact from group
    app.contact.open_contacts_page()
    app.contact.select_group_for_deletion(group.id)
    app.contact.select_contact_by_id(contact.id)
    app.contact.delete_contact_from_group()
    time.sleep(3)
    new_contacts_in_group = db.get_contacts_in_group(Group(id=group.id))
    old_contacts_in_group.remove(contact)
    assert sorted(old_contacts_in_group, key=ContactGroup.id_or_max) == sorted(
        new_contacts_in_group, key=ContactGroup.id_or_max)
def test_modify_some_group(app):
    if app.group.count() == 0:
        app.group.create(Group(name="test9", header="Python group", footer="comment"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(name="Modified name")
    group.id = old_groups[index].id
    app.group.modify_by_index(index, group)
    new_groups = app.group.get_group_list()
    assert len(old_groups) == len(new_groups)
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
def test_delete_rand_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group("oOo"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    app.group.delete_group_by_id(group.id)
    assert len(old_groups) - 1 == app.group.count()
    new_groups = db.get_group_list()
    old_groups.remove(group)
    assert old_groups == new_groups
    if check_ui:
        new_groups = map(lambda x: Group(id = x.id, name = x.name.strip()) , db.get_group_list())
        assert sorted(new_groups, key = Group.id_or_max) == sorted(app.group.get_group_list(), key = Group.id_or_max)
def test_modify_some_group_db(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test9", header="Python group", footer="comment"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    newdata = Group(name="Modified name")
    app.group.modify_by_id(group.id, newdata)
    new_groups = db.get_group_list()
    assert len(old_groups) == len(new_groups)
    print(old_groups)
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
    if check_ui:
        assert sorted(new_groups, key=Group.id_or_max) == sorted(app.group.get_group_list(), key=Group.id_or_max)
Beispiel #5
0
def test_add_contact_to_group(app,db, orm):
    if len(db.get_group_list()) == 0:
        app.group.create(Group("oOo"))
    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact("TIMMY"), Date("20", "March", "1990"), Date("20", "June", "2000"))
    contact = random.choice(db.get_contact_list())
    group = random.choice(db.get_group_list())
    app.contact.add_contact_in_group_by_id(contact.id,group.id)
    assert contact in orm.get_contacts_in_group(group = group)
def generate_groups_data(num_of_elms):
    testdata = [
        Group(random_string("name", 20), random_string("header", 20),
              random_string("footer", 20), None) for i in range(num_of_elms)
    ]
    file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                        "../data/groups.json")
    with open(file, "w") as f:
        f.write(jsonpickle.encode(testdata))
Beispiel #7
0
def test_edit_rand_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group("oOo"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    index = old_groups.index(group)
    new_value_group = Group(name="LOLO", id=group.id)
    app.group.edit_group_by_id(group.id, new_value_group)
    old_groups[index] = new_value_group
    new_groups = db.get_group_list()
    assert sorted(old_groups,
                  key=Group.id_or_max) == sorted(new_groups,
                                                 key=Group.id_or_max)
    if check_ui:
        new_groups = map(lambda x: Group(id=x.id, name=x.name.strip()),
                         db.get_group_list())
        assert sorted(new_groups, key=Group.id_or_max) == sorted(
            app.group.get_group_list(), key=Group.id_or_max)
 def get_groups_list(self):
     groups = list()
     entity_groups = list(
         select(g for g in DBHelper.ORMGroup
                if g.deprecated.date().year == 0))
     for group in entity_groups:
         groups.append(
             Group(group.name, group.header, group.footer, group.id))
     return groups
Beispiel #9
0
 def get_group_list(self):
     if self.group_cash is None:
         wd = self.app.wd
         self.open_groups_page()
         self.group_cash = []
         for element in wd.find_elements_by_css_selector("span.group"):
             text = element.text
             id = element.find_element_by_name("selected[]").get_attribute("value")
             self.group_cash.append(Group(name=text, id=id))
     return list(self.group_cash)
def test_add_defined_group(app):
    old_groups = app.group.get_group_list()
    group = Group(name="first test", header="python group", footer="Python")
    app.group.create(group)
    assert len(old_groups) + 1 == app.group.count()
    new_groups = app.group.get_group_list()
    old_groups.append(group)
    assert sorted(old_groups,
                  key=Group.id_or_max) == sorted(new_groups,
                                                 key=Group.id_or_max)
def test_add_contact_to_group(app):
    app.contacts.create_contact_if_not_exist(Contact("TestFirstName", "TestMiddleName", "TestLastName", None))
    app.groups.create_group_if_not_exist(Group("ToRemoveName", "ToRemoveHeader", "ToRemoveFooter", None))
    app.navigation.to_contacts()
    contact_id = app.contacts.select_contact_by_num_and_get_id(0)
    group_id = app.contacts.add_contact_to_group_by_index_and_get_group_id(0)
    list_ids = list()
    for elm in app.orm.get_contacts_in_groups_list(group_id):
        list_ids.append(elm.elm_id)
    assert int(contact_id) in list_ids
def test_modify_group(app, check_ui):
    app.groups.create_group_if_not_exist(
        Group("ToModifiedName", "ToModifiedHeader", "ToModifiedFooter", None))
    app.navigation.to_groups()
    if check_ui:
        old_groups = app.groups.get_groups()
    else:
        old_groups = app.orm.get_groups_list()
    index = get_random_index_from_list(old_groups)
    app.groups.select_group_by_num_on_page(index)
    modified_group = Group("ModifiedName", "ModifiedHeader", "ModifiedFooter",
                           None)
    app.groups.modify(modified_group)
    app.navigation.to_groups()
    if check_ui:
        new_groups = app.groups.get_groups()
    else:
        new_groups = app.orm.get_groups_list()
    assert len(old_groups) == len(new_groups)
    del old_groups[index]
    old_groups.append(modified_group)
    assert list_sort(old_groups) == list_sort(new_groups)
 def get_groups(self):
     if self.groups_cache is None:
         groups_elements = self.wd.find_elements_by_xpath(
             "//span[@class='group']")
         self.groups_cache = list()
         for element in groups_elements:
             group_id = element.find_element_by_css_selector(
                 "input").get_attribute("value")
             group_name = element.text
             self.groups_cache.append(
                 Group(group_name, None, None, group_id))
         return list(self.groups_cache)
     else:
         return list(self.groups_cache)
Beispiel #14
0
 def get_group_list(self):
     cursor = self.connection.cursor()
     list = []
     try:
         cursor.execute(
             "select group_id, group_name, group_header, group_footer from group_list"
         )
         for row in cursor:
             (id, name, header, footer) = row
             list.append(
                 Group(id=str(id), name=name, header=header, footer=footer))
     finally:
         cursor.close()
     return list
Beispiel #15
0
def test_delete_first_group(app):
    with pytest.allure.step('Create new group if list is empty'):
        if app.group.count() == 0:
            app.group.create(
                Group(name="test9", header="Python group", footer="comment"))
    with pytest.allure.step('Given a group list'):
        old_groups = app.group.get_group_list()
    with pytest.allure.step('Delete first group'):
        app.group.delete_first()
    with pytest.allure.step(
            'The new group list is equal to the old list with deleted group'):
        new_groups = app.group.get_group_list()
        assert len(old_groups) - 1 == len(new_groups)
        old_groups[0:1] = []
        assert old_groups == new_groups
Beispiel #16
0
def test_delete_some_group(app):
    with pytest.allure.step('Create new group if list is empty'):
        if app.group.count() == 0:
            app.group.create(
                Group(name="test9", header="Python group", footer="comment"))
    with pytest.allure.step('Given a group list'):
        old_groups = app.group.get_group_list()
    with pytest.allure.step('Get a index of group'):
        index = randrange(len(old_groups))
    with pytest.allure.step('Delete group with index %s' % index):
        app.group.delete_by_index(index)
    with pytest.allure.step(
            'The new group list is equal to the old list with deleted group'):
        new_groups = app.group.get_group_list()
        assert len(old_groups) - 1 == len(new_groups)
        old_groups[index:index + 1] = []
        assert old_groups == new_groups
Beispiel #17
0
def test_remove_group(app, check_ui):
    app.groups.create_group_if_not_exist(
        Group("ToRemoveName", "ToRemoveHeader", "ToRemoveFooter", None))
    app.navigation.to_groups()
    if check_ui:
        old_groups = app.groups.get_groups()
    else:
        old_groups = app.orm.get_groups_list()
    index = get_random_index_from_list(old_groups)
    app.groups.select_group_by_num_on_page(index)
    app.groups.delete()
    app.navigation.to_groups()
    if check_ui:
        new_groups = app.groups.get_groups()
    else:
        new_groups = app.orm.get_groups_list()
    assert len(old_groups) == len(new_groups) + 1
    del old_groups[index]
    assert list_sort(old_groups) == list_sort(new_groups)
Beispiel #18
0
def test_delete_some_group_db(app, db, check_ui):
    with pytest.allure.step('Create new group if list is empty'):
        if len(db.get_group_list()) == 0:
            app.group.create(
                Group(name="test9", header="Python group", footer="comment"))
    with pytest.allure.step('Given a group list'):
        old_groups = db.get_group_list()
    with pytest.allure.step('Get a id of group'):
        group = random.choice(old_groups)
    with pytest.allure.step('Delete group with group id %s' % group.id):
        app.group.delete_by_id(group.id)
    with pytest.allure.step(
            'The new group list is equal to the old list with deleted group'):
        new_groups = db.get_group_list()
        assert len(old_groups) - 1 == len(new_groups)
        old_groups.remove(group)
        assert old_groups == new_groups
        if check_ui:
            assert sorted(new_groups, key=Group.id_or_max) == sorted(
                app.group.get_group_list(), key=Group.id_or_max)
def test_delete_contact_from_group(app, db, orm):
    if len(db.get_group_list()) == 0:
        app.group.create(Group("oOo"))
    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact("TIMMY"), Date("20", "March", "1990"),
                           Date("20", "June", "2000"))
    groups_with_contacts = []
    for g in db.get_group_list():
        if len(orm.get_contacts_in_group(g)) >= 1:
            groups_with_contacts.append(g)
    if len(groups_with_contacts) == 0:
        contact = random.choice(db.get_contact_list())
        group = random.choice(db.get_group_list())
        app.contact.add_contact_in_group_by_id(contact.id, group.id)
        groups_with_contacts.append(group)
    contact_in_group = orm.get_contacts_in_group(groups_with_contacts[0])[0]
    app.contact.delete_contact_from_group_by_id(contact_in_group.id,
                                                groups_with_contacts[0].id)
    assert contact_in_group not in orm.get_contacts_in_group(
        groups_with_contacts[0])
    assert contact_in_group in orm.get_contacts_not_in_group(
        groups_with_contacts[0])
Beispiel #20
0
from model.groups import Group

constant = [
    Group(name="name1", header="header1", footer="footer1"),
    Group(name="name2", header="header2", footer="footer2")
]
 def clean(group):
     return Group(id=group.id, name=group.name.strip())
Beispiel #22
0
except getopt.GetoptError as err:
    getopt.usage()
    sys.exit(2)

n = 5
f = 'data/groups.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 + string.punctuation
    return prefix + "".join(
        [random.choice(symbols) for i in range(random.randrange(maxlen))])


testdata = [Group(name='', header='', footer='')] + [
    Group(name=random_string("name", 10),
          header=random_string("header", 20),
          footer=random_string("footer", 20)) for x in range(n)
]

file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', f)

with open(file, "w") as f:
    jsonpickle.set_encoder_options("json", indent=2)
    f.write(jsonpickle.dumps(testdata))
Beispiel #23
0
 def convert(group):
     return Group(id=str(group.id), name=group.name, header=group.header, footer=group.footer)
Beispiel #24
0
def new_group(name, header, footer):
    return Group(name = name, header = header, footer = footer)
from fixture.orm import ORMFixture
from model.groups import Group
db = ORMFixture(host = "127.0.0.1", name = "addressbook", user = "******", password = "")

try:
    l = db.get_contacts_in_group(Group(id = 217))
    for item in l:
        print(item)
finally:
    pass #connection.close()
Beispiel #26
0
try:
    opts, args = getopt.getopt(sys.argv[1:], "n:f:", ["number of groups", "file"])
except getopt.GetoptError as err:
    getopt.usage()
    sys.exit(2)

n = 5
f = "data/groups.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 + string.punctuation + " "*10
    symbols = string.ascii_letters + string.digits + " " * 1
    return prefix +"".join([random.choice(symbols) for i in range(random.randrange(maxlen))])

testdata = [Group(name="", header="",footer="")] + [
    Group(name=random_string("name", 10), header=random_string("header", 20),footer=random_string("footer", 20))
    for i in range(n)
]

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))
Beispiel #27
0
def non_empty_group_list(db, app):
    if len(db.get_group_list()) == 0:
        app.group.create(Group("oOo"))
    return db.get_group_list()