예제 #1
0
def test_add_contact_in_group(app, orm, db):
    if len(db.get_contact_list()) == 0:
        app.Contacts.add_contact(Contact(firstname="test2"))
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="testName"))
    with pytest.allure.step('Given a group list'):
        selected_group = random.choice(orm.get_group_list())
    with pytest.allure.step('Given a contact_not_in_group'):
        contact_not_in_group = orm.get_contacts_not_in_group(selected_group)
    with pytest.allure.step('Given a contact_in_group'):
        contact_in_group = orm.get_contacts_in_group(selected_group)
    with pytest.allure.step('check contact list before add'):
        countact_before_adding = len(contact_in_group)
    if len(contact_not_in_group) == 0:
        app.Contacts.add_contact(
            Contact(firstname="Firstname",
                    lastname="Lastname",
                    address="Address"))
    contact_not_in_group = orm.get_contacts_not_in_group(selected_group)
    selected_contact = random.choice(contact_not_in_group)
    with pytest.allure.step('when select group list from group page'):
        app.group.select_group_from_home_page(selected_group.id)
    with pytest.allure.step('when added contact in group'):
        app.Contacts.add_contact_in_group(selected_contact.id)
    with pytest.allure.step('given a new contact list in group'):
        new_contact_in_group = orm.get_contacts_in_group(selected_group)
    with pytest.allure.step('then equal contacts before add with after add'):
        count_contact_in_group_after_adding_member = len(new_contact_in_group)
        assert countact_before_adding + 1 == count_contact_in_group_after_adding_member
예제 #2
0
 def get_group_list(self):
     if self.group_cache is None:
         wd = self.app.wd
         self.open_group_page()
         self.group_cache = []
         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_cache.append(Group(name=text, id=id))
     return list(self.group_cache)
예제 #3
0
 def get_list_of_groups_names_and_ids(self):
     list = []
     cursor = self.connection.cursor()
     try:
         cursor.execute("select group_id, group_name from group_list")
         for row in cursor:
             (id, name) = row
             list.append(Group(id=str(id), name=name))
     finally:
         cursor.close()
     return list
def test_modify_group_name(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name='real', header='true'))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    modified_group = Group(name='modified')
    modified_group.id = group.id
    app.group.modify_group_by_id(group.id, modified_group)
    new_groups = db.get_group_list()
    assert len(old_groups) == app.group.count()
    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_modify_group_header(app):
#old_groups = app.group.get_group_list()
#app.group.modify_first_group(Group(header='modified'))
#new_groups = app.group.get_group_list()
#assert len(old_groups) == len(new_groups)
예제 #5
0
def test_edit_some_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="testName"))
    with pytest.allure.step('Given a old group list'):
        old_groups = db.get_group_list()
        index = randrange(len(old_groups))
        group = Group(name="New Nameasasa")
        group.id = old_groups[index].id
    with pytest.allure.step('When edit group'):
        app.group.edit_group_by_id(group.id, group)
    #assert len(old_groups) == app.group.countgroup()
    with pytest.allure.step('Given a new group list'):
        new_groups = db.get_group_list()
    with pytest.allure.step(
            'Then the new group list equal to the old group list with the edit group'
    ):
        old_groups[index] = group
        assert old_groups == new_groups
    if check_ui:
        groups_name_from_db = db.get_list_of_groups_names_and_ids()
        assert sorted(groups_name_from_db, key=Group.id_or_max) == sorted(
            app.group.get_group_list(), key=Group.id_or_max)
예제 #6
0
 def get_group_list(self):
     list = []
     cursor = self.connection.cursor()
     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
예제 #7
0
def test_delete_some_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name='test'))

    with pytest.allure.step('Given a group list'):
        old_groups = db.get_group_list()
    with pytest.allure.step('Given a random group from the list'):
        group = random.choice(old_groups)
    with pytest.allure.step(
            'When I delete the group with id= %s from the list' % group.id):
        app.group.delete_group_by_id(group.id)
    new_groups = db.get_group_list()
    with pytest.allure.step(
            'Then the new group list is equal to the old list without deleted group'
    ):
        assert len(old_groups) - 1 == app.group.count()
        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)
예제 #8
0
def test_delete_some_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test1"))
    with pytest.allure.step('Given a old group list'):
        old_groups = db.get_group_list()
        group = random.choice(old_groups)
    #index = randrange(len(old_groups))
    #app.group.delete_group_by_index(index)
    with pytest.allure.step('delete group by id'):
        app.group.delete_group_by_id(group.id)
    with pytest.allure.step('Given a new group list'):
        new_groups = db.get_group_list()
    with pytest.allure.step(
            'Then the new group list equal to the old group list with the edit group'
    ):
        assert len(old_groups) - 1 == app.group.countgroup()
        #old_groups[index:index+1] = []
        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)
예제 #9
0
def test_delete_contact_in_group(app, orm, db):
    if len(db.get_contact_list()) == 0:
        app.Contacts.add_contact(Contact(firstname="test2"))
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="testName"))
    group_list = orm.get_group_list()
    contact_list = orm.get_contact_list()
    selected_group = random.choice(group_list)
    contact_list_from_group = orm.get_contacts_in_group(selected_group)
    if len(contact_list_from_group) == 0:
        selected_contact = random.choice(contact_list)
        app.group.select_group_from_home_page(selected_group.id)
        app.Contacts.add_contact_in_group(selected_contact.id)
        contact_list_from_group = orm.get_contacts_in_group(selected_group)
    count_contact_before_add = len(contact_list_from_group)
    selected_contact = random.choice(contact_list_from_group)
    app.Contacts.open_group_page_with_contact(selected_group.name)
    contact_index = contact_list_from_group.index(selected_contact)
    app.Contacts.delete_contact_from_group(selected_group.name, contact_index)
    contact_list = orm.get_contacts_in_group(selected_group)
    count_contact_after_add = len(contact_list)
    assert count_contact_before_add - 1 == count_contact_after_add
예제 #10
0
 def convert(group):
     return Group(id=str(group.id),
                  header=group.header,
                  footer=group.footer,
                  name=group.name)
예제 #11
0
from Model.group import Group

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

n = 3
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 * 5
    return prefix + "".join(
        [random.choice(symbols) for i in range(random.randrange(maxlen))])


Testdata = [Group(name="", footer="", header="")] + [
    Group(name=random_string("name", 10),
          footer=random_string("footer", 20),
          header=random_string("header", 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))
예제 #14
0
from Model.group import Group

testdata_static = [
    Group(name="name1", header='header1', footer='footer1'),
    Group(name="name2", header='header2', footer='footer2')
]
예제 #15
0
from Fixture.orm import ORMFixture
from Model.group import Group

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

try:
    contacts = db.get_contacts_not_in_group(Group(id="18"))
    for contact in contacts:
        print(contact)
    print(len(contacts))
finally:
    pass  #db.destroy()

#from Fixture.db import DbFixture

#db = DbFixture(host="127.0.0.1", name="addressbook", user="******", password="")

#try:
#contacts = db.get_contact_list()
#for contact in contacts:
#print(contact)
#print(len(contacts))
#finally:
#db.destroy()
예제 #16
0
        n = int(a)
    elif o == "-f":
        f = a


def random_string(prefix, maxlen, symbols=None, digits=None):
    if symbols != None:
        symbols = string.ascii_letters + " " * 3
        return prefix + "".join(
            [random.choice(symbols) for i in range(random.randrange(maxlen))])
    elif digits != None:
        digits = string.digits + "-" * 3
        return prefix + "".join(
            [random.choice(digits) for i in range(random.randrange(maxlen))])
    else:
        all = string.ascii_letters + string.digits + string.punctuation + " " * 10
        return prefix + "".join(
            [random.choice(all) for i in range(random.randrange(maxlen))])


testdata = [
    Group(name=random_string('name', 3, symbols=1),
          header=random_string("header", 3, symbols=1),
          footer=random_string("footer", 3, symbols=1)) 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))
예제 #17
0
def test_add_empty_group(app):
    app.session.login(username="******", password="******")
    app.group.create(Group(name="Новая", header="", footer=""))
    app.session.logout()
예제 #18
0
def test_add_group(app):
    app.session.login(username="******", password="******")
    app.group.create(Group(name="Старая", header="Хрень", footer="НеВерная"))
    app.session.logout()
import pymysql.cursors
from fixture.orm import ORMFixture
#from fixture.db import Dbfixture
from Model.group import Group

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

try:
    l = db.get_contacts_in_group(Group(id='24'))
    for item in l:
        print(item)
    print(len(l))
finally:
    pass
예제 #20
0
def non_empty_group_list(db, app):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name='some name'))
    return db.get_group_list()
예제 #21
0
def new_group(name, header, footer):
    return Group(name=name, header=header, footer=footer)