comparison Tests/Tests.py @ 393:3019306499c5

test_revisions_attachments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Apr 2021 15:08:23 +0200
parents 5cbcb4a83b41
children e87d54a8a204
comparison
equal deleted inserted replaced
392:5cbcb4a83b41 393:3019306499c5
1231 DoPost(_REMOTE, '/patients/%s/attachments/1025/verify-md5' % patient) 1231 DoPost(_REMOTE, '/patients/%s/attachments/1025/verify-md5' % patient)
1232 DoPost(_REMOTE, '/patients/%s/attachments/1026/verify-md5' % patient) 1232 DoPost(_REMOTE, '/patients/%s/attachments/1026/verify-md5' % patient)
1233 DoPut(_REMOTE, '/patients/%s/attachments/1026' % patient, 'world2', headers = { 1233 DoPut(_REMOTE, '/patients/%s/attachments/1026' % patient, 'world2', headers = {
1234 'If-Match' : '0' 1234 'If-Match' : '0'
1235 }) 1235 })
1236 self.assertEqual('world2', DoGet(_REMOTE, '/patients/%s/attachments/1026/data' % patient)) 1236
1237 (header, body) = DoGetRaw(_REMOTE, '/patients/%s/attachments/1026/data' % patient)
1238 self.assertEqual('200', header['status'])
1239 self.assertEqual('world2', body)
1237 1240
1238 self.assertRaises(Exception, lambda: DoDelete(_REMOTE, '/instances/%s/attachments/dicom' % instance)) 1241 self.assertRaises(Exception, lambda: DoDelete(_REMOTE, '/instances/%s/attachments/dicom' % instance))
1239 DoDelete(_REMOTE, '/patients/%s/attachments/1025' % patient, headers = { 1242 DoDelete(_REMOTE, '/patients/%s/attachments/1025' % patient, headers = {
1240 'If-Match' : '0' 1243 'If-Match' : '0'
1241 }) 1244 })
1244 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), 1247 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']),
1245 size + int(DoGet(_REMOTE, '/patients/%s/attachments/1026/compressed-size' % patient))) 1248 size + int(DoGet(_REMOTE, '/patients/%s/attachments/1026/compressed-size' % patient)))
1246 1249
1247 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) 1250 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient)))
1248 DoDelete(_REMOTE, '/patients/%s/attachments/1026' % patient, headers = { 1251 DoDelete(_REMOTE, '/patients/%s/attachments/1026' % patient, headers = {
1249 'If-Match' : '0' 1252 'If-Match' : header['etag']
1250 }) 1253 })
1251 self.assertEqual(0, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) 1254 self.assertEqual(0, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient)))
1252 1255
1253 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), size) 1256 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), size)
1254 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) 1257 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize']))
6665 self.assertEqual('"0"', headers['etag']) 6668 self.assertEqual('"0"', headers['etag'])
6666 6669
6667 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/metadata/1024' % i, 'hello') 6670 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/metadata/1024' % i, 'hello')
6668 self.assertEqual('409', headers['status']) 6671 self.assertEqual('409', headers['status'])
6669 6672
6670 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/metadata/TransferSyntax' % i, headers = { 6673 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/metadata/1024' % i, headers = {
6671 'If-None-Match' : '"0"' 6674 'If-None-Match' : '"0"'
6672 }) 6675 })
6673 self.assertEqual('304', headers['status']) # Not modified 6676 self.assertEqual('304', headers['status']) # Not modified
6674 self.assertEqual('"0"', headers['etag']) 6677 self.assertEqual('"0"', headers['etag'])
6675 self.assertEqual('', body) # Body must be empty on 304 status 6678 self.assertEqual('', body) # Body must be empty on 304 status
6715 else: 6718 else:
6716 raise Exception('Internal error') 6719 raise Exception('Internal error')
6717 6720
6718 self.assertEqual('hello2', DoGet(_REMOTE, '/instances/%s/metadata/1024' % i)) 6721 self.assertEqual('hello2', DoGet(_REMOTE, '/instances/%s/metadata/1024' % i))
6719 6722
6723
6724 def test_revisions_attachments(self):
6725 # This test fails on Orthanc <= 1.9.1 (support for revisions
6726 # was introduced in 1.9.2), or if configuration option
6727 # "CheckRevisions" is "False". Conventions for HTTP headers
6728 # related to revisions mimic CouchDB:
6729 # https://docs.couchdb.org/en/stable/api/document/common.html
6730 i = UploadInstance(_REMOTE, 'DummyCT.dcm') ['ID']
6731
6732 # "/compress", "/uncompress" and "/verify-md5" are POST
6733 # methods, and are not affected by revisions
6734 for suffix in [ '', '/compressed-data', '/compressed-md5', '/compressed-size',
6735 '/data', '/is-compressed', '/md5', '/size' ]:
6736 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, suffix))
6737 self.assertEqual('200', headers['status'])
6738 self.assertEqual('"0"', headers['etag'])
6739
6740 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, suffix), headers = {
6741 'If-None-Match' : '"0"'
6742 })
6743 self.assertEqual('304', headers['status']) # Not modified
6744 self.assertEqual('"0"', headers['etag'])
6745 self.assertEqual('', body) # Body must be empty on 304 status
6746
6747 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom/%s' % (i, suffix), headers = {
6748 'If-None-Match' : '"1"'
6749 })
6750 self.assertEqual('200', headers['status'])
6751 self.assertEqual('"0"', headers['etag'])
6752
6753 (headers, body) = DoDeleteRaw(_REMOTE, '/instances/%s/attachments/dicom' % i)
6754 self.assertEqual('403', headers['status']) # Forbidden (system metadata)
6755
6756 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/dicom' % i, 'hello')
6757 self.assertEqual('403', headers['status']) # Forbidden (system metadata)
6758
6759 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello')
6760 self.assertEqual('200', headers['status'])
6761 self.assertEqual('"0"', headers['etag'])
6762
6763 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/1024/data' % i)
6764 self.assertEqual('200', headers['status'])
6765 self.assertEqual('"0"', headers['etag'])
6766 self.assertEqual('hello', body)
6767
6768 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/1024/data' % i, headers = {
6769 'If-None-Match' : '"0"'
6770 })
6771 self.assertEqual('304', headers['status'])
6772 self.assertEqual('"0"', headers['etag'])
6773 self.assertEqual('', body)
6774
6775 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/1024/data' % i, headers = {
6776 'If-None-Match' : '"1"'
6777 })
6778 self.assertEqual('200', headers['status'])
6779 self.assertEqual('"0"', headers['etag'])
6780 self.assertEqual('hello', body)
6781 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/attachments/1024/data' % i))
6782
6783 (headers, body) = DoDeleteRaw(_REMOTE, '/instances/%s/attachments/1024' % i)
6784 self.assertEqual('409', headers['status']) # No revision given, but "CheckRevisions" is True
6785
6786 (headers, body) = DoDeleteRaw(_REMOTE, '/instances/%s/attachments/1024' % i, headers = {
6787 'If-Match' : '45'
6788 })
6789 self.assertEqual('409', headers['status']) # Conflict, as bad revision
6790
6791 (headers, body) = DoDeleteRaw(_REMOTE, '/instances/%s/attachments/1024' % i, headers = {
6792 'If-Match' : '0'
6793 })
6794 self.assertEqual('200', headers['status'])
6795
6796 (headers, body) = DoDeleteRaw(_REMOTE, '/instances/%s/attachments/1024' % i, headers = {
6797 'If-Match' : '0'
6798 })
6799 self.assertEqual('404', headers['status'])
6800
6801 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/1024/data' % i)
6802 self.assertEqual('404', headers['status'])
6803
6804 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/attachments/1024' % i))
6805
6806 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello')
6807 self.assertEqual('200', headers['status'])
6808 self.assertEqual('"0"', headers['etag'])
6809
6810 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello')
6811 self.assertEqual('409', headers['status'])
6812
6813 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/1024/data' % i, headers = {
6814 'If-None-Match' : '"0"'
6815 })
6816 self.assertEqual('304', headers['status']) # Not modified
6817 self.assertEqual('"0"', headers['etag'])
6818 self.assertEqual('', body) # Body must be empty on 304 status
6819
6820 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello', headers = {
6821 'If-Match' : '0'
6822 })
6823 self.assertEqual('200', headers['status'])
6824 self.assertEqual('"1"', headers['etag'])
6825 self.assertEqual('{}', body)
6826
6827 (headers, body) = DoGetRaw(_REMOTE, '/instances/%s/attachments/1024/data' % i, headers = {
6828 'If-None-Match' : headers['etag']
6829 })
6830
6831 if headers['status'] == '200':
6832 print("Your database backend doesn't store revisions")
6833 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello2', headers = {
6834 'If-Match' : '1'
6835 })
6836 self.assertEqual('409', headers['status'])
6837
6838 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello2', headers = {
6839 'If-Match' : '0'
6840 })
6841 self.assertEqual('200', headers['status'])
6842 self.assertEqual('"1"', headers['etag'])
6843 self.assertEqual('{}', body)
6844
6845 elif headers['status'] == '304': # Revisions are supported
6846 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello2', headers = {
6847 'If-Match' : '0'
6848 })
6849 self.assertEqual('409', headers['status'])
6850
6851 (headers, body) = DoPutRaw(_REMOTE, '/instances/%s/attachments/1024' % i, 'hello2', headers = {
6852 'If-Match' : '1'
6853 })
6854 self.assertEqual('200', headers['status'])
6855 self.assertEqual('"2"', headers['etag'])
6856 self.assertEqual('{}', body)
6857
6858 else:
6859 raise Exception('Internal error')
6860
6861 self.assertEqual('hello2', DoGet(_REMOTE, '/instances/%s/attachments/1024/data' % i))