Exemplo n.º 1
0
def test_edit_group_name(app):
    if app.group.count() == 0:
        app.group.create(Group(name="test", header="test", footer="test"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(name="new")
    group.id = old_groups[index].id
    app.group.edit_group_by_index(index, group)
    new_groups = app.group.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)


#def test_edit_group_header(app):
#    if app.group.count() == 0:
#        app.group.create(Group(name="test", header="test", footer="test"))
#    old_groups = app.group.get_group_list()
#    group = Group(header="new")
#    group.id = old_groups[0].id
#    app.group.edit_first_group(group)
#    new_groups = app.group.get_group_list()
#    assert len(old_groups) == len(new_groups)
#    old_groups[0]=group
#    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
Exemplo n.º 2
0
    def insertExampleData(self):
        self.getSession()
        g1 = Group("Group 1")
        g2 = Group("Group 2")
        g2.fav = True

        t1 = Track("Bob", "Hello World!", False, 1)
        t2 = Track("Joe", "How are you doing?", True, 3)
        t3 = Track("Jim", "Can't stop dancing", False, 5)
        t4 = Track("Tom", "A simple melody", True, 9)

        gt1_1 = GroupTrack(1, 0, 100)
        gt1_1.track = t1
        gt1_2 = GroupTrack(2, 100, 200)
        gt1_2.track = t2
        g1.grouptracks.append(gt1_1)
        g1.grouptracks.append(gt1_2)

        gt2_2 = GroupTrack(1, 0, 200)
        gt2_2.track = t2
        gt2_3 = GroupTrack(2, 200, 150)
        gt2_3.track = t3
        g2.grouptracks.append(gt2_2)
        g2.grouptracks.append(gt2_3)

        self.session.add_all([g1, g2, t1, t2, t3, t4, gt1_1, gt1_2, gt2_2, gt2_3])
        self.session.commit()
def test_modify_some_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name='test'))
    old_groups = db.get_group_list()
    random_group = random.choice(old_groups)
    group = Group(name="update")
    group.id = random_group.id
    app.group.modify_group_by_id(group)
    new_groups = db.get_group_list()
    assert len(old_groups) == len(new_groups)
    i = 0
    for x in old_groups:
        if x.id == random_group.id:
            old_groups[i] = group
        i += 1
    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_modify_group_header(app):
#    old_groups = app.group.get_group_list()
#    app.group.modify_first_group(Group(header="update"))
#    new_groups = app.group.get_group_list()
#    assert len(old_groups) == len(new_groups)
def test_modify_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        test_group = Group()
        test_group.dummy()
        app.group.create(test_group)

    old_groups = db.get_group_list()

    group = random.choice(old_groups)

    test_group_new = Group(name = "random")
    test_group_new.id = group.id

    app.group.modify_by_id(group.id, test_group_new)

    new_groups = db.get_group_list()

    assert len(old_groups) == len(new_groups)

    old_groups[old_groups.index(group)] = test_group_new

    assert old_groups == new_groups

    if check_ui:
        assert sorted(map(clean, new_groups), key = Group.id_or_max) == \
            sorted(app.group.get_group_list(), key = Group.id_or_max)
def test_modify_group_name(app):
    group = Group(name="To be modified")
    if app.group.count() == 0:
        app.group.create(Group(name="New group name"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group.id = old_groups[index].id
    app.group.modify_group_by_index(group, index)
    assert len(old_groups) == app.group.count()
    new_groups = app.group.get_group_list()
    old_groups[index] = group
    assert sorted(old_groups, key = Group.id_or_max) == sorted(new_groups, key = Group.id_or_max)

# def test_modify_group_header(app):
#     if app.group.count() == 0:
#         app.group.create(Group(header="To be modified"))
#     app.group.modify_first_group(Group(header="New group header"))
#     old_groups = app.group.get_group_list()
#     new_groups = app.group.get_group_list()
#     assert len(old_groups) == len(new_groups)
#
# def test_modify_group_footer(app):
#     if app.group.count() == 0:
#         app.group.create(Group(footer="To be modified"))
#     app.group.modify_first_group(Group(footer="New group footer"))
#     old_groups = app.group.get_group_list()
#     new_groups = app.group.get_group_list()
#     assert len(old_groups) == len(new_groups)
Exemplo n.º 6
0
    def get_groups(self, uname):
        # get all groups for this user
        group = None
        user_groups = None
        try:
            collection = self.user_collection
            user_groups = collection.find_one({'_id':uname},{"groups":True})
        except Exception as inst:
            print "error reading groups"
            print inst

        if user_groups != None:
            
            group_cursor = user_groups["groups"]
            groups = []

            for item in group_cursor:
                print item
                group = Group()
                group.id = str(item["_id"])
                group.name = item["name"]
                group.hash = item["hash"]

                groups.append(group)

            return groups
        else:
            return None
def test_modify_gname(app):
	old_groups = app.group.get_group_list()
	group = Group(name= 'New Group')
	group.id = old_groups[0].id
	app.group.modify_first_group(group)
	new_groups = app.group.get_group_list()
	assert len(old_groups) == len(new_groups)
	old_groups[0]= group
	assert  sorted(old_groups,key=Group.id_or_max) == sorted(new_groups,key=Group.id_or_max)
Exemplo n.º 8
0
def test_modify_group_name(app, db, check_ui):
    if app.group.count() == 0:
        app.group.create(Group(name="TestGroupName"))
    old_groups = db.get_group_list()
    old_group = random.choice(old_groups)
    group = Group(name="ModifyGroup")
    group.id = old_group.id
    old_groups.remove(old_group)
    app.group.modify_group_by_id(group)
    app.group.check_add_or_modify_success(db, group, old_groups, check_ui)
Exemplo n.º 9
0
def test_modify_group_name(app, orm):
    check_for_group(app)
    old_groups = orm.get_group_list()
    group = random.choice(old_groups)
    gr_obj = Group(name="popopo")
    gr_obj.id = group.id
    old_groups.remove(group)
    old_groups.append(gr_obj)
    app.group.modify_by_id(gr_obj)
    new_groups = orm.get_group_list()
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
Exemplo n.º 10
0
def test_modify_group_name(app):
    if app.group.count() == 0:
        app.group.create(Group(name="testing"))
    old_groups = app.group.get_group_list()
    group = Group (name= "NewGroup")
    group.id = old_groups[0].id
    app.group.modify_first_group(group)
    new_groups = app.group.get_group_list()
    assert len(old_groups) == len (new_groups)
    old_groups[0]=group
    assert sorted(old_groups,key=Group.id_or_max) == sorted(new_groups,key=Group.id_or_max)
Exemplo n.º 11
0
def test_mod_some_group_name(app):
    if app.group.count() == 0:
        app.group.create(Group(name="test"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(name="new group")
    group.id = old_groups[index].id
    app.group.modify_group_by(group,index)
    new_groups = app.group.get_group_list()
    assert len(old_groups) == app.group.count()
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
Exemplo n.º 12
0
def test_modify_some_group(app):
    group = Group(name="New group")
    if app.group.count() == 0:
        app.group.create(group)
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group.id = old_groups[index].id
    app.group.modify_group_by_index(index, group)
    assert len(old_groups) == app.group.count()
    new_groups = app.group.get_group_list()
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
Exemplo n.º 13
0
def test_edit_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="name_name", header="head_head"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    group_new = Group(name="new_name", header="new_header", footer="new_footer")
    group_new.id = group.id
    app.group.edit_group_by_id(group.id, group_new)
    new_groups = db.get_group_list()
    # 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)
Exemplo n.º 14
0
def test_edit_group_name(gen):
    if gen.group.count() == 0:
        gen.group.create(Group(name="test"))
    old_groups = gen.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(name="New name")
    group.id = old_groups[index].id
    gen.group.edit_group_by_index(index, group)
    assert len(old_groups) == gen.group.count()
    new_groups = gen.group.get_group_list()
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
Exemplo n.º 15
0
def test_modify_group_name(app):
   if app.group.count() == 0:
      app.group.create(Group(name="some name", header="some logo", footer="some footer"))
   old_groups = app.group.get_groups_list()
   index = randrange(len(old_groups))
   group = Group(name="new name")
   group.id = old_groups[index].id
   app.group.modify_group_by_index(index, group)
   new_groups = app.group.get_groups_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)
Exemplo n.º 16
0
def test_edit_group(app):
    if app.group.count() == 0:
        app.group.create(Group(name="test"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group=Group(name="aaaaa", header="kkk", footer="ccc")
    group.id = old_groups[index].id
    app.group.edit_group_by_index(index, group)
    new_groups = app.group.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)
Exemplo n.º 17
0
def test_edit_first_group(app, db):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="sdfsf"))
    old_groups = db.get_group_list()
    target_group = random.choice(old_groups)
    group = Group(name="test")
    group.id = target_group.id
    app.group.edit_by_id(target_group.id, group)
    assert len(old_groups) == app.group.count()
    new_groups = db.get_group_list()
    old_groups = [group if gr.id == group.id else gr for gr in old_groups]
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
def test_modify_group_by_index(app):
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(name="test group")
    group.id = old_groups[index].id
    if app.group.count()== 0:
        app.group.create(Group(name="test group"))
    app.group.modify_group_by_index(index, group)
    new_groups = app.group.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)
Exemplo n.º 19
0
def test_edit_some_group_name(app):
    if app.group.count() ==0:
        app.group.create(Group(gr_name="for edit group"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(gr_name="edit_test111111")
    group.id = old_groups[index].id
    app.group.edit_group_by_index(index, group)
    new_groups = app.group.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)
Exemplo n.º 20
0
def create_user_groups():

    user = validate_cookie(request)
    print user.__str__()
    responseWrapper = ResponseWrapper()

    print "hello new group"
    response = any_response(request)

    if user != None:

        group = Group()
        try:
            # form_data = request.form['data']
            print request.form
            form_data = request.form['data']
            json_data = json.loads(form_data)
            group.name = json_data['group_name']
            print "appending to group user ", user.id
            group.users.append(user.id)

        except Exception as inst:
            print inst
            print "Error reading form data"
            responseWrapper.set_error(True)
            responseWrapper.set_data([inst])
            response.data = json.dumps(responseWrapper, default=ResponseWrapper.__str__)
            response.mimetype = "application/json"
            return response

        new_group_id = groupDAO.insert_group(group)
        group.id = new_group_id
        result = userDAO.append_group(user.id,group)

        if result != None:
            responseWrapper.set_error(False)
            new_group_id = str(new_group_id)
            responseWrapper.set_data([{"group_id":new_group_id}])
        else:
            responseWrapper.set_error(True)
            responseWrapper.set_data(["error writing group"])

    else:
        responseWrapper.set_error(True)
        responseWrapper.set_data(["User not found. Please login again"])
        response.status_code = 302

    response.data = json.dumps(responseWrapper, default=ResponseWrapper.__str__)
    response.mimetype = "application/json"
    return response
Exemplo n.º 21
0
def test_edit_some_group_name(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)
    group_new = Group(name="new name")
    app.group.edit_group_by_id(group.id, group_new)
    group_new.id=group.id
    new_groups = db.get_group_list()
    old_groups.remove(group)
    old_groups.append(group_new)
    assert sorted(old_groups, key = Group.id_gr_max) == sorted(new_groups, key = Group.id_gr_max)
    if check_ui:
        assert sorted(new_groups, key=Group.id_gr_max) == sorted(app.group.get_group_list(), key=Group.id_gr_max)
def test_modify_group_fields(app):
    app.session.login(username="******", password="******")
    if app.group.count() == 0:
        app.group.create(Group(name="test", header="test", footer="test"))

    old_groups = app.group.get_group_list()
    group = Group(name="updated", header="updated", footer="updated")
    group.id = old_groups[0].id
    app.group.modify_first_group(group)
    assert len(old_groups) == app.group.count()
    new_groups = app.group.get_group_list()
    old_groups[0] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
    app.session.logout()
def test_modify_group_name(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="new", header="header", footer="footer"))
    old_groups = db.get_group_list()
    random_group = random.choice(old_groups)
    group_index = old_groups.index(random_group)
    group = Group(name="updated group", header="updated header", footer="updated footer")
    group.id = random_group.id
    app.group.modify_group_by_id(group, random_group.id)
    new_groups = db.get_group_list()
    old_groups[group_index] = 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)
Exemplo n.º 24
0
def test_modify_group_name(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)
    modified_group = Group(name="New group")
    modified_group.id = group.id
    app.group.modify_group_by_id(modified_group.id, modified_group)
    new_groups = db.get_group_list()
    old_groups.remove(group)
    old_groups.append(modified_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)
Exemplo n.º 25
0
def test_edit_some_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="not enough groups"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    edited_group = Group(name="edited_name", header="edited_header", footer="edited_footer")
    edited_group.id = group.id
    app.group.edit_group_by_id(edited_group, group.id)
    new_groups = db.get_group_list()
    old_groups.remove(group)
    old_groups.append(edited_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_groups_list(), key=Group.id_or_max)
def test_modify_group_name_to(app, db, check_ui):
    if len(db.get_groups_list()) == 0:
        app.group.create(Group(name="TestName"))
    old_groups = db.get_groups_list()
    group = random.choice(old_groups)
    new_group = Group(name="NewName")
    new_group.id = group.id
    app.group.modify_group_by_id(new_group.id, new_group)
    assert len(old_groups) == app.group.count()
    new_groups = db.get_groups_list()
    index = old_groups.index(group)
    old_groups[index] = new_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)
Exemplo n.º 27
0
def test_edit_random_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="GroupName", header="GroupHeader", footer="GroupFooter"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    new_group = Group(name='Group name 1', header='Group header 1', footer='Group footer 1')
    new_group.group_id = group.group_id
    app.group.edit_group_by_id(new_group, group.group_id)
    assert len(old_groups) == app.group.count()
    new_groups = db.get_group_list()
    old_groups.remove(group)
    old_groups.append(new_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 test_rename_first_group(app,db,check_ui):
    if app.group.count() == 0:
        app.group.create(Group(name="test"))
    old_groups = db.get_group_list()
    chosen_group = random.choice(old_groups)
    index = old_groups.index(chosen_group)
    group = Group(name="edited1", header="edited", footer="edited")
    group.id=chosen_group.id
    app.group.edit_group_by_id(group.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:
        assert sorted(new_groups, key = Group.id_or_max) == sorted(app.group.get_group_list(), key = Group.id_or_max)
Exemplo n.º 29
0
def test_update_group_name(app, orm, check_ui):
    if len(orm.get_groups()) == 0:
        app.group.add(Group(name='first group'))
    old_groups = orm.get_groups()
    group = random.choice(old_groups)
    index = old_groups.index(group)
    new_data = Group(name='new name')
    new_data.id = group.id
    app.group.update_by_id(group.id, new_data)
    new_groups = orm.get_groups()
    assert len(old_groups) == len(new_groups)
    old_groups[index] = new_data
    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(), key=Group.id_or_max)
Exemplo n.º 30
0
    def newgroup(self, name):
        '''
        create a group and insert it to the list in the position
        '''
        self._checksession()

        g = Group(name)
        g.fav = True
        self.lst.append(g)
        self.session.add(g)
        self.session.commit()

        self.resort()

        return self.lst.index(g)
Exemplo n.º 31
0
from model.group import Group


test_data = [
    Group(name="name1", header="header1", footer="footer1")
]
Exemplo n.º 32
0
def test_delete_first_group(app):
    if app.group.count == 0:
        app.group.create(Group(name="test"))
    app.group.delete_first_group()
Exemplo n.º 33
0
 def clean(group):
     return Group(id=group.id, name=group.name.strip())
Exemplo n.º 34
0
from model.group import Group
import random
import string

def random_string(prefix, maxlen):
    symbols = string.ascii_letters + string.digits
    #symbols = string.ascii_letters + string.digits + " "*5 + string.punctuation
    return prefix + "".join([random.choice(symbols) for i in range(random.randrange(3, maxlen))])

testdata = [Group(name="", header="", footer="")] + [
    Group(name=random_string("name_", 10), header=random_string("header_", 8), footer=random_string("footer_", 12))
    for i in range(5)
]
Exemplo n.º 35
0
def non_empty_group_list(db, app):
    if len(db.get_group_list()) == 0:
        app.group.create(
            Group(name='name1', header='header1', footer='footer1'))
    return db.get_group_list()
Exemplo n.º 36
0
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 + string.punctuation + " " * 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))
Exemplo n.º 37
0
from fixture.orm import ORMFixture
from model.group import Group
from model.contact import Contacts

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

try:
    # l = db.get_contacts_not_in_group(Group(id="268"))
    # for item in l:
    #     print(item)
    # print(len(l))
    l = db.get_contacts_in_group(Group(id="331"))
    #l = db.get_contacts_not_in_group(Contacts())
    for item in l:
        print(item)
    print(len(l))
finally:
    pass  #db.destroy()
Exemplo n.º 38
0
 def convert(group):
     return Group(id=str(group.id),
                  name=group.name,
                  header=group.header,
                  footer=group.footer)
Exemplo n.º 39
0
from fixture.orm import ORMFixture
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="160"))
    # l = db.get_contacts_not_in_group(Group(id="160"))
    for item in l:
        print(item)
    print(len(l))
finally:
    pass
Exemplo n.º 40
0
def new_group(name, header, footer):
    return Group(name=name, header=header, footer=footer)
Exemplo n.º 41
0
f_name = 'data/groups.xlsx'

for opt, val in opts:
    if opt == '-n':
        n = int(val)
    elif opt == '-f':
        f = val


def random_string(prefix, max_len):
    symbols = string.ascii_letters + string.digits + " " * 10
    return prefix + ''.join(
        [random.choice(symbols) for i in range(random.randrange(max_len))])


testdata = [Group(name='')
            ] + [Group(name=random_string('name', 10)) for i in range(n)]

file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', f_name)

excel = Excel.ApplicationClass()
excel.visible = True

workbook = excel.Workbooks.Add()
sheet = workbook.ActiveSheet

for i in range(len(testdata)):
    sheet.Range[("A%s" % (i + 1))].Value2 = testdata[i].name

workbook.SaveAs(file)
Exemplo n.º 42
0
from fixture.orm import ORMFixture
from model.group import Group
from model.contact import Contact

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

try:
    group = Group(id="300")
    c = db.get_contact_list(search="name")
    for item in c:
        print(item)
    print(len(c))

finally:
    pass
Exemplo n.º 43
0
import sys
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/groups.json"

for o, a in opts:
    if o == "-n":
        n = int(a)
    elif o == "-f":
        f = a

testdata = [
    Group(name=MH.random_string("name", 10),
          header=MH.random_string("header", 20),
          footer=MH.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))
Exemplo n.º 44
0
from fixture.orm import ORMFixture
from 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='509'))
    for item in l:
        print(item)
    print(len(l))
finally:
    pass











'''
import pymysql.cursors

connection = pymysql.connect(host="127.0.0.1", database="addressbook", user="******", password="")

try:
    cursor = connection.cursor()
    cursor.execute("select * from group_list")
Exemplo n.º 45
0
from fixture.orm import ORMFixture
from 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='181'))
    for item in l:
        print(item)
    print(len(l))
finally:
    pass  #db.destroy()
Exemplo n.º 46
0
 def clean(group):
     group.name = re.sub(" +", " ", group.name)
     return Group(id=group.id, name=group.name.strip())
Exemplo n.º 47
0
def test_add_group(app):
    app.session.login(username="******", password="******")
    app.group.create(
        Group(name="test3333", header="test test", footer="test for test"))
    app.session.logout()
# -*- coding: utf-8 -*-
from fixture.orm import ORMFixture
from model.group import Group

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

try:
    result_list = db.get_contacts_in_group(Group(id="11"))
    # result_list = db.get_contact_list()
    for item in result_list:
        print(item)
    print(len(result_list))
finally:
    db.destroy()
Exemplo n.º 49
0
def test_add_empty_group(app):
    app.group.create(Group(name="", header="", footer=""))
 def clean(group):
     return Group(id=group.id, name=group.name.strip()
                  )  #удаление лишних пробелов вначале и в конце
Exemplo n.º 51
0
def test_empty_group(app):

    app.session.login( username="******", password="******")
    app.group.create(Group(name="", header="", footer=""))
    app.session.logout()
Exemplo n.º 52
0
from fixture.orm import ORMFixture
from model.group import Group

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

try:
    list = db.get_addresses_not_in_group(Group(id="114"))
    for i in list:
        print(i)
    print(len(list))
finally:
    pass  # db.destroy()
Exemplo n.º 53
0
def test_add_group(app):
    app.group.create(Group(name="asdasda", header="sdfwsfws", footer="asdasdasda"))
Exemplo n.º 54
0
    sys.exit(2)


cg = 5
fg = "data/group.json"


for o, a in opts:
    if o == "-cg":
        cg = int(a)
    elif o == "-fg":
        fg = a


def random_string(prefix, max_length):
    symbols = string.ascii_letters + string.digits + ' '*10
    return prefix + "".join([random.choice(symbols) for i in range(random.randrange(max_length))])


test_data = [Group(name="", header="", footer="")] + [
    Group(name=random_string("name", 10), header=random_string("header_group", 20), footer=random_string("footer", 20))
    for i in range(cg)
]


data_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", fg)

with open(data_file, "w") as data:
    jsonpickle.set_encoder_options("json", indent=2)
    data.write(jsonpickle.encode(test_data))
Exemplo n.º 55
0
def test_add_group(app):

    app.session.login( username="******", password="******")
    app.group.create(Group(name="fgtyhtgfd", header="dfrtghy", footer="cdfgvbhnjyu"))
    app.session.logout()
Exemplo n.º 56
0
    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_str(prefix, maxlen):
    sym = string.ascii_letters + string.digits + " "*10 #+ string.punctuation
    return prefix + "".join([random.choice(sym) for i in range(random.randrange(maxlen))])


testdata = [Group(name="", header="", footer="")] + [
    Group(name=random_str("NN",10), header=random_str("HH",20), footer=random_str("FF",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))
Exemplo n.º 57
0
 def clean_group(self, group):
     return Group(id=group.id, name=group.name.strip())
Exemplo n.º 58
0
import mysql.connector
from fixture.orm import ORMFixture
from model.group import Group

#def check_contact_in_group():
db = ORMFixture(host="127.0.0.1",
                database="addressbook",
                user="******",
                password="")
massive = []
try:
    L = db.get_contacts_in_group(Group(id='165'))
    for i in L:
        massive.append(i)
    print(massive)
    print(len(L))
finally:
    pass  #db.destroy()
Exemplo n.º 59
0
def non_empty_group_list(db, app):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="name"))
    return db.get_group_list()
Exemplo n.º 60
0
 # -*- coding utf-8 -*-
from model.group import Group
import pytest
import random
import string

def random_string(prefix, maxlen):
    symbols = string.ascii_letters + string.digits + string.punctuation + " "*10
    return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))])


testdata = [Group(group_name=random_string("name", 10), group_header=random_string("header", 20), group_footer=random_string("footer", 20))
                                                     for i in range(5)]


@pytest.mark.parametrize("group", testdata, ids=[repr(x) for x in testdata])
def test_add_group(app, group):
    old_groups = app.group.get_group_list()
    app.group.create(group)
    assert len(old_groups) + 1 == app.group.count()
    new_groups = app.group.get_group_list()
    old_groups.append(group)
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)