Best Python code snippet using localstack_python
test_iam_groups.py
Source:test_iam_groups.py
...100@mock_iam101def test_attach_group_policies():102 conn = boto3.client("iam", region_name="us-east-1")103 conn.create_group(GroupName="my-group")104 conn.list_attached_group_policies(GroupName="my-group")[105 "AttachedPolicies"106 ].should.be.empty107 policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforEC2Role"108 conn.list_attached_group_policies(GroupName="my-group")[109 "AttachedPolicies"110 ].should.be.empty111 conn.attach_group_policy(GroupName="my-group", PolicyArn=policy_arn)112 conn.list_attached_group_policies(GroupName="my-group")[113 "AttachedPolicies"114 ].should.equal(115 [{"PolicyName": "AmazonElasticMapReduceforEC2Role", "PolicyArn": policy_arn}]116 )117 conn.detach_group_policy(GroupName="my-group", PolicyArn=policy_arn)118 conn.list_attached_group_policies(GroupName="my-group")[119 "AttachedPolicies"120 ].should.be.empty121@mock_iam_deprecated()122def test_get_group_policy():123 conn = boto.connect_iam()124 conn.create_group("my-group")125 with pytest.raises(BotoServerError):126 conn.get_group_policy("my-group", "my-policy")127 conn.put_group_policy("my-group", "my-policy", MOCK_POLICY)128 conn.get_group_policy("my-group", "my-policy")129@mock_iam_deprecated()130def test_get_all_group_policies():131 conn = boto.connect_iam()132 conn.create_group("my-group")...
AWS-IAM_test.py
Source:AWS-IAM_test.py
...37 def list_user_policies(self):38 pass39 def list_attached_user_policies(self):40 pass41 def list_attached_group_policies(self):42 pass43 def get_login_profile(self):44 pass45@pytest.mark.parametrize('args, res', PAGINATION_CHECK)46def test_list_user_policies(mocker, args, res):47 """48 Given:49 - user_name - user name to retrieve policies for.50 - pagination args - combination of marker, limit, page and page_size args in order to control pagination.51 When:52 - After running a list_user_policies command53 Then:54 - Ensure that the returned list includes only the policies the user posses.55 """56 response = {57 'PolicyNames': [58 'AllAccessPolicy',59 'KeyPolicy'60 ],61 'IsTruncated': True,62 'Marker': '111'63 }64 policy_data = []65 for policy in res:66 policy_data.append({67 'UserName': 'test',68 'PolicyName': policy,69 })70 mocker.patch.object(AWSClient, "aws_session", return_value=Boto3Client())71 mocker.patch.object(Boto3Client, "list_user_policies", return_value=response)72 mocker.patch.object(demisto, 'results')73 client = AWSClient()74 AWS_IAM.list_user_policies(args, client)75 contents = demisto.results.call_args[0][0]76 assert 'AWS IAM Policies for user test' in contents.get('HumanReadable')77 assert policy_data in contents.get('EntryContext').values()78 assert response.get('Marker') in contents.get('EntryContext').values()79def test_list_attached_user_polices(mocker):80 """81 Given:82 - user_name - user name to retrieve policies for.83 - pagination args - combination of marker, limit, page and page_size args in order to control pagination.84 When:85 - After running a list_user_attached_policies command86 Then:87 - Ensure that the returned list includes only the attached policies the user posses.88 """89 args = {90 'userName': 'test'91 }92 policy_name = ATTACHED_POLICIES[0].get('PolicyName')93 policy_arn = ATTACHED_POLICIES[0].get('PolicyArn')94 mocker.patch.object(AWSClient, "aws_session", return_value=Boto3Client())95 mocker.patch.object(Boto3Client, "list_attached_user_policies", return_value=ATTACHED_RESPONSE)96 mocker.patch.object(demisto, 'results')97 client = AWSClient()98 AWS_IAM.list_attached_user_policies(args, client)99 contents = demisto.results.call_args[0][0]100 assert 'AWS IAM Attached Policies for user test' in contents.get('HumanReadable')101 assert [{'UserName': 'test', 'PolicyName': policy_name, 'PolicyArn': policy_arn}] in contents.get(102 'EntryContext').values()103 assert '111' in contents.get('EntryContext').values()104def test_list_attached_group_polices(mocker):105 """106 Given:107 - group_name - group name to retrieve policies for.108 - pagination args - combination of marker, limit, page and page_size args in order to control pagination.109 When:110 - After running a list_group_attached_policies command111 Then:112 - Ensure that the returned list includes only the attached policies the group posses.113 """114 args = {115 'groupName': 'test'116 }117 policy_name = ATTACHED_POLICIES[0].get('PolicyName')118 policy_arn = ATTACHED_POLICIES[0].get('PolicyArn')119 mocker.patch.object(AWSClient, "aws_session", return_value=Boto3Client())120 mocker.patch.object(Boto3Client, "list_attached_group_policies", return_value=ATTACHED_RESPONSE)121 mocker.patch.object(demisto, 'results')122 client = AWSClient()123 AWS_IAM.list_attached_group_policies(args, client)124 contents = demisto.results.call_args[0][0]125 assert 'AWS IAM Attached Policies for group test' in contents.get('HumanReadable')126 assert [{'GroupName': 'test', 'PolicyName': policy_name, 'PolicyArn': policy_arn}] in contents.get(127 'EntryContext').values()128 assert '111' in contents.get('EntryContext').values()129def test_get_user_login_profile(mocker):130 """131 Given:132 - user_name - user name to retrieve login profile for.133 When:134 - After running a get_user_login_profile command135 Then:136 - Ensure that the returned profile set correctly.137 """...
aws_iam_list_group_policies.py
Source:aws_iam_list_group_policies.py
...28 dt_string = now.strftime("%d_%m_%Y_%H_%M_%S")29 file = "{}_iam_list_group_policies".format(dt_string)30 filename = "./workspaces/{}/{}".format(workspace, file)31 try:32 response = profile.list_attached_group_policies(33 GroupName=variables['GROUP']['value']34 )35 while response['IsTruncated']:36 response.extend(profile.list_attached_group_policies(37 Marker=response['Marker']38 ))39 with open(filename,'w') as outputfile:40 json.dump(response, outputfile, indent=4, default=str)41 print(colored("[*] Output written to file", "green"), colored("'{}'".format(filename), "blue"),42 colored(".", "green"))43 outputfile.close()44 print(colored("------------------------", "yellow", attrs=['bold']))45 print("{}: {}".format(colored("GroupName", "yellow", attrs=['bold']), variables['GROUP']['value']))46 print(colored("------------------------", "yellow", attrs=['bold']))47 for policy in response['AttachedPolicies']:48 for key, value in policy.items():49 print("\t{}: {}".format(colored(key, "red", attrs=['bold']), colored(value, "blue")))50 print()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!