|
| 1 | +#! /usr/bin/env python |
| 2 | +from __future__ import absolute_import |
| 3 | +import os |
| 4 | +import six |
| 5 | +import sys |
| 6 | +import unittest |
| 7 | + |
| 8 | +from irods.test import helpers |
| 9 | + |
| 10 | +class TestResource(unittest.TestCase): |
| 11 | + |
| 12 | + from helpers import create_simple_resc_hierarchy |
| 13 | + |
| 14 | + def setUp(self): |
| 15 | + self.sess = helpers.make_session() |
| 16 | + |
| 17 | + def test_resource_properties_for_parent_and_hierarchy_at_3_levels__392(self): |
| 18 | + ses = self.sess |
| 19 | + root = "deferred_392" |
| 20 | + pt = "pt_392" |
| 21 | + leaf = "leaf_392" |
| 22 | + root_resc = ses.resources.create(root,"deferred") |
| 23 | + try: |
| 24 | + # Create two (passthru + storage) hierarchies below the root: ie. pt0;leaf0 and pt1;leaf1 |
| 25 | + with self.create_simple_resc_hierarchy(pt + "_0", leaf + "_0"), \ |
| 26 | + self.create_simple_resc_hierarchy(pt + "_1", leaf + "_1"): |
| 27 | + try: |
| 28 | + # Adopt both passthru's as children under the main root (deferred) node. |
| 29 | + ses.resources.add_child(root, pt + "_0") |
| 30 | + ses.resources.add_child(root, pt + "_1") |
| 31 | + # Now we have two different 3-deep hierarchies (root;pt0;leaf0 and root;pt1;leaf) sharing the same root node. |
| 32 | + # Descend each and make sure the relationships hold |
| 33 | + for mid in root_resc.children: |
| 34 | + hierarchy = [root_resc, mid, mid.children[0]] |
| 35 | + parent_resc = None |
| 36 | + hier_str = root |
| 37 | + # Assert that the hierarchy and parent properties hold at each level, in both tree branches. |
| 38 | + for n,resc in enumerate(hierarchy): |
| 39 | + if n > 0: |
| 40 | + hier_str += ";{}".format(resc.name) |
| 41 | + self.assertEqual(resc.parent_id, (None if n == 0 else parent_resc.id)) |
| 42 | + self.assertEqual(resc.parent_name, (None if n == 0 else parent_resc.name)) |
| 43 | + self.assertEqual(resc.hierarchy_string, hier_str) |
| 44 | + self.assertIs(type(resc.hierarchy_string), str) # type of hierarchy field is string. |
| 45 | + if resc.parent is None: |
| 46 | + self.assertIs(resc.parent_id, None) |
| 47 | + self.assertIs(resc.parent_name, None) |
| 48 | + else: |
| 49 | + self.assertIn(type(resc.parent_id), six.integer_types) # type of a non-null id field is integer. |
| 50 | + self.assertIs(type(resc.parent_name), str) # type of a non-null name field is string. |
| 51 | + parent_resc = resc |
| 52 | + finally: |
| 53 | + ses.resources.remove_child(root, pt + "_0") |
| 54 | + ses.resources.remove_child(root, pt + "_1") |
| 55 | + finally: |
| 56 | + ses.resources.remove(root) |
| 57 | + |
| 58 | + |
| 59 | +if __name__ == '__main__': |
| 60 | + # let the tests find the parent irods lib |
| 61 | + sys.path.insert(0, os.path.abspath('../..')) |
| 62 | + unittest.main() |
0 commit comments