How to use get_user_name_id method in autotest

Best Python code snippet using autotest_python

service_helper.py

Source:service_helper.py Github

copy

Full Screen

...23 pidfh = open(pidfile, 'w')24 proc = subprocess.Popen(cmd, stdout=logfh, stderr=logfh, cwd=chdir)25 pidfh.write(str(proc.pid))26 pidfh.close()27def get_user_name_id(user):28 """29 Get the user id # and name.30 @param user: integer or string containing either the uid #31 or a string username32 @returns a tuple of the user name, user id33 """34 if re.match('\d+', str(user)):35 pass_info = pwd.getpwuid(user)36 else:37 pass_info = pwd.getpwnam(user)38 return pass_info[0], pass_info[2]39def get_group_name_id(group):40 """41 Get the group id # and name42 @param group: integer or string containing either the uid #43 or a string username44 @returns a tuple of group name, group id45 """46 if re.match('\d+', str(group)):47 group_info = grp.getgrgid(group)48 else:49 group_info = grp.getgrnam(group)50 return group_info[0], group_info[2]51def set_group_user(group=None, user=None):52 """53 Set the group and user id if gid or uid is defined.54 @param group: Change the group id the program is run under55 @param user: Change the user id the program is run under56 """57 if group:58 _, gid = get_group_name_id(group)59 os.setgid(gid)60 os.setegid(gid)61 if user:62 username, uid = get_user_name_id(user)63 # Set environment for programs that use those to find running user64 for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):65 os.environ[name] = username66 os.setuid(uid)67 os.seteuid(uid)68def main():69 parser = optparse.OptionParser()70 parser.allow_interspersed_args = False71 parser.add_option('-l', '--logfile', action='store',72 default=None,73 help='File to redirect stdout to')74 parser.add_option('-c', '--chdir', action='store',75 default=None,76 help='Change to dir before starting the process')...

Full Screen

Full Screen

task-8.py

Source:task-8.py Github

copy

Full Screen

...3import argparse4def get_person_friends(user_id, token, version):5 if not user_id.isdigit():6 try:7 user_id = get_user_name_id(user_id, token, version)8 except KeyError:9 raise ValueError("User doesn't exist!")10 person_friends = (f'https://api.vk.com/method/friends.get?user_id={user_id}'11 f'&order=name&fields=nickname,domain'12 f'&access_token={token}'13 f'&v={version}')14 try:15 return api_request(person_friends)['response']16 except KeyError:17 raise KeyError(f"{api_request(person_friends)['error']['error_msg']}")18def get_user_name_id(name, token, version):19 name_id = (f'https://api.vk.com/method/users.get?user_id={name}'20 f'&access_token={token}'21 f'&v={version}')22 return api_request(name_id)['response'][0]['id']23def api_request(request_message):24 return json.loads(urlopen(Request(request_message)).read())25def start_app():26 parser = argparse.ArgumentParser()27 parser.add_argument('--userid', required=True, help='user id')28 parser.add_argument('--token', required=True, help='your token')29 args_parser = parser.parse_args()30 api_response = get_person_friends(args_parser.userid, args_parser.token, '5.131')['items']31 with open('../resources-8/response.txt', 'w', encoding='utf-8') as file:32 file.write('\n'.join([f"{person['first_name']} {person['last_name']}" for person in api_response]))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful