def test_del_contact_from_group(app, db, orm): if len(app.form.get_contacts_list()) == 0: app.form.create(Contact(first_name="ZUMZUM")) if len(app.group.get_group_list()) == 0: app.group.create(Group(name="BBB", header="BBB", footer="BBB")) if len(db.get_groups_with_contacts()) == 0: contact_id = random.choice(db.get_contacts_list()).id group_id = random.choice(db.get_group_list()).id app.form.add_contact_to_group(contact_id, group_id) group_id = random.choice(db.get_groups_with_contacts()).id contact_id = random.choice(orm.get_contacts_in_group( Group(id=group_id))).id app.form.delete_contact_from_group(group_id) assert db.get_contact_by_id(contact_id) not in orm.get_contacts_in_group( Group(id=group_id))
def test_add_contact_to_group(app, db): if len(db.get_contacts_list()) == 0: app.form.create(Contact(first_name="ZUMZUM")) if len(db.get_group_list()) == 0: app.group.create(Group(name="ZZZ", header="CCC", footer="PPP")) contact_list = db.get_contacts_list() contact_id = random.choice(contact_list).id group_list = db.get_group_list() group_id = random.choice(group_list).id app.form.add_contact_to_group(contact_id, group_id)
def get_groups_with_contacts(self): list = [] cursor = self.connection.cursor() try: cursor.execute("select group_id from address_in_groups") for row in cursor: (id, ) = row list.append(Group(id=str(id))) finally: cursor.close() return list
def test_edit_some_group_name(app, db, check_ui): if app.group.count() == 0: app.group.create(Group(name="VVVVVVV")) old_groups = db.get_group_list() index = random.choice(range(len(old_groups))) id = old_groups[index].id group = Group(name="111", id=id) app.group.edit_group_by_id(id, group) new_groups = db.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) if check_ui: def clean(group): return Group(id=group.id, name=group.name.rstrip()) assert sorted(list(map(clean, new_groups)), key=Group.id_or_max) == sorted( app.group.get_group_list(), key=Group.id_or_max)
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_delete_some_group(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(name="VVVVVVV")) 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() assert len(old_groups) - 1 == len(new_groups) old_groups.remove(group) assert old_groups == new_groups if check_ui: def clean(group): return Group(id=group.id, name=group.name.rstrip()) assert sorted(list(map(clean, new_groups)), key=Group.id_or_max) == sorted( app.group.get_group_list(), key=Group.id_or_max)
from fixture.orm import ORMFixture from model.hw_group import Group from model.contact import Contact db = ORMFixture(host="127.0.0.1", database="addressbook", user="******", password="") try: l = db.get_contacts_not_in_group(Group(id='40')) for item in l: print(item) print(len(l)) finally: pass
def convert(group): return Group(id=str(group.id), name=group.name, header=group.header, footer=group.footer)
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): symbol = string.ascii_letters + string.digits + string.punctuation + " " * 10 return prefix + "".join( [random.choice(symbol) for i in range(random.randrange(maxlen))]) testdata = [Group(name="", header="", footer="")] + [ Group(name=random_string("Zombi", 10), header=random_string("zombi", 20), footer=random_string("zombi", 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))
from model.hw_group import Group testdata = [ 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.rstrip())