def test_login_multiple_sessions(): auth_one = login(CONF.config["usmqe"]["username"], CONF.config["usmqe"]["password"]) auth_two = login(CONF.config["usmqe"]["username"], CONF.config["usmqe"]["password"]) logout(auth=auth_one) logout(auth=auth_two)
def test_login_multiple_sessions(): auth_one = login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password")) auth_two = login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password")) logout(auth=auth_one) logout(auth=auth_two)
def api_valid_credentials(): """ During setup phase, login default usmqe user account (username and password comes from usm.ini config file) and return requests auth object. Then during teardown logout the user to close the session. """ auth = login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password")) yield auth logout(auth=auth)
def valid_session_credentials(request): """ During setup phase, login default usmqe user account (username and password comes from usm.ini config file) and return requests auth object. Then during teardown logout the user to close the session. """ auth = login(CONF.config["usmqe"]["username"], CONF.config["usmqe"]["password"]) yield auth logout(auth=auth)
def test_login_invalid(): asserts = { "cookies": None, "ok": False, "reason": 'Unauthorized', "status": 401, } auth = login("invalid_user", "invalid_password", asserts_in=asserts) api = TendrlApi(auth) api.jobs(asserts_in=asserts)
def test_login_multiple_sessions_twisted(): asserts = { "cookies": None, "ok": False, "reason": 'Unauthorized', "status": 401, } api_one = TendrlApi(auth=login(CONF.config["usmqe"]["username"], CONF.config["usmqe"]["password"])) api_two = TendrlApi(auth=login(CONF.config["usmqe"]["username"], CONF.config["usmqe"]["password"])) api_one.jobs() api_two.jobs() logout(auth=api_one._auth) api_one.jobs(asserts_in=asserts) api_two.jobs() logout(auth=api_two._auth) api_one.jobs(asserts_in=asserts) api_two.jobs(asserts_in=asserts)
def test_login_multiple_sessions_twisted(): asserts = { "cookies": None, "ok": False, "reason": 'Unauthorized', "status": 401, } api_one = TendrlApi(auth=login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password"))) api_two = TendrlApi(auth=login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password"))) api_one.flows() api_two.flows() logout(auth=api_one._auth) api_one.flows(asserts_in=asserts) api_two.flows() logout(auth=api_two._auth) api_one.flows(asserts_in=asserts) api_two.flows(asserts_in=asserts)
def valid_new_user(valid_user_data): """ Create user from valid_user_data fixture and return these data. At the end remove this user. """ auth = login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password")) admin = tendrlapi_user.ApiUser(auth=auth) admin.add_user(valid_user_data) yield valid_user_data admin.del_user(valid_user_data["username"]) logout(auth=auth)
def delete_new_user(user_data): """ Delete user with given user_data. """ auth = login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password")) admin = tendrlapi_user.ApiUser(auth=auth) if user_data['email'].endswith( usmqe.inventory.role2hosts("usm_client")[0]): SSH = usmssh.get_ssh() node_connection = SSH[usmqe.inventory.role2hosts("usm_client")[0]] userdel = 'userdel {}'.format(user_data['username']) userdel_response = node_connection.run(userdel) # userdel command returned 0 return code assert userdel_response[0] == 0 admin.del_user(user_data["username"]) logout(auth=auth)
def delete_new_user(user_data): """ Delete user with given user_data. """ auth = login(CONF.config["usmqe"]["username"], CONF.config["usmqe"]["password"]) admin = tendrlapi_user.ApiUser(auth=auth) if user_data['email'].endswith( CONF.inventory.get_groups_dict()["usm_client"][0]): SSH = usmssh.get_ssh() node_connection = SSH[CONF.inventory.get_groups_dict()["usm_client"] [0]] userdel = 'userdel {}'.format(user_data['username']) userdel_response = node_connection.run(userdel) # userdel command returned 0 return code assert userdel_response[0] == 0 admin.del_user(user_data["username"]) logout(auth=auth)
def create_new_user(user_data): """ Create user from given user_data. """ auth = login(pytest.config.getini("usm_username"), pytest.config.getini("usm_password")) admin = tendrlapi_user.ApiUser(auth=auth) admin.add_user(user_data) if user_data['email'].endswith( usmqe.inventory.role2hosts("usm_client")[0]): SSH = usmssh.get_ssh() useradd = 'useradd {}'.format(user_data['username']) node_connection = SSH[usmqe.inventory.role2hosts("usm_client")[0]] node_connection.run(useradd) passwd = 'echo "{}" | passwd --stdin {}'.format( user_data['password'], user_data['username']) passwd_response = node_connection.run(passwd) # passwd command returned 0 return code assert passwd_response[0] == 0
def create_new_user(user_data): """ Create user from given user_data. """ auth = login(CONF.config["usmqe"]["username"], CONF.config["usmqe"]["password"]) admin = tendrlapi_user.ApiUser(auth=auth) admin.add_user(user_data) if user_data['email'].endswith( CONF.inventory.get_groups_dict()["usm_client"][0]): SSH = usmssh.get_ssh() useradd = 'useradd {}'.format(user_data['username']) node_connection = SSH[CONF.inventory.get_groups_dict()["usm_client"] [0]] node_connection.run(useradd) passwd = 'echo "{}" | passwd --stdin {}'.format( user_data['password'], user_data['username']) passwd_response = node_connection.run(passwd) # passwd command returned 0 return code assert passwd_response[0] == 0
def test_user_change_password(valid_new_normal_user, valid_password): """@pylatest api/user.edit API-users: edit user ******************* .. test_metadata:: author [email protected] Description =========== Change password and email of user and login with new password. """ auth = login(valid_new_normal_user["username"], valid_new_normal_user["password"]) test = tendrlapi_user.ApiUser(auth=auth) """@pylatest api/user.get .. test_step:: 1 Send **PUT** request to ``APIURL/users``. During this step is set email to `[email protected]` because user can not be edited if he does not have set email. (e.g. admin) .. test_result:: 1 Edited user data are returned. """ new_email = "*****@*****.**" edit_data = { "email": new_email, "password": valid_password, "password_confirmation": valid_password } test.edit_user(valid_new_normal_user["username"], edit_data) """@pylatest api/user.get .. test_step:: 2 Login Send **POST** request to ``APIURL/login``. .. test_result:: 2 User is logged with new credentials. """ logout(auth=auth) auth = login(valid_new_normal_user["username"], valid_password) test = tendrlapi_user.ApiUser(auth=auth) """@pylatest api/user.get .. test_step:: 3 Check if user have edited email. Send **GET** request to ``APIURL/users/{user}``. .. test_result:: 3 User information is checked if email was correctly changed. """ valid_new_normal_user["email"] = new_email test.check_user(valid_new_normal_user) logout(auth=auth)
def test_user_change_password_to_invalid(valid_new_normal_user, invalid_password): """@pylatest api/user.edit API-users: edit user ******************* .. test_metadata:: author [email protected] Description =========== Attempt to change password to invalid - either too long or too short. Checks on 8-symbol password and on an extremely long password fail due to bug https://bugzilla.redhat.com/show_bug.cgi?id=1610947 """ auth = login(valid_new_normal_user["username"], valid_new_normal_user["password"]) test = tendrlapi_user.ApiUser(auth=auth) """@pylatest api/user.get .. test_step:: 1 Send **PUT** request to ``APIURL/users``. During this step is set email to `[email protected]` because user can not be edited if he does not have set email. (e.g. admin) .. test_result:: 1 Error 422 Unprocessable Entity is returned. The response includes words "is too long" or "is too short" depending on the invalid password length. This check might fail due to https://bugzilla.redhat.com/show_bug.cgi?id=1610947 """ new_email = "*****@*****.**" edit_data = { "email": new_email, "password": invalid_password, "password_confirmation": invalid_password } asserts = {"ok": False, "reason": 'Unprocessable Entity', "status": 422} response = test.edit_user(valid_new_normal_user["username"], edit_data, asserts_in=asserts) if len(invalid_password) > 10: pass_length_error = "is too long" in str(response) else: pass_length_error = "is too short" in str(response) pytest.check(pass_length_error, issue='https://bugzilla.redhat.com/show_bug.cgi?id=1610947') """@pylatest api/user.get .. test_step:: 2 Check if the response to the request in test_step 1 returned the expected error. If it didn't, change the password back to original. .. test_result:: 2 User password is the same as it was before test_step 1 """ if not pass_length_error: edit_back_data = { "email": new_email, "password": valid_new_normal_user["password"], "password_confirmation": valid_new_normal_user["password"] } test.edit_user(valid_new_normal_user["username"], edit_back_data)