def test_edit_first_group_footer(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(name='test')) old_groups = db.get_group_list() index = randrange(len(old_groups)) group_id = old_groups[index].id group = Group(footer="Edited footer") app.group.edit_group_by_id(group, group_id) new_groups = db.get_group_list() old_groups[index].footer = group.footer 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)
def test_modify_group_name(app): app.group.modify_first_group(Group(name="New group")) ##def test_modify_group_name(app): ##app.session.login(username="******", password="******") ## app.group.modify_first_group(Group(header="New header")) ##app.session.logout()
def test_modify_group(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(name="Group for modify")) old_groups = db.get_group_list() group = random.choice(old_groups) old_groups.remove(group) modify_group = Group(name="modify_name") modify_group.id = group.id app.group.modify_group_by_id(group.id, modify_group) assert len(old_groups) + 1 == app.group.count_groups() new_groups = db.get_group_list() old_groups.append(modify_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)
def get_group_list(self): if self.group_cache is None: wd = self.app.wd self.open_groups_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)
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
def test_del_random_group(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(name='test')) old_groups = db.get_group_list() group = random.choice(old_groups) app.group.delete_group_by_id(group.id) new_groups = db.get_group_list() 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_add_new_contact_to_group(app): if len(db.get_group_list_orm()) == 0: app.group.create(Group(name='test')) # Select group to adding contacts groups_list = sorted(db.get_group_list_orm(), key=Group.id_or_max) group_id = groups_list[-1].id # Add at least one contact to group to avoid errors app.contact.add_new(Contact(name=''), group_id) # Get number of group members old_members = len(db.get_contacts_in_group_orm(Group(id='%s' % group_id))) # Add one more group member app.contact.add_new(Contact(name=''), group_id) contacts_list = sorted(db.get_contact_list_orm(), key=Contact.id_or_max) contact_id = contacts_list[-1].id # Check that one more member was added to group new_members = sorted(db.get_contacts_in_group_orm(Group(id='%s' % group_id)), key=Contact.id_or_max) assert len(new_members) == old_members + 1 assert new_members[-1].id == contact_id
def test_delete_some_group(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(name="Created group for deletion")) 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_groups() new_groups = db.get_group_list() 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 clean(group): return Group(id.group.id, name=group.name.strip())
def convert(group): return Group(id=str(group.id), name=group.name, header=group.header, footer=group.footer)
from python_training.model.group import Group testdata = [ Group(name='name1', header='header1', footer='footer1'), Group(name='name2', header='header2', footer='footer2') ]
from python_training.model.group import Group testdata = [ Group(name="name1", header="header1", footer="footer1"), Group(name="name2", header="header2", footer="footer2") ]
def test_add_group(app): app.group.create(Group(name="1", header="1", footer="1"))
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): str1 = string.ascii_letters + string.digits + string.punctuation + " " * 10 str2 = str1.replace("'", "") symbols = str2.replace('"', "") return prefix + "".join([ random.choice(symbols.strip()) 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))
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 + ""*10 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))
from python_training.fixture.orm import ORMFixture from python_training.model.group import Group db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") try: l = db.get_contacts_not_in_group(Group(id="95")) for item in l: print(item) print(len(l)) finally: pass # db.destroy()