Ejemplo n.º 1
0
def test_modify_group(app, db, check_ui):
    with allure.step("If there are no group create one"):
        if len(db.get_group_list()) == 0:
            app.group.create(Group(name="Group for modification"))
    with allure.step("Given a list of groups and the data for modification"):
        old_groups = db.get_group_list()
        old_group = random.choice(old_groups)
        group = Group()
        # Prepare data
        group.name = "%s %s" % (old_group.name, RandomData.get_random_string())
        group.header = "%s %s" % (old_group.header,
                                  RandomData.get_random_string())
        group.footer = "%s %s" % (old_group.footer,
                                  RandomData.get_random_string())
        group.id = old_group.id
    with allure.step("When modifying the group"):
        app.group.modify_by_id(group.id, group)
    with allure.step(
            "Then the new list of groups is equal to the old list with a modified group"
    ):
        new_groups = db.get_group_list()
        old_groups.remove(old_group)
        old_groups.append(group)
        assert sorted(old_groups,
                      key=Group.id_or_max) == sorted(new_groups,
                                                     key=Group.id_or_max)
        if check_ui:
            for i in range(0, len(new_groups)):
                new_groups[i] = new_groups[i].clear()
            assert sorted(new_groups, key=Group.id_or_max) == sorted(
                app.group.get_group_list(), key=Group.id_or_max)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def test_modify_group_header(app):
    old_groups = app.group.get_groups_list()
    group = Group(header="new group header")
    group.id = old_groups[0].id
    group.name = old_groups[0].name
    app.group.modify_first_group(group)
    new_groups = app.group.get_groups_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)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def test_update_random_group_header(app):
    if app.group.count() == 0:
        app.group.create(Group(name="Group to be updated"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(header="Updated Group Header")
    app.group.update_group_by_index(Group(header="Updated Group Header"), index)
    assert len(old_groups) == app.group.count()
    new_groups = app.group.get_group_list()
    group.name = old_groups[index].name
    group.footer = old_groups[index].footer
    group.id = old_groups[index].id
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
Ejemplo n.º 6
0
def test_modify_group_footer(app):
    check_group_list_not_empty(app)
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(footer="modified_footer")
    group.id = old_groups[index].id
    group.name = old_groups[index].name
    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)
Ejemplo n.º 7
0
	def get_group_by_hash(self, invite_hash):

		collection = self.collection
		result = collection.find_one({"hash": invite_hash});

		if result != None:
			group = Group()
			group.id = result["_id"]
			# print group.id
			group.name = result["name"]
			group.hash = result["hash"]
			group.users = result["users"]

			return group
		else:
			return None
Ejemplo n.º 8
0
def test_change_some_group_header(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="group", header="new", footer="new_1"))
    old_groups = db.get_group_list()
    old_group = random.choice(old_groups)
    id = old_group.id
    group = Group(header="change_new_group")
    app.group.change_by_id(id, group)
    group.id =id
    group.name = old_group.name
    new_groups = db.get_group_list()
    old_groups.insert(old_groups.index(old_group), group)
    old_groups.remove(old_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)
Ejemplo n.º 9
0
	def get_group_by_id(self, group_id):
		# get group document from db

		collection = self.collection
		group_id = ObjectId(group_id)
		result = collection.find_one({"_id": group_id});

		if result != None:
			group = Group()
			group.id = group_id
			# print group.id
			group.name = result["name"]
			group.hash = result["hash"]
			group.users = result["users"]
			
			return group
		else:
			return None
Ejemplo n.º 10
0
def test_mod_group_name(app, orm, check_ui):
    with pytest.allure.step('Given a non-empty group list'):
        if len(orm.get_group_list()) == 0:
            app.group.create_new(Group(name="NEW"))
        old_group_list = orm.get_group_list()
        new_group = Group(header="NEW NAME")
        mod_group = random.choice(old_group_list)
        new_group.id = mod_group.id
    with pytest.allure.step('I modify the group %s in the list' % mod_group):
        if new_group.name is None:
            new_group.name = mod_group.name
        app.group.mod_group_by_id(new_group)
    with pytest.allure.step('the new group list is equal to the old list with the modified group'):
        new_group_list = orm.get_group_list()
        old_group_list.remove(mod_group)
        old_group_list.append(new_group)
        assert sorted(old_group_list, key=Group.id_or_max) == sorted(new_group_list, key=Group.id_or_max)
        if check_ui:
            print("Проверка пользовательского интерфейса")
            assert sorted(new_group_list, key=Group.id_or_max) == sorted(app.group.get_group_list(), key=Group.id_or_max)
Ejemplo n.º 11
0
def test_mod_group_name(app, orm, check_ui):
    if len(orm.get_group_list()) == 0:
        app.group.create_new(Group(name="NEW"))
    old_group_list = orm.get_group_list()
    new_group = Group(header="NEW NAME")
    mod_group = random.choice(old_group_list)
    new_group.id = mod_group.id
    if new_group.name is None:
        new_group.name = mod_group.name
    app.group.mod_group_by_id(new_group)
    new_group_list = orm.get_group_list()
    old_group_list.remove(mod_group)
    old_group_list.append(new_group)
    assert sorted(old_group_list,
                  key=Group.id_or_max) == sorted(new_group_list,
                                                 key=Group.id_or_max)
    if check_ui:
        print("Проверка пользовательского интерфейса")
        assert sorted(new_group_list, key=Group.id_or_max) == sorted(
            app.group.get_group_list(), key=Group.id_or_max)
def test_modify_some_group(app, orm, check_ui):
    if len(orm.get_group_list()) == 0:
        app.group.create_one_group()
    old_groups = orm.get_group_list()
    new_group = Group(header="Super Edited group header",
                      footer="Super Edited group footer")
    group_to_modify = random.choice(old_groups)
    new_group.id = group_to_modify.id
    if new_group.name is None:
        new_group.name = group_to_modify.name
    app.group.modify_group_by_id(new_group)
    new_groups = orm.get_group_list()
    old_groups.remove(group_to_modify)
    old_groups.append(new_group)
    assert sorted(old_groups,
                  key=app.utils.id_or_max) == sorted(new_groups,
                                                     key=app.utils.id_or_max)
    if check_ui:
        print('UI verification activated')
        assert sorted(new_groups, key=app.utils.id_or_max) == sorted(
            app.group.get_group_list(), key=app.utils.id_or_max)