Best Python code snippet using tempest_python
test_roles_members_api.py
Source:test_roles_members_api.py
...30 def test_get_members_400(self):31 """Test case for 400 status response for GET requests using 'members' query parameter32 """33 with self.assertRaises(conjur.ApiException) as context:34 self.api.show_role(35 self.account,36 NULL_BYTE,37 'admin',38 members=''39 )40 self.assertEqual(context.exception.status, 400)41 def test_get_members_401(self):42 """Test case for 401 status response for GET requests using 'members' query parameter43 401 - unauthorized request44 """45 with self.assertRaises(conjur.ApiException) as context:46 self.bad_auth_api.show_role(47 self.account,48 'user',49 'admin',50 members=''51 )52 self.assertEqual(context.exception.status, 401)53 def test_get_members_404(self):54 """Test case for 404 status response for GET requests using 'members' query parameter55 404 - the queried role does not exist56 """57 with self.assertRaises(conjur.ApiException) as context:58 self.api.show_role(59 self.account,60 'user',61 'fakeUser',62 members=''63 )64 self.assertEqual(context.exception.status, 404)65 def test_get_members_422(self):66 """Test case for 422 status response for GET requests using 'members' query parameter67 422 - Conjur recieved a malformed request parameter68 """69 with self.assertRaises(conjur.ApiException) as context:70 self.api.show_role(71 self.account,72 'user',73 'admin',74 members='',75 search=NULL_BYTE76 )77 self.assertEqual(context.exception.status, 422)78 # Test cases for getting all of a role's memberships, expanded recursively79 def test_get_all_memberships_200(self):80 """Test case for 200 status response for GET requests using 'all' query parameter81 Queries user:bob for all its memberships, expanded recursively82 """83 # Set bob as member of userGroup and anotherGroup84 # Set userGroup as member of testLayer85 self.add_user_to_group('bob')86 self.api.add_member_to_role(87 self.account,88 'group',89 'anotherGroup',90 members='',91 member=self.BOB_ID92 )93 self.api.add_member_to_role(94 self.account,95 'layer',96 'testLayer',97 members='',98 member=self.USER_GROUP_ID99 )100 # testLayer will be listed in all memberships of bob101 bob_membership_data, status, _ = self.api.show_role_with_http_info(102 self.account,103 'user',104 'bob',105 all=''106 )107 target_membership_data = [108 self.LAYER_ID,109 self.ANOTHER_GROUP_ID,110 self.USER_GROUP_ID,111 self.BOB_ID112 ]113 self.assertEqual(status, 200)114 for i in bob_membership_data:115 self.assertIn(i, target_membership_data)116 def test_get_all_memberships_400(self):117 """Test case for 400 status response for GET requests using 'all' query parameter118 Error originates from NGINX, occurs when making HTTPS requests to Conjur through NGINX119 This same request made directly to Conjur with HTTP results in a 422 status response120 400 - request rejected by NGINX proxy121 """122 with self.assertRaises(conjur.ApiException) as context:123 self.api.show_role(124 self.account,125 NULL_BYTE,126 'admin',127 all=''128 )129 self.assertEqual(context.exception.status, 400)130 def test_get_all_memberships_401(self):131 """Test case for 401 status response for GET requests using 'all' query parameter132 401 - unauthorized request133 """134 with self.assertRaises(conjur.ApiException) as context:135 self.bad_auth_api.show_role(136 self.account,137 'user',138 'admin',139 all=''140 )141 self.assertEqual(context.exception.status, 401)142 def test_get_all_memberships_404(self):143 """Test case for 404 status response for GET requests using 'all' query parameter144 404 - the queried role does not exist145 """146 with self.assertRaises(conjur.ApiException) as context:147 self.api.show_role(148 self.account,149 'user',150 'fakeUser',151 all=''152 )153 self.assertEqual(context.exception.status, 404)154 # Test cases for getting a role's direct memberships155 def test_get_direct_memberships_200(self):156 """Test case for 200 status response for GET requests using 'memberships' query parameter157 Queries user:bob for all its memberships, expanded recursively158 This will include memberships of bob's direct memberships159 """160 # Set bob as member of userGroup and anotherGroup161 # Set userGroup as member of testLayer162 self.add_user_to_group('bob')163 self.api.add_member_to_role(164 self.account,165 'group',166 'anotherGroup',167 members='',168 member=self.BOB_ID169 )170 self.api.add_member_to_role(171 self.account,172 'layer',173 'testLayer',174 members='',175 member=self.USER_GROUP_ID176 )177 # testLayer will not be listed in direct memberships of bob178 bob_membership_data, status, _ = self.api.show_role_with_http_info(179 self.account,180 'user',181 'bob',182 memberships=''183 )184 memberships = [f'{self.account}:group:userGroup', f'{self.account}:group:anotherGroup']185 self.assertEqual(status, 200)186 for i in range(0, 2):187 self.assertIn(bob_membership_data[i]['role'], memberships)188 def test_get_direct_memberships_400(self):189 """Test case for 400 status response for GET requests using 'memberships' query parameter190 Error originates from NGINX, occurs when making HTTPS requests to Conjur through NGINX191 This same request made directly to Conjur with HTTP results in a 422 status response192 400 - request rejected by NGINX proxy193 """194 with self.assertRaises(conjur.ApiException) as context:195 self.api.show_role(196 self.account,197 NULL_BYTE,198 'admin',199 memberships=''200 )201 self.assertEqual(context.exception.status, 400)202 def test_get_direct_memberships_401(self):203 """Test case for 401 status response for GET requests using 'memberships' query parameter204 401 - unauthorized request205 """206 with self.assertRaises(conjur.ApiException) as context:207 self.bad_auth_api.show_role(208 self.account,209 'user',210 'admin',211 memberships=''212 )213 self.assertEqual(context.exception.status, 401)214 def test_get_direct_memberships_404(self):215 """Test case for 404 status response for GET requests using 'memberships' query parameter216 404 - the queried role does not exist217 """218 with self.assertRaises(conjur.ApiException) as context:219 self.api.show_role(220 self.account,221 'user',222 'fakeUser',223 memberships=''224 )225 self.assertEqual(context.exception.status, 404)226 def test_get_direct_memberships_422(self):227 """Test case for 422 status response for GET requests using 'memberships' query parameter228 422 - Conjur recieved a malformed request parameter229 """230 with self.assertRaises(conjur.ApiException) as context:231 self.api.show_role(232 self.account,233 'user',234 'admin',235 memberships='',236 search=NULL_BYTE237 )238 self.assertEqual(context.exception.status, 422)239if __name__ == '__main__':...
test_roles_query_params_api.py
Source:test_roles_query_params_api.py
...12 Adds dev:user:bob as a member of group:userGroup, then queries for a member count13 """14 self.add_user_to_group('bob')15 self.add_user_to_group('alice')16 response = self.api.show_role(17 self.account,18 'group',19 'userGroup',20 members='',21 count=True22 )23 self.assertEqual(response['count'], 3)24 def test_get_members_offset(self):25 """Test using members & offset query parameters on GET requests26 Returns member data starting at <offset>27 """28 self.add_user_to_group('bob')29 self.add_user_to_group('alice')30 response = self.api.show_role(31 self.account,32 'group',33 'userGroup',34 members='',35 offset=236 )37 # starting at offset 2 should omit user:admin (0) and user:alice (1)38 target_response = [39 {40 'admin_option': False,41 'ownership': False,42 'role': self.USER_GROUP_ID,43 'member': self.BOB_ID44 }45 ]46 self.assertEqual(response, target_response)47 def test_get_members_limit(self):48 """Test using members & limit query parameters on GET requests49 Returns member data limited to the first <limit> results50 """51 self.add_user_to_group('bob')52 self.add_user_to_group('alice')53 response = self.api.show_role(54 self.account,55 'group',56 'userGroup',57 members='',58 limit=259 )60 # limiting the results to the first 2 should omit user:bob (idx 2)61 target_response = [62 {63 'admin_option': True,64 'ownership': True,65 'role': self.USER_GROUP_ID,66 'member': self.ADMIN_ID,67 'policy': self.ROOT_ID68 },69 {70 'admin_option': False,71 'ownership': False,72 'role': self.USER_GROUP_ID,73 'member': self.ALICE_ID74 }75 ]76 self.assertEqual(response, target_response)77 def test_get_members_search(self):78 """Test using members & search query parameters on GET requests79 Returns only members matching the provided string80 """81 self.add_user_to_group('bob')82 self.add_user_to_group('alice')83 response = self.api.show_role(84 self.account,85 'group',86 'userGroup',87 members='',88 search='bob'89 )90 target_response = [91 {92 'admin_option': False,93 'ownership': False,94 'role': self.USER_GROUP_ID,95 'member': self.BOB_ID96 }97 ]98 self.assertEqual(response, target_response)99 # Test cases for getting a role membership graph100 def test_show_graph_200(self):101 """Test case for show 200 response with graph query param"""102 details, status, _ = self.api.show_role_with_http_info(103 self.account,104 'user',105 'admin',106 graph=''107 )108 self.assertEqual(status, 200)109 # root policy as parent should always be first for admin user110 for i in details:111 self.assertIn('parent', i)112 self.assertIn('child', i)113 def test_show_graph_400(self):114 """Test case for show_role 400 response with graph query param"""115 with self.assertRaises(conjur.exceptions.ApiException) as context:116 self.bad_auth_api.show_role(self.account, 'user', NULL_BYTE, graph='')117 self.assertEqual(context.exception.status, 400)118 def test_show_graph_401(self):119 """Test case for show_role 401 response with graph query param"""120 with self.assertRaises(conjur.exceptions.ApiException) as context:121 self.bad_auth_api.show_role(self.account, 'user', 'admin', graph='')122 self.assertEqual(context.exception.status, 401)123 def test_show_graph_404(self):124 """Test case for show_role 404 response with graph query param"""125 with self.assertRaises(conjur.exceptions.ApiException) as context:126 self.api.show_role(self.account, 'user', 'nonexist', graph='')127 self.assertEqual(context.exception.status, 404)128 # Test combinations of optional query parameters when getting role information129 def test_parameter_combos_a(self):130 """Test Conjur's response to being given all optional parameters in a single request131 Conjur responds with `graph` results ONLY132 """133 details, status, _ = self.api.show_role_with_http_info(134 self.account,135 'user',136 'admin',137 all='',138 memberships='',139 members='',140 graph=''...
cmd_roles.py
Source:cmd_roles.py
1import click2from parsec.commands.roles.create_role import cli as create_role3from parsec.commands.roles.get_roles import cli as get_roles4from parsec.commands.roles.show_role import cli as show_role5@click.group()6def cli():7 pass8cli.add_command(create_role)9cli.add_command(get_roles)...
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!!