def test_delete_contact_from_group(app, db): if len(db.get_contacts_list()) == 0: app.contact.create( Contact("Precond name", "Precond last", "Precon address", "00000", " Precond notes notes notes")) if len(db.get_groups_list()) == 0: app.group.create( Group("Precondiction Group name", "Precondition Group header", "Precongition Group footer")) db_orm = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="******") groups = db_orm.get_group_list() for g in groups: if len(db_orm.get_contact_in_group(g)) > 0: contact = random.choice(db_orm.get_contact_in_group(g)) app.contact.delete_contact_from_group(contact, g) assert contact not in db_orm.get_contact_in_group(g) print("IN IF") return else: app.contact.create(Contact(firstname="Contact")) app.navigation.open_contacts() contact = db.get_last_added_contact() group = random.choice(db.get_groups_list()) app.contact.add_contact_to_group(contact, group) #assert str(contact) in str(db_orm.get_contact_in_group(group)) app.contact.delete_contact_from_group(contact, group) assert str(contact) not in str(db_orm.get_contact_in_group(group)) print("IN ELSE")
def test_del_some_group(app, db, check_ui): if len(db.get_groups_list()) == 0: app.group.create(Group("Precondiction Group name", "Precondition Group header", "Precongition Group footer")) old_groups = db.get_groups_list() group = random.choice(old_groups) app.group.delete_by_id(group.id) new_groups = db.get_groups_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_groups_list(), key=Group.id_or_max)
def test_mod_group(app, db, check_ui): if len(db.get_groups_list()) == 0: app.group.create( Group("Precondiction Group name", "Precondition Group header", "Precongition Group footer")) old_groups = db.get_groups_list() group = Group(" " + str(datetime.now()) + " ", "" + str(datetime.now()) + " ", "" + str(datetime.now())) modyfied_group = random.choice(old_groups) app.group.modify_some_group_by_id(modyfied_group.id, group) # in application, in 9.0 version, is bug after updating a group: # Invalid ID. # return to the group page new_groups = db.get_groups_list() old_groups.remove(modyfied_group) group.set_id(modyfied_group.id) 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_groups_list(), key=Group.id_or_max)
def get_groups_list(self): groups = [] 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 groups.append( Group(id=str(id), name=name, header=header, footer=footer)) finally: cursor.close() return groups
def clean(group): return Group(id=group.id, name=group.name.strip())
from src.model.group import Group testdata = [ Group(name="name1", header="header1", footer="footer1"), Group(name="*name2+", header="?header2/", footer="=footer2>") ] # def random_string(prefix, maxlen): # symbols = string.ascii_letters + string.digits + " "*7 # return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))]) # # test_data = [Group(name=random_string("name", 10), header=random_string("header", 10), footer=random_string("footer", 10)) # for i in range(3)]
print(err) # will print something like "option -a not recognized" getopt.usage() sys.exit(2) n = 2 f = "data/groups.json" for o, a in opts: if o == "-n": n = int(a) elif o == "-f": f = a else: assert False, "unhandled option" def random_string(prefix, maxlen): symbols = string.ascii_letters + string.digits + " " * 7 return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))]) test_data = [ Group(name=random_string("name", 10), header=random_string("header", 10), footer=random_string("footer", 10)) 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(test_data))
from src.fixture.orm import ORMFixture from src.model.group import Group db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="******") try: l = db.get_contact_not_in_group(Group(id=476)) for item in l: print(item) finally: pass # try: # groups = db.get_group_list() # for g in groups: # print(g) # finally: # pass # # try: # contacts = db.get_contact_list() # for c in contacts: # print(c) # finally: # pass
def convert(group): return Group(id=group.id, name=group.name, header=group.header, footer=group.footer)
def create_group(self, name, header, footer): self.fixture.group.create( Group(name=name, header=header, footer=footer))
def new_group(name, header, footer): return (Group(name=name, header=header, footer=footer))