def testExportTreeWithMSince(self):

        assertEqual = self.assertEqual

        auth = current.auth
        auth.override = True

        xmlstr = """
<s3xml>
    <resource name="hms_hospital" uuid="ORDERTESTHOSPITAL1">
        <data field="name">OrderTestHospital1</data>
    </resource>
    <resource name="hms_hospital" uuid="ORDERTESTHOSPITAL2">
        <data field="name">OrderTestHospital2</data>
    </resource>
</s3xml>"""

        try:
            xmltree = etree.ElementTree(etree.fromstring(xmlstr))
            resource = current.s3db.resource("hms_hospital")
            resource.import_xml(xmltree)

            resource = current.s3db.resource(resource,
                                             uid=["ORDERTESTHOSPITAL1",
                                                  "ORDERTESTHOSPITAL2",
                                                  ])

            # Load the records without orderby
            resource.load(limit=2)
            assertEqual(len(resource), 2)

            # Determine which comes first and which last without orderby
            first = resource._rows[0]["uuid"]
            last = resource._rows[1]["uuid"]

            # Make first older than last
            now = datetime.datetime.utcnow()
            ts = now - datetime.timedelta(seconds=5)
            resource._rows[0].update_record(created_on = ts,
                                            modified_on = ts,
                                            )
            resource._rows[1].update_record(created_on = now,
                                            modified_on = now,
                                            )

            # Without msince, elements should have same order as in load
            msince = msince=datetime.datetime.utcnow() - datetime.timedelta(days=1)
            tree = resource.export_tree(start=0,
                                        limit=1,
                                        dereference=False)
            root = tree.getroot()
            assertEqual(len(root), 1)

            child = root[0]
            uuid = child.get("uuid", None)
            assertEqual(uuid, first)

            # With msince, elements should be ordered by age
            tree = resource.export_tree(start=0,
                                        limit=1,
                                        msince=msince,
                                        dereference=False)
            root = tree.getroot()
            assertEqual(len(root), 1)

            child = root[0]
            uuid = child.get("uuid", None)
            assertEqual(uuid, last)

        finally:
            current.db.rollback()
            auth.override = False

    # -------------------------------------------------------------------------
Test automatic ordering of export items by mtime if msince is given
dataset/ETHPy150Open sahana/eden/modules/unit_tests/s3/s3resource.py/ResourceExportTests.testExportTreeWithMSince