comparison Tests/Tests.py @ 603:75244cf58a6d

new test for KeepLabels
author Alain Mazy <am@osimis.io>
date Mon, 22 Jan 2024 17:12:08 +0100
parents b6c1f0c9ca15
children 8fb9b5cd0f4f
comparison
equal deleted inserted replaced
602:d88b0fc15f08 603:75244cf58a6d
10041 10041
10042 # responses with bodies contain x-content-type-options 10042 # responses with bodies contain x-content-type-options
10043 if IsOrthancVersionAbove(_REMOTE, 1, 12, 2): 10043 if IsOrthancVersionAbove(_REMOTE, 1, 12, 2):
10044 (headers, body) = DoGetRaw(_REMOTE, '/system') 10044 (headers, body) = DoGetRaw(_REMOTE, '/system')
10045 self.assertIn('nosniff', headers['x-content-type-options']) 10045 self.assertIn('nosniff', headers['x-content-type-options'])
10046
10047 def test_modify_with_labels(self):
10048
10049 def UploadAndLabel(testId):
10050 DropOrthanc(_REMOTE)
10051
10052 u = UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm')
10053 studyId = u["ParentStudy"]
10054 seriesId = u["ParentSeries"]
10055 patientId = u["ParentPatient"]
10056 instanceId = u["ID"]
10057
10058 if testId == 2: # multi instance study
10059 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0002.dcm')
10060 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
10061 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0002.dcm')
10062
10063 # add a label to the study before modification
10064 DoPut(_REMOTE, '/patients/%s/labels/label-patient' % patientId)
10065 DoPut(_REMOTE, '/studies/%s/labels/label-study' % studyId)
10066 DoPut(_REMOTE, '/series/%s/labels/label-series' % seriesId)
10067 DoPut(_REMOTE, '/instances/%s/labels/label-instance' % instanceId)
10068
10069 originalPatient = DoGet(_REMOTE, '/patients/%s' % patientId)
10070 self.assertEqual(1, len(originalPatient["Labels"]))
10071 self.assertIn('label-patient', originalPatient["Labels"])
10072
10073 originalStudy = DoGet(_REMOTE, '/studies/%s' % studyId)
10074 self.assertEqual(1, len(originalStudy["Labels"]))
10075 self.assertIn('label-study', originalStudy["Labels"])
10076
10077 originalSeries = DoGet(_REMOTE, '/series/%s' % seriesId)
10078 self.assertEqual(1, len(originalSeries["Labels"]))
10079 self.assertIn('label-series', originalSeries["Labels"])
10080
10081 originalInstance = DoGet(_REMOTE, '/instances/%s' % instanceId)
10082 self.assertEqual(1, len(originalInstance["Labels"]))
10083 self.assertIn('label-instance', originalInstance["Labels"])
10084
10085 return originalPatient, originalStudy, originalSeries, originalInstance
10086
10087
10088 for testId in range(1, 2): #test with a single instance study and a multi instance study
10089
10090 originalPatient, originalStudy, originalSeries, originalInstance = UploadAndLabel(testId)
10091
10092 # modify a study in place with no label field in the payload (default behavior before 1.12.3)
10093 DoPost(_REMOTE, '/studies/%s/modify' % originalStudy['ID'], {
10094 'Keep' : ['StudyInstanceUID', 'SeriesInstanceUID', 'SOPInstanceUID'],
10095 'Replace' : {
10096 'PatientName': 'modified'
10097 },
10098 'Force': True
10099 })
10100
10101 # with no options, all resources lose their labels during the modification
10102 modifiedStudy = DoGet(_REMOTE, '/studies/%s' % originalStudy['ID'])
10103 self.assertEqual(0, len(modifiedStudy["Labels"]))
10104 self.assertEqual('modified', modifiedStudy["PatientMainDicomTags"]["PatientName"])
10105
10106 if IsOrthancVersionAbove(_REMOTE, 1, 12, 3):
10107
10108 for testId in range(1, 2): #test with a single instance study and a multi instance study
10109
10110 originalPatient, originalStudy, originalSeries, originalInstance = UploadAndLabel(testId)
10111
10112 # modify a study in place with no label field in the payload (default behavior before 1.12.3)
10113 DoPost(_REMOTE, '/studies/%s/modify' % originalStudy['ID'], {
10114 'Keep' : ['StudyInstanceUID', 'SeriesInstanceUID', 'SOPInstanceUID'],
10115 'Replace' : {
10116 'PatientName': 'modified2'
10117 },
10118 'Force': True,
10119 'KeepLabels': True
10120 })
10121
10122 # now, each resource level shall have kept its labels
10123
10124 modifiedInstance = DoGet(_REMOTE, '/instances/%s' % originalInstance['ID'])
10125 self.assertEqual(1, len(modifiedInstance["Labels"]))
10126 self.assertIn('label-instance', modifiedInstance["Labels"])
10127
10128 modifiedSeries = DoGet(_REMOTE, '/series/%s' % originalSeries['ID'])
10129 self.assertEqual(1, len(modifiedSeries["Labels"]))
10130 self.assertIn('label-series', modifiedSeries["Labels"])
10131
10132 modifiedStudy = DoGet(_REMOTE, '/studies/%s' % originalStudy['ID'])
10133 self.assertEqual(1, len(modifiedStudy["Labels"]))
10134 self.assertIn('label-study', modifiedStudy["Labels"])
10135 self.assertEqual('modified2', modifiedStudy["PatientMainDicomTags"]["PatientName"])
10136
10137 modifiedPatient = DoGet(_REMOTE, '/patients/%s' % originalPatient['ID'])
10138 self.assertEqual(1, len(modifiedPatient["Labels"]))
10139 self.assertIn('label-patient', modifiedPatient["Labels"])
10140