def test_add_contact_to_group(app, db): groups = db.get_group_list() if len(groups) is 0: app.group.create(Group(name='GroupForContacts')) groups = db.get_group_list() group = groups[0] oldGroupContacts = db.get_contacts_in_group(group) contact = Contact(firstname=random_string('ContactForGroup', 3), lastname=random_string('ln', 3), group=group) app.contact.create(contact) newGroupContacts = db.get_contacts_in_group(group) oldGroupContacts.append(contact) assert len(oldGroupContacts) == len(newGroupContacts) assert sorted(oldGroupContacts, key=Contact.id_or_max) == sorted(newGroupContacts, key=Contact.id_or_max)
def test_project_add(app): old_projects = app.soap.get_projects() project = Project(name=random_string("PN", 20)) app.soap.create(project) new_projects = app.soap.get_projects() old_projects.append(project) assert len(old_projects) == len(new_projects) assert sorted(old_projects, key=Project.Key) == sorted(new_projects, key=Project.Key)
def test_project_add(app): app.session.login("administrator", "root") old_projects = app.project.get_projects() project = Project(name=random_string("PN", 20)) app.project.create(project) new_projects = app.project.get_projects() old_projects.append(project) assert len(old_projects) == len(new_projects) assert sorted(old_projects, key=Project.Key) == sorted(new_projects, key=Project.Key)
def test_remove_contact_from_group(app, db): groups = db.get_group_list() if len(groups) is 0: app.group.create(Group(name='GroupForContacts')) groups = db.get_group_list() group = groups[0] oldGroupContacts = db.get_contacts_in_group(group) contact = Contact(firstname=random_string('ContactForGroup', 3), lastname=random_string('ln', 3), group=group) app.contact.create(contact) newGroupContacts = db.get_contacts_in_group(group) oldGroupContacts.append(contact) assert len(oldGroupContacts) == len(newGroupContacts) oldGroupContacts.sort(key=Contact.id_or_max) newGroupContacts.sort(key=Contact.id_or_max) assert oldGroupContacts== newGroupContacts id = newGroupContacts[-1].id app.contact.delete_by_id(id) oldGroupContacts.remove(contact) newGroupContacts = db.get_contacts_in_group(group) assert len(oldGroupContacts) == len(newGroupContacts) newGroupContacts.sort(key=Contact.id_or_max) assert oldGroupContacts== newGroupContacts
def test_project_delete(app): project = None old_projects = app.soap.get_projects() if len(old_projects) == 0: project = Project(name=random_string("PN", 20)) app.soap.create( project) old_projects.append(project) else: project = random.choice(old_projects) app.soap.delete(project) new_projects = app.soap.get_projects() old_projects.remove(project) assert len(old_projects) == len(new_projects) assert sorted(old_projects, key=Project.Key) == sorted(new_projects, key=Project.Key)
import sys import os import jsonpickle 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/contacts.json' for o, a in opts: if o == "-n": n = int(a) elif o == "-f": f = a testdata= [Contact(firstname="", middlename="", lastname="")] + [ Contact(firstname=random_string("fname", 15), middlename=random_string("mname", 15), lastname=random_string("lname", 15)) 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))
import sys 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 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))