comparison Plugins/DicomWeb/Run.py @ 558:0ad170c7b6c8

reactivation of test_issue_216, as the fix is now in the mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Jun 2023 10:38:35 +0200
parents 739cad709a8c
children 87fc87897e7e 2c809c605592
comparison
equal deleted inserted replaced
557:1cdb14a679f2 558:0ad170c7b6c8
31 # } 31 # }
32 # } 32 # }
33 33
34 34
35 35
36 import argparse
36 import copy 37 import copy
37 import os 38 import os
38 import pprint 39 import pprint
40 import re
39 import sys 41 import sys
40 import argparse
41 import unittest 42 import unittest
42 import re 43 import xml.dom.minidom
43 from PIL import ImageChops 44 from PIL import ImageChops
44 45
45 from DicomWeb import * 46 from DicomWeb import *
46 47
47 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) 48 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
1689 'X-Forwarded-Proto': 'https' 1690 'X-Forwarded-Proto': 'https'
1690 }) 1691 })
1691 self.assertIn("https://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI']) 1692 self.assertIn("https://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI'])
1692 1693
1693 1694
1694 @unittest.skip("Not implemented yet")
1695 def test_issue_216(self): 1695 def test_issue_216(self):
1696 if IsOrthancVersionAbove(ORTHANC, 1, 12, 1): 1696 study = UploadInstance(ORTHANC, 'ColorTestImageJ.dcm')['ParentStudy']
1697 study = UploadInstance(ORTHANC, 'ColorTestImageJ.dcm')['ParentStudy'] 1697 studyUid = DoGet(ORTHANC, '/studies/%s' % study)['MainDicomTags']['StudyInstanceUID']
1698 studyUid = DoGet(ORTHANC, '/studies/%s' % study)['MainDicomTags']['StudyInstanceUID'] 1698
1699 1699 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = {
1700 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = { 1700 'accept': 'image/webp, */*;q=0.8, text/html, application/xhtml+xml, application/xml;q=0.9'
1701 'accept': 'image/webp, */*;q=0.8, text/html, application/xhtml+xml, application/xml;q=0.9' 1701 })
1702 self.assertEqual(1, len(m))
1703 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0])
1704
1705 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = {
1706 'accept': 'text/html, application/xhtml+xml, application/xml, image/webp, */*;q=0.8'
1707 })
1708 self.assertEqual(1, len(m))
1709 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0])
1710
1711 # This fails on DICOMweb <= 1.13 because of the "; q=.2",
1712 # since multiple accepts were not supported
1713 # https://bugs.orthanc-server.com/show_bug.cgi?id=216
1714 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = {
1715 'accept': 'text/html, image/gif, image/jpeg, */*; q=.2, */*; q=.2'
1716 })
1717 self.assertEqual(1, len(m))
1718 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0])
1719
1720 # This fails on Orthanc <= 1.12.0 because of the ";q=0.9"
1721 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = {
1722 'accept': 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8'
1723 })
1724 self.assertEqual(1, len(m))
1725 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0])
1726
1727
1728 def test_accept_negotiation(self):
1729 def CheckBadRequest(uri, accept):
1730 response = DoGetRaw(ORTHANC, uri, headers = {
1731 'accept': accept
1702 }) 1732 })
1703 self.assertEqual(1, len(m)) 1733 self.assertEqual(int(response[0]['status']), 400)
1704 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0]) 1734
1705 1735 def CheckIsJson(uri, accept):
1706 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = { 1736 if accept != None:
1707 'accept': 'text/html, application/xhtml+xml, application/xml, image/webp, */*;q=0.8' 1737 response = DoGetRaw(ORTHANC, uri, headers = {
1708 }) 1738 'accept': accept
1709 self.assertEqual(1, len(m)) 1739 })
1710 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0]) 1740 else:
1711 1741 response = DoGetRaw(ORTHANC, uri)
1712 # This fails on Orthanc <= 1.12.0 because of the "; q=.2" 1742 self.assertEqual(int(response[0]['status']), 200)
1713 # https://bugs.orthanc-server.com/show_bug.cgi?id=216 1743 self.assertEqual(response[0]['content-type'], 'application/dicom+json')
1714 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = { 1744 json.loads(response[1])
1715 'accept': 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2' 1745
1716 }) 1746 def CheckIsXml(uri, accept):
1717 self.assertEqual(1, len(m)) 1747 response = DoGetMultipart(ORTHANC, uri, headers = {
1718 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0]) 1748 'accept': accept
1719 1749 }, returnHeaders = True)
1720 # This fails on Orthanc <= 1.12.0 because of the ";q=0.9" 1750 self.assertEqual(1, len(response))
1721 m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyUid, headers = { 1751 self.assertEqual(2, len(response[0]))
1722 'accept': 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8' 1752 self.assertEqual('application/dicom+xml', response[0][1]['Content-Type'])
1723 }) 1753 xml.dom.minidom.parseString(response[0][0])
1724 self.assertEqual(1, len(m)) 1754
1725 self.assertEqual(studyUid, m[0]['0020000D']['Value'][0]) 1755 study = UploadInstance(ORTHANC, 'ColorTestImageJ.dcm')['ParentStudy']
1756 studyUid = DoGet(ORTHANC, '/studies/%s' % study)['MainDicomTags']['StudyInstanceUID']
1757
1758 CheckIsJson('/dicom-web/studies/%s/metadata' % studyUid, None)
1759 CheckBadRequest('/dicom-web/studies/%s/metadata' % studyUid, 'application/nope')
1760 CheckIsJson('/dicom-web/studies/%s/metadata' % studyUid, 'application/json')
1761 CheckIsJson('/dicom-web/studies/%s/metadata' % studyUid, 'application/dicom+json')
1762 CheckBadRequest('/dicom-web/studies/%s/metadata' % studyUid, 'multipart/related')
1763 CheckIsXml('/dicom-web/studies/%s/metadata' % studyUid, 'multipart/related; type=application/dicom+xml')
1764 CheckIsXml('/dicom-web/studies/%s/metadata' % studyUid, 'multipart/related; type="application/dicom+xml"')
1765 CheckBadRequest('/dicom-web/studies/%s/metadata' % studyUid, 'multipart/related; type="application/nope"')
1766 CheckBadRequest('/dicom-web/studies/%s/metadata' % studyUid, 'multipart/related; type=application/dicom+xml; transfer-syntax=nope')
1726 1767
1727 1768
1728 try: 1769 try:
1729 print('\nStarting the tests...') 1770 print('\nStarting the tests...')
1730 unittest.main(argv = [ sys.argv[0] ] + args.options) 1771 unittest.main(argv = [ sys.argv[0] ] + args.options)