changeset 340:60775134a406

finalized webdav standalone tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Oct 2020 17:57:38 +0200
parents 44ab919be2e9
children 66a36befb208
files Plugins/WebDav/Run.py
diffstat 1 files changed, 46 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/WebDav/Run.py	Wed Oct 14 14:05:33 2020 +0200
+++ b/Plugins/WebDav/Run.py	Wed Oct 14 17:57:38 2020 +0200
@@ -284,6 +284,10 @@
         self.assertEqual(2, len(WEBDAV.ls(folder)))
         self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0]))
 
+        files = ListFiles('/webdav/by-patients/', True)
+        self.assertEqual(1, len(files))
+        self.assertEqual('%s/%s.dcm' % (folder, i), unquote(files[0]))
+        
         a = DownloadFile('%s/%s.dcm' % (folder, i))
         with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f:
             self.assertEqual(a, f.read())
@@ -310,8 +314,6 @@
         self.assertEqual('ozp00SjY2xG - KNIX - Knee (R)', study)
         self.assertEqual('MR - AX.  FSE PD', series)
 
-        self.assertEqual(1, len(ListFiles('/webdav/by-studies/', True)))
-        
         self.assertEqual(0, len(ListFiles('/webdav/by-studies/', False)))
         self.assertEqual(2, len(WEBDAV.ls('/webdav/by-studies/')))
         self.assertEqual(0, len(ListFiles('/webdav/by-studies/%s' % study, False)))
@@ -322,6 +324,10 @@
         self.assertEqual(2, len(WEBDAV.ls(folder)))
         self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0]))
 
+        files = ListFiles('/webdav/by-studies/', True)
+        self.assertEqual(1, len(files))
+        self.assertEqual('%s/%s.dcm' % (folder, i), unquote(files[0]))
+
         a = DownloadFile('%s/%s.dcm' % (folder, i))
         with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f:
             self.assertEqual(a, f.read())
@@ -332,6 +338,44 @@
         self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True)))
 
 
+    def test_by_dates(self):
+        self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True)))
+        self.assertEqual(1, len(WEBDAV.ls('/webdav/by-patients/')))
+        self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
+
+        i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
+        tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i)
+        year = tags['StudyDate'][0:4]
+        month = tags['StudyDate'][4:6]
+        study = '%s - %s - %s' % (tags['PatientID'], tags['PatientName'], tags['StudyDescription'])
+        series = '%s - %s' % (tags['Modality'], tags['SeriesDescription'])
+        self.assertEqual('ozp00SjY2xG - KNIX - Knee (R)', study)
+        self.assertEqual('MR - AX.  FSE PD', series)
+
+        self.assertEqual(0, len(ListFiles('/webdav/by-dates/', False)))
+        self.assertEqual(2, len(WEBDAV.ls('/webdav/by-dates/')))
+        self.assertEqual(0, len(ListFiles('/webdav/by-dates/%s' % year, False)))
+        self.assertEqual(2, len(WEBDAV.ls('/webdav/by-dates/%s' % year)))
+        self.assertEqual(0, len(ListFiles('/webdav/by-dates/%s/%s-%s' % (year, year, month), False)))
+        self.assertEqual(2, len(WEBDAV.ls('/webdav/by-dates/%s/%s-%s' % (year, year, month))))
+
+        folder = '/webdav/by-dates/%s/%s-%s/%s/%s' % (year, year, month, study, series)
+        self.assertEqual(1, len(ListFiles(folder, False)))
+        self.assertEqual(2, len(WEBDAV.ls(folder)))
+        self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0]))
+
+        files = ListFiles('/webdav/by-dates/', True)
+        self.assertEqual(1, len(files))
+        self.assertEqual('%s/%s.dcm' % (folder, i), unquote(files[0]))
+        
+        a = DownloadFile('%s/%s.dcm' % (folder, i))
+        with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f:
+            self.assertEqual(a, f.read())
+
+        self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
+        WEBDAV.delete('%s/%s.dcm' % (folder, i))
+        self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
+        self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True)))
 
         
 try: