コード例 #1
0
def test_get_userInfo_validUser():
    print('Get user Information API test started')

    username = validUser
    url = BASE_URL + '/api/users/' + username
    action = 'GET'
    request_data = ''

    getUserInfo = ResponseMessage(url, action, request_data)

    assert getUserInfo.get_response_statuscode(
    ) != 401, 'Authentication failed'

    assert getUserInfo.get_response_statuscode() == 200, 'API call failed'

    assert getUserInfo.get_status() == 'SUCCESS', 'Message request failed'

    firstname = getUserInfo.get_first_name()

    assert firstname == validFirstName, 'Validation failed for firstname : Expected = ' + validFirstName + ', found = ' + firstname

    lastname = getUserInfo.get_last_name()

    assert lastname == validLastName, 'Validation failed for lastname : Expected = ' + validLastName + ', found = ' + lastname

    phone = getUserInfo.get_phone()

    assert phone == validPhone, 'Validation failed for phone : Expected = ' + validPhone + ', found = ' + phone

    print('Get user Information API tested successfully')
コード例 #2
0
def test_get_users():
    print('Get users API test started')

    url = BASE_URL + '/api/users'
    action = 'GET'
    request_data = ''

    getUsers = ResponseMessage(url, action, request_data)

    assert getUsers.get_response_statuscode() == 200, 'API call failed'

    assert getUsers.get_status() == 'SUCCESS', 'Message request failed'

    assert (getUsers.get_payload().__sizeof__() >= 0), 'No users found'

    print('Get users API tested successfully')
コード例 #3
0
def test_get_userInfo_invalidUser():
    print('Get user Information API test started')

    username = inValidUser
    url = BASE_URL + '/api/users/' + username
    action = 'GET'
    request_data = ''

    getUserInfo =  ResponseMessage(url,action,request_data)
    
    assert getUserInfo.get_response_statuscode()  != 401, 'Authentication failed'
    
    assert getUserInfo.get_response_statuscode() == 404, 'Incorrect status code received'
    
    assert getUserInfo.get_status() == 'FAILURE', 'Incorrect status response received'
    
    print('Get user Information API tested successfully')
コード例 #4
0
def test_put_userInfo_emptyRequest():
    print('Update user Information API test started')

    username = validUser
    url = BASE_URL + '/api/users/' + username
    action = 'PUT'

    request_data = json.loads(updateUserData4)

    updateUserInfo = ResponseMessage(url, action, request_data)

    assert updateUserInfo.get_response_statuscode(
    ) != 401, 'Authentication failed'

    assert updateUserInfo.get_response_statuscode(
    ) == 403, 'Incorrect HTTP status code received'

    assert updateUserInfo.get_message(
    ) == 'Field update not allowed', 'Incorrect response message received'

    assert updateUserInfo.get_status(
    ) == 'FAILURE', 'Incorrect status response received'

    print('Update user information API tested successfully')
def test_put_userInfo_InvalidUser_completeData():
    print('Update user Information API test started')
    
    username = validUser
    url = BASE_URL + '/api/users/' + inValidUser
    action = 'PUT'
    
    request_data = json.loads(updateUserData1);
    updatedFirstName = request_data['firstname']
    updatedLastName = request_data['lastname']
    updatedPhone = request_data['phone']
    
    updateUserInfo = ResponseMessage(url,action,request_data)
    
    assert updateUserInfo.get_response_statuscode()  != 401, 'Authentication failed'
    
    assert updateUserInfo.get_response_statuscode() == 403, 'API call failed'
    
    assert updateUserInfo.get_message() == 'Updated', 'Message update failed'
    
    assert updateUserInfo.get_status() == 'SUCCESS', 'Message update failed'
    
    #Validate if the data is updated correctly
    url = BASE_URL + '/api/users/' + username
    action = 'GET'
    request_data = ''
    
    updateUserInfo = ResponseMessage(url,action,request_data)
    
    assert updateUserInfo.get_response_statuscode() == 200, 'API call failed'
    
    firstname = updateUserInfo.get_first_name()
    
    assert firstname == updatedFirstName, 'Validation failed for firstname : Expected = ' + updatedFirstName +', found = ' + firstname
    
    lastname = updateUserInfo.get_last_name()
    
    assert lastname == updatedLastName, 'Validation failed for lastname : Expected = ' + updatedLastName +', found = ' + lastname
    
    phone = updateUserInfo.get_phone()
    
    assert phone == updatedPhone, 'Validation failed for phone : Expected = ' + updatedPhone +', found = ' + phone
    
    print('Update user information API tested successfully')