Exemple #1
0
 def test_update_new_username(self):
     # update to a new username
     before = User(**updated_user1)
     before.username = '******'
     AccountManager.update_user(user1['username'], before)
     after = get_user(before.username)
     self.assertDictEqual(after.to_dict(), before.to_dict())
Exemple #2
0
    def post():
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        data, errors = user_create_request_schema.load(json_data)
        if errors:
            return errors, 422
        from AccountManager.account_manager import AccountManager

        if "filepath" in data:
            results = AccountManager.create_groups(data["group_count"],
                                                   data["users_per_group"],
                                                   data["filepath"])
        else:
            results = AccountManager.create_groups(data["group_count"],
                                                   data["users_per_group"])

        if results:
            return group_response_schema.dump({"success": results})
        else:
            return {"success": False}, 409
Exemple #3
0
    def delete():
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        data, errors = group_delete_request_schema.load(json_data)

        if errors:
            return errors, 422

        from AccountManager.account_manager import AccountManager
        errors = []
        for group in data['list_of_groups']:
            try:
                AccountManager.delete_group(group)
            except ValueError as e:
                errors.append("Error deleting group " + group + ": " + str(e))
        if errors:
            print(errors)
            return {"success": False, "errors": errors}, 200

        return {"success": True}, 200
Exemple #4
0
    def delete():
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        data, errors = user_delete_request_schema.load(json_data)

        if errors:
            return errors, 422

        from AccountManager.account_manager import AccountManager

        errors = []
        for user in data['list_of_users']:
            # try:
            #     AccountManager.delete_user(user)
            # except ValueError as e:
            #     errors.append("Error deleting user " + user + ": " + str(e))
            AccountManager.delete_user(user)
        if errors:
            print(errors)
            return {"success": False, "errors": errors}, 200

        return {"success": True}, 200
Exemple #5
0
    def put():
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        data, errors = user_update_request_schema.load(json_data)

        if errors:
            return errors, 422

        username = data["username"]
        updated_user = data["updated_user"]

        from AccountManager.account_manager import AccountManager
        results = AccountManager.update_user(username, updated_user)
        if results:
            return user_response_schema.dump({"success": results})
        else:
            return {"success": results}, 404
Exemple #6
0
 def tearDown(self):
     AccountManager.delete_user('updated_username')
     AccountManager.delete_user(user2['username'])
     AccountManager.delete_user(user1['username'])
Exemple #7
0
 def test_group_delete(self):
     self.assertTrue(AccountManager.delete_group(1000))
Exemple #8
0
 def test_update_nonexistent(self):
     self.assertFalse(
         AccountManager.update_user('notauser', User(**bare_user)))
Exemple #9
0
 def test_update_invalid_param(self):
     self.assertFalse(AccountManager.update_user(5, User('user')))
Exemple #10
0
    def put():
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400

        data, errors = group_update_request_schema.load(json_data)

        if errors:
            return errors, 422
        from AccountManager.account_manager import AccountManager

        results = False
        if "command" in data and "platform_ids" in data:
            if data["command"] == "attach":
                for plat in data["platform_ids"]:
                    results = AccountManager.attach_platform(
                        data["group_id"], plat)
                    if not results:
                        print("Failed to attach {} to group {}".format(
                            plat, data["group_id"]))
                        continue

                    plat_info = DatabaseHandler.find('platforms', plat)
                    for current in plat_info['subplatforms']:
                        if 'Rocketchat' == current['name']:
                            platform_man = PlatformManagerInstance.get_instance(
                            )
                            # running = platform_man.getPlatformStatus(plat_info['main']['id'], current['id'])
                            running = True
                            if not running:
                                platform_man.platform_interface.startPlatform(
                                    plat_info['main']['id'], current['id'])

                            group_info = DatabaseHandler.find(
                                'groups', data["group_id"])
                            command = {'command': 'registerUser', 'param': {}}
                            for user in group_info['members']:
                                command['param']['username'] = user
                                command['param'][
                                    'email'] = user + "@citsystem.com"
                                user_info = DatabaseHandler.find('users', user)
                                command['param']['password'] = user_info[
                                    'password']
                                success, user_id = platform_man.platform_interface.requestHandler(
                                    plat_info['main']['id'], current['id'],
                                    command)
                                if not success:
                                    print("ERROR: Unable to register user: "******"command"] == "detach":
                results = AccountManager.detach_platform(data["platform_id"])
        else:
            results = AccountManager.update_group(data["group_id"],
                                                  data["updated_group"])

        if results:
            return group_response_schema.dump({"success": results})
        else:
            return {"success": False}, 409
Exemple #11
0
 def test_username_taken(self):
     self.assertFalse(
         AccountManager.update_user(user1['username'], User(**user2)))
Exemple #12
0
 def setUp(self):
     global start_id
     start_id = get_next_id()
     AccountManager.create_groups(1, 2)
Exemple #13
0
 def test_update_nonexistent(self):
     self.assertFalse(
         AccountManager.update_group(102, Group(**updated_group)))
Exemple #14
0
 def test_deleted_prev(self):
     # update to a new username
     user = User(**updated_user1)
     user.username = '******'
     AccountManager.update_user(user1['username'], user)
     self.assertIsNone(get_user(user1['username']))
Exemple #15
0
 def test_create_groups(self):
     global start_id
     start_id = get_next_id()
     self.assertTrue(AccountManager.create_groups(group_count, user_count))
Exemple #16
0
 def tearDown(self):
     for i in range(group_count):
         AccountManager.delete_group(start_id + i)
Exemple #17
0
 def test_import(self):
     with open(test_filepath, 'w') as f:
         f.writelines(file_content)
     self.assertTrue(AccountManager.create_groups(filepath=test_filepath))
Exemple #18
0
 def tearDown(self):
     for line in file_users:
         current = get_user(line[0]).group_id
         AccountManager.delete_group(current)
Exemple #19
0
 def test_delete_user(self):
     AccountManager.delete_user(user1['username'])
     self.assertIsNone(get_user(user1['username']))
Exemple #20
0
 def test_group_delete(self):
     AccountManager.delete_group(1000)
     self.assertIsNone(get_group(1000))
Exemple #21
0
 def tearDown(self):
     AccountManager.delete_group(start_id)
Exemple #22
0
 def tearDown(self):
     self.assertTrue(AccountManager.delete_user(user1['username']))
     self.assertTrue(AccountManager.delete_user(user2['username']))
Exemple #23
0
 def test_change_id(self):
     self.assertFalse(
         AccountManager.update_group(start_id, Group(**updated_group)))
Exemple #24
0
 def test_update_user(self):
     # update everything but keep the username
     AccountManager.update_user(user1['username'], User(**updated_user1))
     user = get_user(user1['username']).to_dict()
     self.assertDictEqual(user, updated_user1)