def testExportOptionsLastOptJSONHierarchy(self):

        assertEqual = self.assertEqual
        assertTrue = self.assertTrue

        db = current.db
        s3db = current.s3db

        # Configure parent-field
        table = db.fotest_lookup_table
        represent = S3Represent(lookup="fotest_lookup_table")
        table.parent.requires = IS_EMPTY_OR(
                                    IS_ONE_OF(db,
                                                "fotest_lookup_table.id",
                                                represent,
                                                ))
        table.parent.requires = represent

        # Configure hierarchy
        s3db.configure("fotest_lookup_table", hierarchy="parent")
        S3Hierarchy.dirty("fotest_lookup_table")

        # Insert a child node
        options = dict(self.records)
        child_node = {"name": "option3",
                      "uuid": "OPTION3",
                      "parent": options.keys()[0],
                      }
        child_id = table.insert(**child_node)
        options[child_id] = child_node

        # Get the last record
        table = db.fotest_lookup_table
        last = db(table.id>0).select(limitby=(0, 1),
                                     orderby=~table.id).first()
        self.assertNotEqual(last, None)

        # Request last option
        resource = s3db.resource("fotest_table")
        result = resource.export_options(fields=["lookup"],
                                         only_last=True,
                                         hierarchy=True,
                                         as_json=True)
        fo = json.loads(result)

        # Inspect result
        assertTrue(isinstance(fo, dict))

        assertTrue("option" in fo)
        assertTrue(isinstance(fo["option"], list))
        assertEqual(len(fo["option"]), 1)

        opt = fo["option"][0]
        value = opt["@value"]
        assertEqual(options[value]["uuid"], last.uuid)
        assertEqual(opt["$"], options[value]["name"])

        assertTrue("@parent" in opt)
        assertEqual(opt["@parent"], str(options[value]["parent"]))

# =============================================================================
dataset/ETHPy150Open sahana/eden/modules/unit_tests/s3/s3xml.py/GetFieldOptionsTests.testExportOptionsLastOptJSONHierarchy/original