Mercurial > hg > orthanc-tests
changeset 748:09d3e251b783
added test_attachment_range
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 04 Dec 2024 18:14:01 +0100 |
parents | d21ff981e7a1 |
children | 27a955d3d05f |
files | Tests/Tests.py |
diffstat | 1 files changed, 102 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Tests/Tests.py Fri Nov 15 09:39:01 2024 +0100 +++ b/Tests/Tests.py Wed Dec 04 18:14:01 2024 +0100 @@ -10784,3 +10784,105 @@ self.assertEqual(1, int(a[0]['RequestedTags']['NumberOfStudyRelatedInstances'])) self.assertEqual('CT', a[0]['RequestedTags']['ModalitiesInStudy']) self.assertEqual('', a[0]['RequestedTags']['PatientComments']) + + + def test_attachment_range(self): + def TestData(path): + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, path)) + self.assertFalse('content-range' in resp) + self.assertEqual(200, resp.status) + self.assertEqual(2472, len(content)) + self.assertEqual('2472', resp['content-length']) + self.assertEqual('application/dicom', resp['content-type']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, path), headers = { 'Range' : 'bytes=128-131' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(4, len(content)) + self.assertEqual('D', content[0]) + self.assertEqual('I', content[1]) + self.assertEqual('C', content[2]) + self.assertEqual('M', content[3]) + self.assertEqual('4', resp['content-length']) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 128-131/2472', resp['content-range']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, path), headers = { 'Range' : 'bytes=-' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(2472, len(content)) + self.assertEqual('2472', resp['content-length']) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 0-2471/2472', resp['content-range']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, path), headers = { 'Range' : 'bytes=128-' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(2344, len(content)) + self.assertEqual('D', content[0]) + self.assertEqual('I', content[1]) + self.assertEqual('C', content[2]) + self.assertEqual('M', content[3]) + self.assertEqual('2344', resp['content-length']) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 128-2471/2472', resp['content-range']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, path), headers = { 'Range' : 'bytes=-131' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(132, len(content)) + self.assertEqual('D', content[-4]) + self.assertEqual('I', content[-3]) + self.assertEqual('C', content[-2]) + self.assertEqual('M', content[-1]) + self.assertEqual('132', resp['content-length']) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 0-131/2472', resp['content-range']) + + i = UploadInstance(_REMOTE, 'DummyCT.dcm') ['ID'] + + DoPost(_REMOTE, '/instances/%s/attachments/dicom/uncompress' % i) + TestData('data') + TestData('compressed-data') + + DoPost(_REMOTE, '/instances/%s/attachments/dicom/compress' % i) + TestData('data') + + (resp, compressed) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/compressed-data' % i) + self.assertFalse('content-range' in resp) + self.assertEqual(200, resp.status) + self.assertTrue(len(compressed) < 2000) + self.assertEqual(len(compressed), int(resp['content-length'])) + self.assertEqual('application/octet-stream', resp['content-type']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/compressed-data' % i, headers = { 'Range' : 'bytes=-' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(compressed, content) + self.assertEqual(len(compressed), int(resp['content-length'])) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 0-%d/%d' % (len(compressed) - 1, len(compressed)), resp['content-range']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/compressed-data' % i, headers = { 'Range' : 'bytes=10-' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(compressed[10:], content) + self.assertEqual(len(compressed) - 10, int(resp['content-length'])) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 10-%d/%d' % (len(compressed) - 1, len(compressed)), resp['content-range']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/compressed-data' % i, headers = { 'Range' : 'bytes=-20' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(compressed[0:21], content) + self.assertEqual(21, int(resp['content-length'])) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 0-20/%d' % len(compressed), resp['content-range']) + + (resp, content) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/compressed-data' % i, headers = { 'Range' : 'bytes=10-20' }) + self.assertTrue('content-range' in resp) + self.assertEqual(206, resp.status) + self.assertEqual(compressed[10:21], content) + self.assertEqual(11, int(resp['content-length'])) + self.assertEqual('application/octet-stream', resp['content-type']) + self.assertEqual('bytes 10-20/%d' % len(compressed), resp['content-range'])