changeset 677:599ff47f609d large-queries

updated extended /changes tests
author Alain Mazy <am@orthanc.team>
date Thu, 05 Sep 2024 18:46:25 +0200
parents c76a8c783996
children 72f186c739d0
files Tests/Tests.py
diffstat 1 files changed, 47 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Tests/Tests.py	Mon Jun 03 12:21:33 2024 +0200
+++ b/Tests/Tests.py	Thu Sep 05 18:46:25 2024 +0200
@@ -627,20 +627,20 @@
 
 
     def test_changes_extended(self):
-        if IsOrthancVersionAbove(_REMOTE, 1, 13, 0) and DoGet(_REMOTE, '/system').get("HasExtendedApiV1"):
+        if IsOrthancVersionAbove(_REMOTE, 1, 12, 5) and DoGet(_REMOTE, '/system').get("Capabilities").get("HasExtendedChanges"):
             # Check emptiness
-            c = DoGet(_REMOTE, '/extended-api-v1/changes')
+            c = DoGet(_REMOTE, '/changes')
             self.assertEqual(0, len(c['Changes']))
             #self.assertEqual(0, c['Last'])   # Not true anymore for Orthanc >= 1.5.2
             self.assertTrue(c['Done'])
-            c = DoGet(_REMOTE, '/extended-api-v1/changes?last')
+            c = DoGet(_REMOTE, '/changes?last')
             self.assertEqual(0, len(c['Changes']))
             #self.assertEqual(0, c['Last'])   # Not true anymore for Orthanc >= 1.5.2
             self.assertTrue(c['Done'])
 
             # Add 1 instance
             i = UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')['ID']
-            c = DoGet(_REMOTE, '/extended-api-v1/changes')
+            c = DoGet(_REMOTE, '/changes')
             begin = c['Last']
             self.assertEqual(4, len(c['Changes']))
             self.assertTrue(c['Done'])
@@ -652,45 +652,67 @@
             self.assertEqual(c['Changes'][2]['ChangeType'], 'NewStudy')
             self.assertEqual(c['Changes'][3]['ChangeType'], 'NewPatient')
 
-            c = DoGet(_REMOTE, '/extended-api-v1/changes?type=NewInstance')
+            c = DoGet(_REMOTE, '/changes?type=NewInstance')
             self.assertEqual(1, len(c['Changes']))
             self.assertEqual(begin-3, c['Last'])
 
-            c = DoGet(_REMOTE, '/extended-api-v1/changes?type=NewPatient')
+            c = DoGet(_REMOTE, '/changes?type=NewPatient')
             self.assertEqual(1, len(c['Changes']))
             self.assertEqual(begin, c['Last'])
 
             UploadFolder(_REMOTE, 'Knee/T1')
             UploadFolder(_REMOTE, 'Knee/T2')
 
-            # 1000 New Instance changes  -> all 50 shall be reported
-            c = DoGet(_REMOTE, '/extended-api-v1/changes', { 'type': 'NewInstance', 'since' : begin, 'limit' : 1000 })
+            # Request the 1000 first NewInstance changes  -> all 50 shall be reported
+            c = DoGet(_REMOTE, '/changes', { 'type': 'NewInstance', 'since' : begin, 'limit' : 1000 })
             self.assertEqual(50, len(c['Changes']))
             self.assertLess(begin, c['Changes'][0]['Seq'])
-            self.assertTrue(c['Done'])
-            lastFromAll = c['Last']
-
-            # Only 10 New Instance changes  -> only 10 shall be reported
-            c = DoGet(_REMOTE, '/extended-api-v1/changes', { 'type': 'NewInstance', 'since' : begin, 'limit' : 10 })
+            self.assertTrue(c['Done'])   #w e have got them all so it's DONE
+            lastFrom1000NewInstances = c['Last']
+            firstFrom1000NewInstances = c['First']
+            self.assertLess(firstFrom1000NewInstances, lastFrom1000NewInstances)
+
+            # Only the 10 first NewInstance changes  -> only 10 shall be reported
+            c = DoGet(_REMOTE, '/changes', { 'type': 'NewInstance', 'since' : begin, 'limit' : 10 })
             self.assertEqual(10, len(c['Changes']))
             self.assertFalse(c['Done'])
-            lastFrom10 = c['Last']
-            self.assertLess(lastFrom10, lastFromAll)
+            lastFrom10firstNewInstances = c['Last']
+            firstFrom10firstNewInstances = c['First']
+            self.assertLess(firstFrom10firstNewInstances, lastFrom10firstNewInstances)
+            self.assertLess(lastFrom10firstNewInstances, lastFrom1000NewInstances)
+            self.assertEqual(firstFrom10firstNewInstances, firstFrom1000NewInstances)
 
             # between begin and begin+10 with a max of 10 and a filter -> less than 10 NewInstance since there are other changes in this range
-            c = DoGet(_REMOTE, '/extended-api-v1/changes', { 'type': 'NewInstance', 'since' : begin, 'to': begin+10, 'limit' : 10 })
+            c = DoGet(_REMOTE, '/changes', { 'type': 'NewInstance', 'since' : begin, 'to': begin+10, 'limit' : 10 })
             self.assertLess(len(c['Changes']), 10)
             self.assertTrue(c['Done'])  # we have received ALL NewInstance that are between since and to so we consider it's done
-            lastFrom10 = c['Last']
-            self.assertLess(lastFrom10, lastFromAll)
-
-            # test with only 'to' -> all 50 shall be reported
-            c = DoGet(_REMOTE, '/extended-api-v1/changes', { 'type': 'NewInstance', 'to': lastFromAll, 'limit' : 50 })
-            self.assertEqual(lastFromAll, c['Changes'][-1]['Seq'])
+            lastFrom10SubsetNewInstances = c['Last']
+            firstFrom10SubsetNewInstances = c['First']
+            self.assertLess(firstFrom10SubsetNewInstances, lastFrom10SubsetNewInstances)
+            self.assertLess(lastFrom10SubsetNewInstances, lastFrom10firstNewInstances)
+            self.assertEqual(firstFrom10SubsetNewInstances, firstFrom1000NewInstances)
+
+            # test with only 'to' -> all 50 NewInstance shall be reported
+            c = DoGet(_REMOTE, '/changes', { 'type': 'NewInstance', 'to': lastFrom1000NewInstances, 'limit' : 50 })
+            self.assertEqual(lastFrom1000NewInstances, c['Changes'][-1]['Seq'])
             self.assertEqual(50, len(c['Changes']))
-            self.assertFalse(c['Done'])
-            lastFromTo = c['Last']
-            self.assertLess(lastFrom10, lastFromTo)
+            self.assertFalse(c['Done'])  # Done can not be used when working in reverse direction
+            lastFrom50Reverse = c['Last']
+            firstFrom50Reverse = c['First']
+            self.assertLess(firstFrom50Reverse, lastFrom50Reverse)
+            self.assertEqual(lastFrom50Reverse, lastFrom1000NewInstances)
+            self.assertEqual(firstFrom50Reverse, firstFrom1000NewInstances)
+
+            # test with only 'to' and limit to 10 NewInstance changes
+            c = DoGet(_REMOTE, '/changes', { 'type': 'NewInstance', 'to': lastFrom1000NewInstances, 'limit' : 10 })
+            self.assertEqual(lastFrom1000NewInstances, c['Changes'][-1]['Seq'])
+            self.assertEqual(10, len(c['Changes']))
+            self.assertFalse(c['Done'])  # Done can not be used when working in reverse direction
+            lastFrom10Reverse = c['Last']
+            firstFrom10Reverse = c['First']
+            self.assertLess(firstFrom10Reverse, lastFrom10Reverse)
+            self.assertEqual(lastFrom10Reverse, lastFrom1000NewInstances)
+            self.assertLessEqual(firstFrom50Reverse, firstFrom10Reverse)
 
 
     def test_archive(self):