|
10 | 10 | from irods.column import In, Like |
11 | 11 | from irods.exception import UserDoesNotExist |
12 | 12 | from irods.models import User,Collection,DataObject |
| 13 | +from irods.path import iRODSPath |
13 | 14 | from irods.user import iRODSUser |
14 | 15 | from irods.session import iRODSSession |
15 | 16 | import irods.test.helpers as helpers |
@@ -371,6 +372,85 @@ def test_removed_user_does_not_affect_raw_ACL_queries__issue_431(self): |
371 | 372 | else: |
372 | 373 | u.remove() |
373 | 374 |
|
| 375 | + def test_iRODSAccess_can_be_constructed_using_iRODSCollection__issue_558(self): |
| 376 | + user_name = "testuser" |
| 377 | + collection_path = "/".join([helpers.home_collection(self.sess), "give_read_access_to_this"]) |
| 378 | + |
| 379 | + try: |
| 380 | + user = self.sess.users.create(user_name, 'rodsuser') |
| 381 | + collection = self.sess.collections.create(collection_path) |
| 382 | + |
| 383 | + # Give user access to data object. This should succeed. Before the fix in #558, this would cause an error |
| 384 | + # from pickle during a call to deepcopy of the iRODSAccess object. The library does not know how to pickle |
| 385 | + # an iRODSCollection object. |
| 386 | + access = iRODSAccess('read', collection, user.name) |
| 387 | + self.sess.acls.set(access) |
| 388 | + |
| 389 | + # We can get permissions from collection, and the test user's entry is there. |
| 390 | + perms = self.sess.acls.get(collection) |
| 391 | + self.assertTrue(any(p for p in perms if p.user_name == user_name)) |
| 392 | + |
| 393 | + finally: |
| 394 | + self.sess.users.get(user_name).remove() |
| 395 | + self.sess.collections.remove(collection_path, force=True) |
| 396 | + |
| 397 | + def test_iRODSAccess_can_be_constructed_using_iRODSDataObject__issue_558(self): |
| 398 | + user_name = "testuser" |
| 399 | + data_object_path = "/".join([helpers.home_collection(self.sess), "give_read_access_to_this"]) |
| 400 | + |
| 401 | + try: |
| 402 | + user = self.sess.users.create(user_name, 'rodsuser') |
| 403 | + data_object = self.sess.data_objects.create(data_object_path) |
| 404 | + |
| 405 | + # Give user access to data object. This should succeed. Before the fix in #558, this would cause an error |
| 406 | + # from pickle during a call to deepcopy of the iRODSAccess object. The library does not know how to pickle |
| 407 | + # an iRODSDataObject object. |
| 408 | + access = iRODSAccess('read', data_object, user.name) |
| 409 | + self.sess.acls.set(access) |
| 410 | + |
| 411 | + # We can get permissions from the data object, and the test user's entry is there. |
| 412 | + perms = self.sess.acls.get(data_object) |
| 413 | + self.assertTrue(any(p for p in perms if p.user_name == user_name)) |
| 414 | + |
| 415 | + finally: |
| 416 | + self.sess.users.get(user_name).remove() |
| 417 | + self.sess.data_objects.unlink(data_object_path, force=True) |
| 418 | + |
| 419 | + def test_iRODSAccess_can_be_constructed_using_iRODSPath__issue_558(self): |
| 420 | + user_name = "testuser" |
| 421 | + data_object_path = "/".join([helpers.home_collection(self.sess), "give_read_access_to_this"]) |
| 422 | + |
| 423 | + try: |
| 424 | + irods_path = iRODSPath(data_object_path) |
| 425 | + |
| 426 | + user = self.sess.users.create(user_name, 'rodsuser') |
| 427 | + data_object = self.sess.data_objects.create(data_object_path) |
| 428 | + |
| 429 | + # Give user access to data object. This should succeed. Before the fix in #558, this would cause an error |
| 430 | + # from pickle during a call to deepcopy of the iRODSAccess object. The library does not know how to pickle |
| 431 | + # an iRODSDataObject object. |
| 432 | + access = iRODSAccess('read', irods_path, user.name) |
| 433 | + self.sess.acls.set(access) |
| 434 | + |
| 435 | + # We can get permissions from the data object, and the test user's entry is there. |
| 436 | + perms = self.sess.acls.get(data_object) |
| 437 | + self.assertTrue(any(p for p in perms if p.user_name == user_name)) |
| 438 | + |
| 439 | + finally: |
| 440 | + self.sess.users.get(user_name).remove() |
| 441 | + self.sess.data_objects.unlink(data_object_path, force=True) |
| 442 | + |
| 443 | + def test_iRODSAccess_cannot_be_constructed_using_unsupported_type__issue_558(self): |
| 444 | + # Before the fix in #558, this would have been allowed and only later would the type discrepancy be revealed, |
| 445 | + # leading to opaque error messages. Now, the types are checked on the way in to ensure clarity and correctness. |
| 446 | + # TODO(#480): We cannot use the unittest.assertRaises context manager as this was introduced in python 3.1. |
| 447 | + self.assertRaisesRegex( |
| 448 | + TypeError, |
| 449 | + "'path' parameter must be of type 'str', 'irods.collection.iRODSCollection', " |
| 450 | + "'irods.data_object.iRODSDataObject', or 'irods.path.iRODSPath'.", |
| 451 | + iRODSAccess, 'read', self.sess) |
| 452 | + |
| 453 | + |
374 | 454 | if __name__ == '__main__': |
375 | 455 | # let the tests find the parent irods lib |
376 | 456 | sys.path.insert(0, os.path.abspath('../..')) |
|
0 commit comments