changeset 358:458b2d887ea0

WebDAV: test_upload_zip
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Dec 2020 15:22:41 +0100
parents 18597ca05e48
children 8b476a383999
files Plugins/WebDav/Run.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/WebDav/Run.py	Tue Dec 08 15:02:42 2020 +0100
+++ b/Plugins/WebDav/Run.py	Tue Dec 08 15:22:41 2020 +0100
@@ -412,6 +412,36 @@
                 WEBDAV.delete(p)
                 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
 
+
+    def test_upload_zip(self):
+        f = StringIO()
+        with zipfile.ZipFile(f, 'w') as z:
+            z.writestr('hello/world/invalid.txt', 'Hello world')
+            with open(GetDatabasePath('DummyCT.dcm'), 'rb') as g:
+                c = g.read()
+                z.writestr('hello/world/dicom1.dcm', c)
+                z.writestr('hello/world/dicom2.dcm', c)
+
+        f.seek(0)
+        archive = f.read()
+        
+        self.assertEqual(0, len(DoGet(ORTHANC, '/studies')))
+
+        with tempfile.NamedTemporaryFile(delete = True) as f:
+            f.close()
+            with open(f.name, 'wb') as g:
+                g.write(archive)
+            WEBDAV.upload(f.name, '/webdav/uploads/DummyCT.zip')
+            os.unlink(f.name)
+
+        while len(ListFiles('/webdav/uploads/', True)) > 1:
+            time.sleep(0.1)
+        time.sleep(0.1)  # Give some more delay to be sure that the store has succeeded (necessary for Wine)
+        
+        instances = DoGet(ORTHANC, '/instances')
+        self.assertEqual(1, len(instances))
+        self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', instances[0])
+                
         
 try:
     print('\nStarting the tests...')