How to use get_acls method in autotest

Best Python code snippet using autotest_python

test_baton_api.py

Source:test_baton_api.py Github

copy

Full Screen

...20from serapis.storage.irods.baton_mappings import ACLMapping21# DATA OBJECT - related tests:22class GetACLSBatonDataObjectAPITest(unittest.TestCase):23 def test_get_acls_data_object(self):24 result = BatonDataObjectAPI._get_acls("/humgen/projects/serapis_staging/test-baton/test_acls.txt")25 expected = {ACL(user='ic4', zone='humgen', permission='READ'),26 ACL(user='ic4', zone='Sanger1', permission='READ'),27 ACL(user='humgenadmin', zone='humgen', permission='OWN'),28 ACL(user='mercury', zone='Sanger1', permission='OWN'),29 ACL(user='irods', zone='humgen', permission='OWN'),30 ACL(user='serapis', zone='humgen', permission='OWN')31 }32 self.assertSetEqual(result, expected)33class AddOrReplaceACLBatonDataObjectAPITest(unittest.TestCase):34 def setUp(self):35 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_add_acls.txt"36 BatonDataObjectAPI.remove_all_acls(self.fpath)37 def tearDown(self):38 BatonDataObjectAPI.remove_all_acls(self.fpath)39 def test_get_or_replace_acls_when_adding_a_new_acl(self):40 added_acl = ACL(user='mp15', zone='humgen', permission='OWN')41 BatonDataObjectAPI.add_or_replace_acl(self.fpath, added_acl)42 acls_set = BatonDataObjectAPI.get_acls(self.fpath)43 found = False44 for acl in acls_set:45 if acl == added_acl:46 found = True47 self.assertTrue(found)48 def test_get_or_replace_acls_when_replacing_an_acl(self):49 added_acl = ACL(user='cn13', zone='humgen', permission='OWN')50 BatonDataObjectAPI.add_or_replace_acl(self.fpath, added_acl)51 acls_set = BatonDataObjectAPI.get_acls(self.fpath)52 self.assertSetEqual(acls_set, {added_acl})53 replacement_acl = ACL(user='cn13', zone='humgen', permission='READ')54 BatonDataObjectAPI.add_or_replace_acl(self.fpath, replacement_acl)55 acls_set = BatonDataObjectAPI.get_acls(self.fpath)56 self.assertSetEqual(acls_set, {replacement_acl})57class AddOrReplaceAsBatchDataObjectAPITest(unittest.TestCase):58 def setUp(self):59 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_add_acls.txt"60 BatonDataObjectAPI.remove_all_acls(self.fpath)61 def test_add_or_replace_a_list_of_acls(self):62 self.acls = [63 ACL(user='cn13', zone='humgen', permission='READ'),64 ACL(user='mp15', zone='humgen', permission='READ')65 ]66 BatonDataObjectAPI.add_or_replace_a_list_of_acls(self.fpath, self.acls)67 self.acls_set = BatonDataObjectAPI.get_acls(self.fpath)68 self.assertEqual(len(self.acls_set), 2)69class RemoveACLsForAListOfUsersDataObjectAPITest(unittest.TestCase):70 def setUp(self):71 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_add_acls.txt"72 BatonDataObjectAPI.remove_all_acls(self.fpath)73 self.acl = ACL(user='cn13', zone='humgen', permission='READ')74 BatonDataObjectAPI.add_or_replace_acl(self.fpath, self.acl)75 existing_acls = BatonDataObjectAPI.get_acls(self.fpath)76 self.assertEqual(len(existing_acls), 1)77 def test_remove_acls_for_a_list_of_users(self):78 BatonDataObjectAPI.remove_acls_for_a_list_of_users(self.fpath, [(self.acl.user, self.acl.zone)])79 existing_acls = BatonDataObjectAPI.get_acls(self.fpath)80 self.assertEqual(0, len(existing_acls))81 def tearDown(self):82 BatonDataObjectAPI.remove_all_acls(self.fpath)83class RemoveACLForUserDataObjectAPITest(unittest.TestCase):84 def setUp(self):85 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_add_acls.txt"86 BatonDataObjectAPI.remove_all_acls(self.fpath)87 self.acl = ACL(user='cn13', zone='humgen', permission='READ')88 BatonDataObjectAPI.add_or_replace_acl(self.fpath, self.acl)89 existing_acls = BatonDataObjectAPI.get_acls(self.fpath)90 self.assertEqual(len(existing_acls), 1)91 def test_remove_acls_for_a_list_of_users(self):92 BatonDataObjectAPI.remove_acls_for_a_list_of_users(self.fpath, [(self.acl.user, self.acl.zone)])93 existing_acls = BatonDataObjectAPI.get_acls(self.fpath)94 self.assertEqual(0, len(existing_acls))95 def tearDown(self):96 BatonDataObjectAPI.remove_all_acls(self.fpath)97class RemoveAllACLSBatonDataObjectAPITest(unittest.TestCase):98 def setUp(self):99 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_add_acls.txt"100 self.acls = [101 ACL(user='cn13', zone='humgen', permission='READ'),102 ACL(user='mp15', zone='humgen', permission='READ')103 ]104 BatonDataObjectAPI.add_or_replace_a_list_of_acls(self.fpath, self.acls)105 self.acls_set = BatonDataObjectAPI.get_acls(self.fpath)106 self.assertNotEqual(len(self.acls_set), 0)107 def test_remove_all_acls(self):108 BatonDataObjectAPI.remove_all_acls(self.fpath)109 acls_set = BatonDataObjectAPI.get_acls(self.fpath)110 self.assertEqual(set(), acls_set)111class AddMetadataBatonDataObjectAPITest(unittest.TestCase):112 def setUp(self):113 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_metadata_add_rm.txt"114 self.meta_dict = {'sample': {'sample2'}, 'sample_id': {'-1'}}115 def test_add_metadata(self):116 BatonDataObjectAPI.add_metadata(self.fpath, self.meta_dict)117 metadata = BatonDataObjectAPI.get_all_metadata(self.fpath).to_dict()118 self.assertDictEqual(self.meta_dict, metadata)119 def tearDown(self):120 BatonDataObjectAPI.remove_metadata(self.fpath, self.meta_dict)121class RemoveMetadataBatonDataObjectAPITest(unittest.TestCase):122 def setUp(self):123 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_metadata_add_rm.txt"124 self.meta_dict = {'sample': {'sample2'}, 'sample_id': {'-1'}}125 self.previous_meta = BatonDataObjectAPI.get_all_metadata(self.fpath)126 BatonDataObjectAPI.add_metadata(self.fpath, self.meta_dict)127 def test_remove_metadata(self):128 BatonDataObjectAPI.remove_metadata(self.fpath, self.meta_dict)129 crt_meta = BatonDataObjectAPI.get_all_metadata(self.fpath)130 self.assertEqual(crt_meta, self.previous_meta)131class UpdateMetadataBatonDataObjectAPITest(unittest.TestCase):132 def setUp(self):133 self.fpath = "/humgen/projects/serapis_staging/test-baton/test_metadata_add_rm.txt"134 BatonDataObjectAPI.add_metadata(self.fpath, {'uniq_key': {'first_value'}})135 def test_update_metadata(self):136 BatonDataObjectAPI.update_metadata(self.fpath, 'uniq_key', {'second_value'})137 updated_meta = BatonDataObjectAPI.get_all_metadata(self.fpath)138 values = updated_meta.get_avu('uniq_key')139 self.assertEqual(values, {'second_value'})140 def tearDown(self):141 BatonDataObjectAPI.remove_metadata(self.fpath, {'uniq_key': {'second_value'}})142class AddMetadataBatonCollectionAPITest(unittest.TestCase):143 def setUp(self):144 self.coll_path = "/humgen/projects/serapis_staging/test-baton/test_coll_metadata"145 self.meta_dict = {'key1': {'val1'}}146 def test_add_metadata(self):147 BatonCollectionAPI.add_metadata(self.coll_path, self.meta_dict)148 crt_meta_dict = BatonCollectionAPI.get_all_metadata(self.coll_path).to_dict()149 self.assertTrue('key1' in crt_meta_dict)150 def tearDown(self):151 BatonCollectionAPI.remove_metadata(self.coll_path, self.meta_dict)152class RemoveMetadataBatonCollectionAPITest(unittest.TestCase):153 def setUp(self):154 self.coll_path = "/humgen/projects/serapis_staging/test-baton/test_coll_metadata"155 self.meta_dict = {'key1': {'val1'}}156 BatonCollectionAPI.add_metadata(self.coll_path, self.meta_dict)157 crt_meta = BatonCollectionAPI.get_all_metadata(self.coll_path).to_dict()158 self.assertTrue('key1' in crt_meta)159 def test_rm_metadata(self):160 BatonCollectionAPI.remove_metadata(self.coll_path, self.meta_dict)161 new_meta = BatonCollectionAPI.get_all_metadata(self.coll_path).to_dict()162 self.assertFalse('key1' in new_meta)163class UpdateMetadataBatonCollectionAPITest(unittest.TestCase):164 def setUp(self):165 self.coll_path = "/humgen/projects/serapis_staging/test-baton/test_coll_metadata"166 self.meta_dict = {'key1': {'val1'}}167 BatonCollectionAPI.add_metadata(self.coll_path, self.meta_dict)168 crt_meta = BatonCollectionAPI.get_all_metadata(self.coll_path).to_dict()169 self.assertTrue('key1' in crt_meta)170 def test_update_metadata(self):171 BatonCollectionAPI.update_metadata(self.coll_path, 'key1', {'val2'})172 crt_meta = BatonCollectionAPI.get_all_metadata(self.coll_path).to_dict()173 self.assertTrue('key1' in crt_meta)174 self.assertSetEqual(crt_meta['key1'], {'val2'})175 def tearDown(self):176 BatonCollectionAPI.remove_metadata(self.coll_path, {'key1': {'val2'}})177class ListContentsBatonCollectionAPITest(unittest.TestCase):178 def setUp(self):179 self.coll_path = "/humgen/projects/serapis_staging/test-baton/test_coll_metadata"180 def test_list_contents(self):181 contents = BatonCollectionAPI.list_data_objects(self.coll_path)182 self.assertEqual(len(contents), 1)183 self.assertEqual(contents[0], "/humgen/projects/serapis_staging/test-baton/test_coll_metadata/test_list_coll.txt")184# ABSTRACT - NOT IMPLEMENTED METHODS TESTS:185class AbstractMethodsTests(unittest.TestCase):186 def test_get_connection(self):187 self.assertRaises(NotImplementedError, BatonBasicAPI._get_connection)188 def test_upload_basic(self):189 self.assertRaises(NotImplementedError, BatonBasicAPI.upload, '', '')190 def test_remove_basic(self):191 self.assertRaises(NotImplementedError, BatonBasicAPI.remove, '')192 def test_move_basic(self):193 self.assertRaises(NotImplementedError, BatonBasicAPI.move, '', '')194 def test_upload_data_object(self):195 self.assertRaises(NotImplementedError, BatonDataObjectAPI.upload, '', '')196 def test_remove_data_object(self):197 self.assertRaises(NotImplementedError, BatonDataObjectAPI.remove, '')198 def test_move_data_object(self):199 self.assertRaises(NotImplementedError, BatonDataObjectAPI.move, '', '')200 def test_upload_collection(self):201 self.assertRaises(NotImplementedError, BatonCollectionAPI.upload, '', '')202 def test_remove_collection(self):203 self.assertRaises(NotImplementedError, BatonCollectionAPI.remove, '')204 def test_move_collection(self):205 self.assertRaises(NotImplementedError, BatonCollectionAPI.move, '', '')206# COLLECTION - RELATED TESTS:207class GetACLSBatonCollectionAPITest(unittest.TestCase):208 def setUp(self):209 self.path = "/humgen/projects/serapis_staging/test-baton/test-collection-acls"210 BatonCollectionAPI.remove_all_acls(self.path)211 BatonCollectionAPI.add_or_replace_a_list_of_acls(self.path,212 [ACL(user='ic4', zone='humgen', permission='OWN'),213 ACL(user='ic4', zone='Sanger1', permission='READ')])214 def test_get_acls_collection(self):215 # TODO: modify the test so that it removes everything, and then adds the ACls before checking on their existence216 result = BatonCollectionAPI._get_acls(self.path)217 expected = {218 ACL(user='ic4', zone='humgen', permission='OWN'),219 ACL(user='ic4', zone='Sanger1', permission='READ'),220 }221 self.assertSetEqual(result, expected)222# class GetACLSBatonCollectionAPITest2(unittest.TestCase):223# def test_trigger_exception(self):224# result = BatonCollectionAPI.get_acls('/smth/non-existing')225# print("Results from trigger exception test; %s" % result)226 # self.assertEqual(1,2)227class RemoveAllACLSBatonCollectionAPITest(unittest.TestCase):228 def setUp(self):229 self.fpath = "/humgen/projects/serapis_staging/test-baton/test-collection-acls"230 self.acls = [231 ACL(user='cn13', zone='humgen', permission='READ'),232 ACL(user='mp15', zone='humgen', permission='READ')233 ]234 BatonCollectionAPI.add_or_replace_a_list_of_acls(self.fpath, self.acls)235 self.acls_set = BatonCollectionAPI.get_acls(self.fpath)236 self.assertNotEqual(len(self.acls_set), 0)237 def test_remove_all_acls(self):238 BatonCollectionAPI.remove_all_acls(self.fpath)239 acls_set = BatonCollectionAPI.get_acls(self.fpath)240 self.assertEqual(set(), acls_set)241class RemoveACLForUserCollectionAPITest(unittest.TestCase):242 def setUp(self):243 self.path = "/humgen/projects/serapis_staging/test-baton/test-collection-acls"244 BatonCollectionAPI.remove_all_acls(self.path)245 self.acl = ACL(user='cn13', zone='humgen', permission='READ')246 BatonCollectionAPI.add_or_replace_acl(self.path, self.acl)247 existing_acls = BatonCollectionAPI.get_acls(self.path)248 self.assertEqual(len(existing_acls), 1)249 def test_remove_acls_for_a_list_of_users(self):250 BatonCollectionAPI.remove_acls_for_a_list_of_users(self.path, [(self.acl.user, self.acl.zone)])251 existing_acls = BatonCollectionAPI.get_acls(self.path)252 self.assertEqual(0, len(existing_acls))253 def tearDown(self):254 BatonCollectionAPI.remove_all_acls(self.path)255class RemoveACLsForAListOfUsersCollectionAPITest(unittest.TestCase):256 def setUp(self):257 self.path = "/humgen/projects/serapis_staging/test-baton/test-collection-acls"258 BatonCollectionAPI.remove_all_acls(self.path)259 self.acl = ACL(user='cn13', zone='humgen', permission='READ')260 BatonCollectionAPI.add_or_replace_acl(self.path, self.acl)261 existing_acls = BatonCollectionAPI.get_acls(self.path)262 self.assertEqual(len(existing_acls), 1)263 def test_remove_acls_for_a_list_of_users(self):264 BatonCollectionAPI.remove_acls_for_a_list_of_users(self.path, [(self.acl.user, self.acl.zone)])265 existing_acls = BatonCollectionAPI.get_acls(self.path)266 self.assertEqual(0, len(existing_acls))267 def tearDown(self):268 BatonCollectionAPI.remove_all_acls(self.path)269class AddOrReplaceACLBatonCollectionAPITest(unittest.TestCase):270 def setUp(self):271 self.path = "/humgen/projects/serapis_staging/test-baton/test-collection-acls"272 BatonCollectionAPI.remove_all_acls(self.path)273 def tearDown(self):274 BatonCollectionAPI.remove_all_acls(self.path)275 def test_get_or_replace_acls_when_adding_a_new_acl(self):276 added_acl = ACL(user='mp15', zone='humgen', permission='OWN')277 BatonCollectionAPI.add_or_replace_acl(self.path, added_acl)278 acls_set = BatonCollectionAPI.get_acls(self.path)279 found = False280 for acl in acls_set:281 if acl == added_acl:282 found = True283 self.assertTrue(found)284 def test_get_or_replace_acls_when_replacing_an_acl(self):285 added_acl = ACL(user='cn13', zone='humgen', permission='OWN')286 BatonCollectionAPI.add_or_replace_acl(self.path, added_acl)287 acls_set = BatonCollectionAPI.get_acls(self.path)288 self.assertSetEqual(acls_set, {added_acl})289 replacement_acl = ACL(user='cn13', zone='humgen', permission='READ')290 BatonCollectionAPI.add_or_replace_acl(self.path, replacement_acl)291 acls_set = BatonCollectionAPI.get_acls(self.path)292 self.assertSetEqual(acls_set, {replacement_acl})293class AddOrReplaceAsBatchCollectionAPITest(unittest.TestCase):294 def setUp(self):295 self.path = "/humgen/projects/serapis_staging/test-baton/test-collection-acls"296 BatonCollectionAPI.remove_all_acls(self.path)297 def test_add_or_replace_a_list_of_acls(self):298 self.acls = [299 ACL(user='cn13', zone='humgen', permission='READ'),300 ACL(user='mp15', zone='humgen', permission='READ')301 ]302 BatonCollectionAPI.add_or_replace_a_list_of_acls(self.path, self.acls)303 self.acls_set = BatonCollectionAPI.get_acls(self.path)...

Full Screen

Full Screen

test_setaccess.py

Source:test_setaccess.py Github

copy

Full Screen

1import unittest2from unittest import TestCase3import setaccess4class TestRequestPermissions(unittest.TestCase):5 def test_get_acls(self):6 # (self, lab, members, request, request_name, request_members, groups, fastqs):7 p = setaccess.RequestPermissions("labX",8 [{"pi": "kunga","member": "kunga","group": False}],9 "08822", "DLP",10 [{'request': '08822', 'member': 'mcmanamd', 'group': False}],11 ["cmoigo", "bicigo"],12 [" vialea"], # dataAccessEmails13 ["none"])14 print("ACL access list:\n" + p.get_acls())15 self.assertIn("A:g:bicigo@hpc.private:rxtncy", p.get_acls())16 self.assertIn("A::kunga@hpc.private:rxtncy", p.get_acls())17 self.assertIn("A::mcmanamd@hpc.private:rxtncy", p.get_acls())18 self.assertIn("A::vialea@hpc.private:rxtncy", p.get_acls())19 self.assertIn("A::grewald@hpc.private:rxtncy", p.get_acls())20 self.assertIn("A::GROUP@:rxtncCy", p.get_acls())21class Test(TestCase):22 def test_get_request_metadata(self):23 p = setaccess.get_request_metadata("08822", "none")24 print("Lab members for 08822 {}".format(p.members))25 print("Lab request members for 08822 {}".format(p.request_members))26 self.assertEqual("shuklan", p.lab)27 def test_get_request_metadata_invalid_request(self):28 p = setaccess.get_request_metadata("08822_XXX", "none")29 print("No information found from endpoint for: {}".format(p))...

Full Screen

Full Screen

get_acls.py

Source:get_acls.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import argparse3from . import cfg4from . import util5def get_acls(path, zkCli, server, config=None, auth=None):6 cmd = 'getAcl %s' % (path)7 auth_str = util.auth_to_auth_str(auth)8 stdout_list, stderr_list = util.exec(cmd, zkCli, server, config, auth_str)9 valid_stdout_list = util.filter_valid_list(stdout_list, ["'sasl", "'world", "'digest", ':'])10 if len(valid_stdout_list) % 2 != 0:11 cfg.logger.error('get_acls: not parse correctly: valid_stdout_list: %s', valid_stdout_list)12 return []13 acls = [''.join(valid_stdout_list[i:i + 2]).replace("'", '').replace(',', ':').replace(' ', '') for i in range(0, len(valid_stdout_list), 2)]14 return acls15def parse_args():16 ''' '''17 parser = argparse.ArgumentParser(description='zookeeper_util: get_children')18 parser.add_argument('-i', '--ini', type=str, required=True, help="ini filename")19 parser.add_argument('-p', '--path', type=str, required=True, help="path")20 parser.add_argument('-l', '--log_filename', type=str, default='', required=False, help="log filename")21 args = parser.parse_args()22 return None, args23def _main():24 error, args = parse_args()25 cfg.init(args.ini, args.log_filename)26 path = args.path27 zkCli = cfg.config.get('zkcli', None)28 server = cfg.config.get('server', None)29 config = cfg.config.get('config', None)30 auth = cfg.config.get('auth', None)31 acls = get_acls(path, zkCli, server, config, auth)32 cfg.logger.info('after get_acls: path: %s acls: %s', path, acls)33if __name__ == '__main__':...

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