changeset 173:ed3db6386587

testing overwrite
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Sep 2018 15:26:17 +0200
parents ead4353854ad
children d468cbe1b161
files Database/DummyCT-overwrite.dcm GenerateConfigurationForTests.py Tests/Tests.py Tests/Toolbox.py
diffstat 4 files changed, 65 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
Binary file Database/DummyCT-overwrite.dcm has changed
--- a/GenerateConfigurationForTests.py	Wed Sep 12 09:25:37 2018 +0200
+++ b/GenerateConfigurationForTests.py	Wed Sep 19 15:26:17 2018 +0200
@@ -111,6 +111,7 @@
 config['OrthancPeers'] = { 'peer' : [ 'http://%s:%d/' % (ip, 5000), 'alice', 'orthanctest' ] }
 config['RegisteredUsers'] = { 'alice' : 'orthanctest' }
 config['RemoteAccessAllowed'] = True
+config['OverwriteInstances'] = True
 
 config['Dictionary'] = {
     '00e1,10c2' : [ 'UI', 'PET-CT Multi Modality Name', 1, 1, 'ELSCINT1' ],
--- a/Tests/Tests.py	Wed Sep 12 09:25:37 2018 +0200
+++ b/Tests/Tests.py	Wed Sep 19 15:26:17 2018 +0200
@@ -156,23 +156,70 @@
 
 
     def test_system(self):
+        self.assertTrue(IsOrthancVersionAbove(_LOCAL, 0, 8, 6))
+        self.assertFalse(IsOrthancVersionAbove(_LOCAL, 0, 8, 7))
+        self.assertTrue(IsOrthancVersionAbove(_LOCAL, 0, 7, 6))
+        self.assertFalse(IsOrthancVersionAbove(_LOCAL, 0, 9, 6))
+        self.assertFalse(IsOrthancVersionAbove(_LOCAL, 1, 8, 6))
         self.assertTrue('Version' in DoGet(_REMOTE, '/system'))
         self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
         self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
 
     def test_upload(self):
+        self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
+        self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
+
+        sizeDummyCT = 2472
+        sizeOverwrite = 2476
+        instance = '66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d'
+
         u = UploadInstance(_REMOTE, 'DummyCT.dcm')
         self.assertEqual('Success', u['Status'])
+
+        j = int(DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/size' % instance))
+        s = sizeDummyCT + j
+        self.assertEqual('%d' % s, DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
+        self.assertEqual('%d' % s, DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
+
         u = UploadInstance(_REMOTE, 'DummyCT.dcm')
-        self.assertEqual('AlreadyStored', u['Status'])
         self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
         self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
         self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
         self.assertEqual(1, len(DoGet(_REMOTE, '/instances')))
-
-        i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % u['ID'])
+        self.assertEqual('%d' % s, DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
+        self.assertEqual('%d' % s, DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
+
+        i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % instance)
         self.assertEqual('20070101', i['StudyDate'])
-
+        self.assertEqual('KNIX', i['PatientName'])
+
+        if IsOrthancVersionAbove(_REMOTE, 1, 4, 2):
+            # Overwriting
+            self.assertEqual('Success', u['Status'])
+        else:
+            self.assertEqual('AlreadyStored', u['Status'])
+
+        u = UploadInstance(_REMOTE, 'DummyCT-overwrite.dcm')
+        self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
+        self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
+        self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
+        self.assertEqual(1, len(DoGet(_REMOTE, '/instances')))
+
+        if IsOrthancVersionAbove(_REMOTE, 1, 4, 2):
+            # Overwriting
+            self.assertEqual('Success', u['Status'])
+            j2 = int(DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/size' % instance))
+            s2 = sizeOverwrite + j2
+            self.assertNotEqual(s, s2)
+            self.assertNotEqual(j, j2)
+            self.assertEqual('%d' % s2, DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
+            self.assertEqual('%d' % s2, DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
+            i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % instance)
+            self.assertEqual('ANOTHER', i['PatientName'])
+        else:
+            self.assertEqual('AlreadyStored', u['Status'])
+            self.assertEqual('%d' % s, DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
+            self.assertEqual('%d' % s, DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
 
     def test_upload_2(self):
         i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID']
--- a/Tests/Toolbox.py	Wed Sep 12 09:25:37 2018 +0200
+++ b/Tests/Toolbox.py	Wed Sep 19 15:26:17 2018 +0200
@@ -254,6 +254,19 @@
 
     return name
 
+def IsOrthancVersionAbove(orthanc, major, minor, revision):
+    v = DoGet(orthanc, '/system')['Version']
+
+    if v == 'mainline':
+        return True
+    else:
+        tmp = v.split('.')
+        a = int(tmp[0])
+        b = int(tmp[1])
+        c = int(tmp[2])
+        return (a > major or
+                (a == major and b > minor) or
+                (a == major and b == minor and c >= revision))
 
 
 class ExternalCommandThread: