Example #1
0
def listusers_get():
    """
    List users
    Get all the users 

    :rtype: List[User]
    """
    u1 = User("foo")
    u2 = User("bar")
    return [u1, u2]
def users_get():  # noqa: E501
    """List all API users created by the administrator. One of the users is flagged as the administrator; that is the very first user created and may not be deleted.

     # noqa: E501


    :rtype: List[User]
    """
    response = service.users.read_all()
    output = [User().from_dict(doc) for doc in response]
    return output
    def test_create_user(self, *_):
        """Test case for create_user


        """
        user = User(email="*****@*****.**", password="******")
        response = self.client.open('/api/v1/user/create',
                                    method='POST',
                                    data=json.dumps(user),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_create_user(self):
        """Test case for create_user

        Crea un nuevo usuario en el sistema
        """
        body = User()
        response = self.client.open('/javierrome/PlatformAPI/1.0.0/user',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Example #5
0
    def test_add_user(self):
        """Test case for add_user

        Add a new user to the validator Application
        """
        body = User()
        response = self.client.open('/validator/users',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_user_create(self):
        """Test case for user_create

        
        """
        name = User()
        response = self.client.open('//users/',
                                    method='POST',
                                    data=json.dumps(name),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_create_user(self):
        """Test case for create_user

        Create user
        """
        body = User()
        response = self.client.open('/user',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_create_users_with_list_input(self):
        """Test case for create_users_with_list_input

        Creates list of users with given input array
        """
        body = [User()]
        response = self.client.open('/user/createWithList',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_update_user(self):
        """Test case for update_user

        Updated user
        """
        body = User()
        response = self.client.open('/vcalendar/user/{id}'.format(id=789),
                                    method='PUT',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_users_id_patch(self):
        """Test case for users_id_patch

        Edit a user's information; at the moment of writing, its pass.
        """
        body = User()
        response = self.client.open(
            '/api/v2/users/{id}'.format(id='id_example'),
            method='PATCH',
            data=json.dumps(body),
            content_type='application/nl.kpmg.v2.user+json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_user_username_put(self):
        """Test case for user_username_put

        Updated user
        """
        body = User()
        response = self.client.open(
            '/user/{username}'.format(username='******'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Example #12
0
    def test_users_post(self):
        """Test case for users_post

        Create a new user
        """
        body = User()
        response = self.client.open(
            '/v1/users',
            method='POST',
            data=json.dumps(body),
            content_type='application/nl.kpmg.v1.user+json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Example #13
0
    def test_users_username_put(self):
        """Test case for users_username_put

        Re-upload user's information
        """
        body = User()
        response = self.client.open(
            '/v1/users/{username}'.format(username='******'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/nl.kpmg.v1.user+json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_subsidies_id_actions_approve_post(self):
        """Test case for subsidies_id_actions_approve_post

        Approve a subsidy
        """
        body = User()
        response = self.client.open(
            '/v1/subsidies/{id}/actions/approve'.format(id='id_example'),
            method='POST',
            data=json.dumps(body),
            content_type='application/nl.kpmg.v1.user+json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_edit_case_file(self):
        """Test case for edit_case_file

        Changes the properties of a specific case file
        """
        body = User()
        response = self.client.open(
            '/api/case-file/uuid/{UUID}'.format(UUID='UUID_example'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Example #16
0
    def test_login_post(self):
        """Test case for login_post

        Login a user; this a virtual endpoint to just confirm the user exists. Also important to see whether a user is an admin or not.
        """
        body = User()
        response = self.client.open(
            '/api/v2/login',
            method='POST',
            data=json.dumps(body),
            content_type='application/nl.kpmg.v2.user+json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_update_user(self):
        """Test case for update_user

        Actualiza los datos del usuario
        """
        body = User()
        response = self.client.open(
            '/javierrome/PlatformAPI/1.0.0/user/{username}'.format(
                username='******'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
def get_user_by_name(username):  # noqa: E501
    """Obtiene el usuario por el nombre de usuario

     # noqa: E501

    :param username: nombre de usuario
    :type username: str

    :rtype: User
    """
    collection = db.user
    u = collection.find_one({'username': str(username)})
    return User(u['id'], u['username'], u['firstName'], u['lastName'],
                u['email'], u['password'], u['phone'])
    def test_set_user_by_key(self):
        """
        Test case for set_user_by_key

        通过连接句柄设置控制器中的用户数据
        """
        user = User()
        response = self.client.open(
            '/v1/data/user/{deviceKey}'.format(deviceKey=789),
            method='PUT',
            data=json.dumps(user),
            content_type='application/x-www-form-urlencoded')
        self.assert200(response,
                       "Response body is : " + response.data.decode('utf-8'))
    def test_update_user(self):
        """Test case for update_user

        Updates users
        """
        body = User()
        response = self.client.open(
            '/Erraticturtle35/Tantakatu/1.0.0/users/{username}'.format(
                username='******'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_create_group(self):
        """
        Test case for create_group

        Add a new group to game
        """
        user = [User()]
        response = self.client.open(
            '/matchmaking/1.0.0/matchmacking/CreateGroup',
            method='POST',
            data=json.dumps(user),
            content_type='application/json')
        self.assert200(response,
                       "Response body is : " + response.data.decode('utf-8'))
Example #22
0
def get_user_bykey(key, userID):
    if key in connects:
        conp = connects[key]
        hd = conp['hd']
        sBuf = create_string_buffer(512 * 1024)
        sTableName = bytes('user', encoding="utf8")
        sFieldNames = bytes('Pin\tCardNo\tPassword', encoding="utf8")
        sFilters = bytes('Pin={}'.format(userID), encoding="utf8")
        sOptions = bytes('', encoding="utf8")
        re = dll.GetDeviceData(hd, sBuf, 512 * 1024,
                               sTableName, sFieldNames, sFilters, sOptions)
        if re < 1: 
            return -3, re

        st = str(sBuf.value)[2:-1]
        va = st.split("\\r\\n")[1].split(',')
        user = User(va[0],'',va[2],int(va[1]))

        sBuf = create_string_buffer(128 * 1024)
        sTableName = bytes('userauthorize', encoding="utf8")
        sFieldNames = bytes('Pin\tAuthorizeTimezoneId\tAuthorizeDoorId', 
                                encoding="utf8")
        reAuthorize = dll.GetDeviceData(hd, sBuf, 128 * 1024,
                               sTableName, sFieldNames, sFilters, sOptions)
        if reAuthorize > 0:
            st = str(sBuf.value)[2:-1]
            va = st.split("\\r\\n")[1].split(',')
            vi = int(va[2])
            user.authorize = [(vi & 1) > 0, (vi & 2) > 0,
                              (vi & 4) > 0, (vi & 8) > 0]
        
        sBuf = create_string_buffer(1 * 1024 * 1024)
        sTableName = bytes('templatev10', encoding="utf8")
        sFieldNames = bytes('Pin\tSize\tFingerID\tValid\tTemplate',
                            encoding="utf8")
        reTemplate = dll.GetDeviceData(hd, sBuf, 1024 * 1024,
                                        sTableName, sFieldNames, sFilters, sOptions)
        if reTemplate > 0:
            st = str(sBuf.value)[2:-1]
            la = st.split("\\r\\n")[1:-1]
            user.finger = []
            for l in la:
                va = l.split(',')
                user.finger.append(UserFinger(int(va[2]), int(
                    va[1]), int(va[3]) == 3, va[4]))

        return 1, user
    else:
        return -4, None
    def test_login_user(self, *_):
        """Test case for login_user


        """
        mock_db.DB = {
            "*****@*****.**": {
                'password': "******",
                'confirmed': True
            }
        }
        user = User(email="*****@*****.**", password="******")
        response = self.client.open('/api/v1/user/login',
                                    method='POST',
                                    data=json.dumps(user),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Example #24
0
def get_all_users():  # noqa: E501
    """Get all users on email server

     # noqa: E501


    :rtype: List[User]
    """
    bots_r = redis.StrictRedis(host='localhost', port=6379, db=2)
    deactivated_bots_r = redis.StrictRedis(host='localhost', port=6379, db=3)
    ## Not sure if this will work on all email implementations. 
    ## Needs location of mailboxes on server, and permission to access that location
    users = []
    domains = os.listdir('{}/mailboxes'.format(mail_home))
    for domain in domains:
        temp_users = os.listdir('{}/mailboxes/{}/'.format(mail_home, domain))
        for name in temp_users:
            users.append("{}@{}".format(name, domain).encode('utf-8'))
    # Get bots to exclude, we only want to return real users
    bots = []
    for key in bots_r.scan_iter():
        bots.append(key)
    # also exclude deactivated bots
    for key in deactivated_bots_r.scan_iter():
        bots.append(key)
    users = list(set(users) - set(bots))
    # Decode from bytes to string for JSON encoding
    decoded_users = [User(email_address = x.decode('utf-8')) for x in users]
    # Get first and last names
    conn = sql.connect("{}/user_names.sqlite".format(mail_home))
    cur = conn.cursor()
    for i in range(0, len(decoded_users)):
        try:
            decoded_users[i].first_name = cur.execute("select first_name from names where email = {}".format(decoded_users[i].email_address)).fetchone()[0]
            decoded_users[i].last_name = cur.execute("select last_name from names where email = {}".format(decoded_users[i].email_address)).fetchone()[0]
        except:
            logging.warning("No first or last name found for {}".format(decoded_users[i].email_address))
    cur.close()
    conn.close()

    logging.info("Returned list of users")
    
    return decoded_users
    def test_update_user(self):
        """Test case for update_user

        Updated user
        """
        self.test_create_user()
        body = User(id=1,
                    username="******",
                    first_name="user1",
                    last_name="user1",
                    email="user_update",
                    password="******")
        response = self.client.open(
            '/v1/user/{username}'.format(username='******'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/json',
            headers={'Cookie': 'Autorization=' + getcookie(login_creds)})
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Example #26
0
    def test_create_user(self):
        """Test case for create_user

        Create user
        """
        body = User()
        data = dict(id=789,
                    username='******',
                    first_name='first_name_example',
                    last_name='last_name_example',
                    email='email_example',
                    password='******',
                    phone='phone_example',
                    user_status=56)
        response = self.client.open('/user',
                                    method='POST',
                                    data=json.dumps(body),
                                    data=data,
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_create_user(self):
        """Test case for create_user

        Create user
        """
        body = User(id=1,
                    username="******",
                    first_name="user1",
                    last_name="user1",
                    email="user1",
                    password="******")
        response = self.client.open(
            '/v1/user',
            method='POST',
            data=json.dumps(body),
            content_type='application/json',
            headers={'Cookie': 'Autorization=' + getcookie(login_creds)})
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
        logging.info("create")
        logging.info(
            "create" +
            str(globals.db_session.query(orm.Userinfo).all()[0].dao_username))
Example #28
0
def get_job_by_id(job_id, access_token):  # noqa: E501
    """Finds job by ID

    Returns a single job # noqa: E501

    :param job_id: ID of job to return
    :type job_id: int
    :param access_token: Access token
    :type access_token: str

    :rtype: job
    """

    user = User()
    user_info = user.validate_user(access_token)
    if not(user_info[0]):
        error_code = 401
        error_message = {
          "detail": "You are not authorized to use this API.",
          "status": error_code,
          "title": "Unauthorized",
          "type": "about:blank"
        }
        return error_message, error_code

    userId = user_info[1]
    if not(userId.isdigit()):
        error_code = 405
        error_message = {
            "detail": 'Invalid input, please provide valid userId.',
            "status": error_code,
            "title": "Invalid input",
            "type": "about:blank"
        }
        return error_message, error_code

    if not(str(job_id).isdigit()):
        error_code = 405
        error_message = {
            "detail": 'Invalid input, please provide valid job_id.',
            "status": error_code,
            "title": "Invalid input",
            "type": "about:blank"
        }
        return error_message, error_code

    job = Job()
    cox = job.connect()
    if cox != '':
        error_code = 500
        error_message = {
            "detail": cox,
            "status": error_code,
            "title": "Internal Server Error",
            "type": "about:blank"
        }
        return error_message, error_code

    row = []
    try:
        row = job.get_job(job_id, userId)
        job.close()
    except Exception as e: # work on python 3.x
        error_code = 500
        error_message = {
            "detail": 'Error in getting job from database: '+str(e),
            "status": error_code,
            "title": "Internal Server Error",
            "type": "about:blank"
        }
        return error_message, error_code

    if len(row) == 1:
        row = row[0]
        my_result = {
            "jobId": row[0],
            "hpcJobId": row[1],
            "operation": row[2],
            "userId": row[3],
            "name": row[4],
            "commands": json.loads(row[5]),
            "jobMetaData": json.loads(row[6]),
            "created": row[7],
            "updated": row[8],
            "result": row[9],
            "log": row[10],
            "status": row[11]
        }

        if connexion.request.is_json:
            return my_result
        else:
            return my_result
    else:
        error_code = 404
        error_message = {
          "detail": "job with jobId " + str(job_id) + " not found.",
          "status": error_code,
          "title": "Not found",
          "type": "about:blank"
        }
        return error_message, error_code
Example #29
0
def update_job(body, job_id, access_token):  # noqa: E501
    """Updates an existing job

     # noqa: E501

    :param body: job object that needs to be added
    :type body: dict | bytes
    :param job_id: ID of job to return
    :type job_id: int
    :param access_token: Access token
    :type access_token: str

    :rtype: job
    """
    
    user = User()
    user_info = user.validate_user(access_token)
    if not(user_info[0]):
        error_code = 401
        error_message = {
          "detail": "You are not authorized to use this API.",
          "status": error_code,
          "title": "Unauthorized",
          "type": "about:blank"
        }
        return error_message, error_code

    userId = user_info[1]
    if not(userId.isdigit()):
        error_code = 405
        error_message = {
            "detail": 'Invalid input, please provide valid userId.',
            "status": error_code,
            "title": "Invalid input",
            "type": "about:blank"
        }
        return error_message, error_code

    if not(str(job_id).isdigit()):
        error_code = 405
        error_message = {
            "detail": 'Invalid input, please provide valid job_id.',
            "status": error_code,
            "title": "Invalid input",
            "type": "about:blank"
        }
        return error_message, error_code

    '''
    if connexion.request.is_json:
        body = job.from_dict(connexion.request.get_json())  # noqa: E501
    '''

    job = Job()
    cox = job.connect()
    if cox != '':
        error_code = 500
        error_message = {
            "detail": cox,
            "status": error_code,
            "title": "Internal Server Error",
            "type": "about:blank"
        }
        return error_message, error_code

    try:
        row = job.get_job(job_id, userId)
    except Exception as e: # work on python 3.x
        error_code = 500
        error_message = {
            "detail": 'Error in getting job from database: '+str(e),
            "status": error_code,
            "title": "Internal Server Error",
            "type": "about:blank"
        }
        return error_message, error_code

    if len(row) == 1:

        if not('error' in body['jobMetaData'] and 'output' in body['jobMetaData']):
            error_code = 405
            error_message = {
                "detail": 'Invalid input',
                "status": error_code,
                "title": "Invalid input",
                "type": "about:blank"
            }
            return error_message, error_code

        if not(isinstance(body['commands'], list)):
            error_code = 405
            error_message = {
                "detail": 'Invalid input, please provide commands as list',
                "status": error_code,
                "title": "Invalid input",
                "type": "about:blank"
            }
            return error_message, error_code

        hpc_cout = 0
        for cmd in body['commands']:
            if not('subJobType' in cmd and 'parameters' in cmd):
                error_code = 405
                error_message = {
                    "detail": 'Invalid input, please provide subJobType and parameters in commands',
                    "status": error_code,
                    "title": "Invalid input",
                    "type": "about:blank"
                }
                return error_message, error_code
            if cmd['subJobType'] == 'hpc':
                    hpc_cout = hpc_cout + 1
            if hpc_cout > 1:
                error_code = 405
                error_message = {
                    "detail": 'Invalid input, please provide only one subJobType=hpc in commands',
                    "status": error_code,
                    "title": "Invalid input",
                    "type": "about:blank"
                }
                return error_message, error_code


        body['jobMetaData'] = json.dumps(body['jobMetaData'])
        body['commands'] = json.dumps(body['commands'])

        if job.update_job_status(row[0][11], body['status']):
            try:
                job.update_job(job_id, body)
                job.close()
            except Exception as e: # work on python 3.x
                error_code = 500
                error_message = {
                    "detail": 'Error in updating job into database: '+str(e),
                    "status": error_code,
                    "title": "Internal Server Error",
                    "type": "about:blank"
                }
                return error_message, error_code
            
            body['jobId'] = job_id
            body['jobMetaData'] = json.loads(body['jobMetaData'])
            body['commands'] = json.loads(body['commands'])
            return body
        else:
            error_code = 409
            error_message = {
              "detail": "job with jobId " + str(job_id) + " cannot be updated with this status.",
              "status": error_code,
              "title": "job cannot updated",
              "type": "about:blank"
            }
            return error_message, error_code
    else:
        error_code = 404
        error_message = {
          "detail": "job with jobId " + str(job_id) + " not found.",
          "status": error_code,
          "title": "Not found",
          "type": "about:blank"
        }
        return error_message, error_code
Example #30
0
def update_job_by_operation(job_id, operation, access_token):  # noqa: E501
    """Updates operation of an existing job

     # noqa: E501

    :param job_id: name that need to be updated
    :type job_id: int
    :param operation: job Operation
    :type operation: str
    :param access_token: Access token
    :type access_token: str

    :rtype: job
    """

    user = User()
    user_info = user.validate_user(access_token)
    if not(user_info[0]):
        error_code = 401
        error_message = {
          "detail": "You are not authorized to use this API.",
          "status": error_code,
          "title": "Unauthorized",
          "type": "about:blank"
        }
        return error_message, error_code

    userId = user_info[1]
    if not(userId.isdigit()):
        error_code = 405
        error_message = {
            "detail": 'Invalid input, please provide valid userId.',
            "status": error_code,
            "title": "Invalid input",
            "type": "about:blank"
        }
        return error_message, error_code

    if not(str(job_id).isdigit()):
        error_code = 405
        error_message = {
            "detail": 'Invalid input, please provide valid job_id.',
            "status": error_code,
            "title": "Invalid input",
            "type": "about:blank"
        }
        return error_message, error_code

    job = Job()
    cox = job.connect()
    if cox != '':
        error_code = 500
        error_message = {
            "detail": cox,
            "status": error_code,
            "title": "Internal Server Error",
            "type": "about:blank"
        }
        return error_message, error_code

    if operation != 'queue' or operation != 'abort':
        error_code = 405
        error_message = {
            "detail": 'Operation must be "abort"',
            "status": error_code,
            "title": "Invalid input",
            "type": "about:blank"
        }
        return error_message, error_code


    try:
        row = job.get_job(job_id, userId)
    except Exception as e: # work on python 3.x
        error_code = 500
        error_message = {
            "detail": 'Error in getting job from database: '+str(e),
            "status": error_code,
            "title": "Internal Server Error",
            "type": "about:blank"
        }
        return error_message, error_code

    if len(row) == 1:

        if job.operate_job_status(status, operation):
            try:
                job.update_job_operation(job_id, operation)
                job.close()
            except Exception as e: # work on python 3.x
                error_code = 500
                error_message = {
                    "detail": 'Error in updating job into database: '+str(e),
                    "status": error_code,
                    "title": "Internal Server Error",
                    "type": "about:blank"
                }
                return error_message, error_code

            row = row[0]
            my_result = {
                "jobId": row[0],
                "hpcJobId": row[1],
                "operation": operation,
                "userId": row[3],
                "name": row[4],
                "commands": json.loads(row[5]),
                "jobMetaData": json.loads(row[6]),
                "created": row[7],
                "updated": row[8],
                "result": row[9],
                "log": row[10],
                "status": row[11]
            }

            if connexion.request.is_json:
                return my_result
            else:
                return my_result
        else:
            error_code = 409
            error_message = {
              "detail": "job with jobId " + str(job_id) + " cannot be aborted because status needs to be hpc_queued or hpc_in_progress.",
              "status": error_code,
              "title": "job cannot deleted",
              "type": "about:blank"
            }
            return error_message, error_code
    else:
        error_code = 404
        error_message = {
          "detail": "job with jobId " + str(job_id) + " not found.",
          "status": error_code,
          "title": "Not found",
          "type": "about:blank"
        }
        return error_message, error_code