changeset 59:84378ada15ab

test_decode_brainix_as_jpeg
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Nov 2015 09:56:47 +0100
parents b5518378e23b
children cd3c7f70f139
files Tests/Tests.py Tests/Toolbox.py
diffstat 2 files changed, 39 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Tests/Tests.py	Fri Nov 13 17:02:27 2015 +0100
+++ b/Tests/Tests.py	Wed Nov 18 09:56:47 2015 +0100
@@ -2521,3 +2521,40 @@
         ])
         z = zipfile.ZipFile(StringIO(s), "r")
         self.assertEqual(7, len(z.namelist()))
+
+
+    def test_decode_brainix_as_jpeg(self):
+        i = UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm')['ID']
+
+        j = GetImage(_REMOTE, '/instances/%s/preview' % i)
+        self.assertEqual('PNG', j.format)
+        self.assertEqual(j.size[0], 256)
+        self.assertEqual(j.size[1], 256)
+
+        j = GetImage(_REMOTE, '/instances/%s/preview' % i, headers = { 'Accept' : '*/*' })
+        self.assertEqual('PNG', j.format)
+
+        j = GetImage(_REMOTE, '/instances/%s/preview' % i, headers = { 'Accept' : 'image/*' })
+        self.assertEqual('PNG', j.format)
+
+        j = GetImage(_REMOTE, '/instances/%s/preview' % i, headers = { 'Accept' : 'image/png' })
+        self.assertEqual('PNG', j.format)
+
+        j = GetImage(_REMOTE, '/instances/%s/preview' % i, headers = { 'Accept' : 'image/jpeg' })
+        self.assertEqual('JPEG', j.format)
+        self.assertEqual(j.size[0], 256)
+        self.assertEqual(j.size[1], 256)
+
+        a = len(DoGet(_REMOTE, '/instances/%s/preview?quality=50' % i, headers = { 'Accept' : 'image/jpeg' }))
+        b = len(DoGet(_REMOTE, '/instances/%s/preview' % i, headers = { 'Accept' : 'image/jpeg' }))
+        self.assertLess(a, b)
+
+        j = GetImage(_REMOTE, '/instances/%s/image-uint8' % i, headers = { 'Accept' : 'image/jpeg' })
+        self.assertEqual('JPEG', j.format)
+
+        # 16bit encoding is not supported with JPEG
+        self.assertRaises(Exception, lambda: GetImage(_REMOTE, '/instances/%s/image-uint16' % i, headers = { 'Accept' : 'image/jpeg' }))
+        self.assertRaises(Exception, lambda: GetImage(_REMOTE, '/instances/%s/image-int16' % i, headers = { 'Accept' : 'image/jpeg' }))
+
+        # No matching content type
+        self.assertRaises(Exception, lambda: GetImage(_REMOTE, '/instances/%s/preview' % i, headers = { 'Accept' : 'application/pdf' }))
--- a/Tests/Toolbox.py	Fri Nov 13 17:02:27 2015 +0100
+++ b/Tests/Toolbox.py	Wed Nov 18 09:56:47 2015 +0100
@@ -171,9 +171,9 @@
     m.update(data)
     return m.hexdigest()
 
-def GetImage(orthanc, uri):
+def GetImage(orthanc, uri, headers = {}):
     # http://www.pythonware.com/library/pil/handbook/introduction.htm
-    data = DoGet(orthanc, uri)
+    data = DoGet(orthanc, uri, headers = headers)
     return Image.open(StringIO(data))
 
 def GetArchive(orthanc, uri):