diff Plugins/DicomWeb/Run.py @ 559:87fc87897e7e

test_accept_negotiation for multipart DICOM
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Jun 2023 11:18:45 +0200
parents 0ad170c7b6c8
children 2db7a9041507
line wrap: on
line diff
--- a/Plugins/DicomWeb/Run.py	Wed Jun 28 10:38:35 2023 +0200
+++ b/Plugins/DicomWeb/Run.py	Wed Jun 28 11:18:45 2023 +0200
@@ -37,6 +37,7 @@
 import copy
 import os
 import pprint
+import pydicom
 import re
 import sys
 import unittest
@@ -1752,6 +1753,18 @@
             self.assertEqual('application/dicom+xml', response[0][1]['Content-Type'])
             xml.dom.minidom.parseString(response[0][0])
 
+        def CheckIsDicom(uri, accept):
+            if accept != None:
+                response = DoGetMultipart(ORTHANC, uri, headers = {
+                    'accept': accept
+                }, returnHeaders = True)
+            else:
+                response = DoGetMultipart(ORTHANC, uri, returnHeaders = True)
+            self.assertEqual(1, len(response))
+            self.assertEqual(2, len(response[0]))
+            self.assertEqual('application/dicom', response[0][1]['Content-Type'])
+            pydicom.dcmread(BytesIO(response[0][0]), force=True)
+
         study = UploadInstance(ORTHANC, 'ColorTestImageJ.dcm')['ParentStudy']
         studyUid = DoGet(ORTHANC, '/studies/%s' % study)['MainDicomTags']['StudyInstanceUID']
 
@@ -1765,6 +1778,17 @@
         CheckBadRequest('/dicom-web/studies/%s/metadata' % studyUid, 'multipart/related; type="application/nope"')
         CheckBadRequest('/dicom-web/studies/%s/metadata' % studyUid, 'multipart/related; type=application/dicom+xml; transfer-syntax=nope')
 
+        CheckBadRequest('/dicom-web/studies/%s' % studyUid, 'multipart/nope')
+        CheckIsDicom('/dicom-web/studies/%s' % studyUid, None)
+        CheckIsDicom('/dicom-web/studies/%s' % studyUid, 'multipart/related')
+        CheckIsDicom('/dicom-web/studies/%s' % studyUid, 'multipart/related; type=application/dicom')
+        CheckIsDicom('/dicom-web/studies/%s' % studyUid, 'multipart/related; type="application/dicom"')
+        CheckBadRequest('/dicom-web/studies/%s' % studyUid, 'multipart/related; type=application/nope')
+        CheckIsDicom('/dicom-web/studies/%s' % studyUid, 'multipart/related; transfer-syntax=*')
+        CheckIsDicom('/dicom-web/studies/%s' % studyUid, 'multipart/related; type=application/dicom; transfer-syntax=*')
+        CheckBadRequest('/dicom-web/studies/%s' % studyUid, 'multipart/related; transfer-syntax=nope')
+        CheckIsDicom('/dicom-web/studies/%s' % studyUid, 'multipart/related; type=application/dicom; transfer-syntax=1.2.840.10008.1.2.1')
+
 
 try:
     print('\nStarting the tests...')