changeset 138:0682740fcfcb

cleanup
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 May 2018 11:08:58 +0200
parents 412d5f70447e
children 29433f28a368
files Tests/Tests.py Tests/Toolbox.py
diffstat 2 files changed, 22 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Tests/Tests.py	Thu May 24 21:43:40 2018 +0200
+++ b/Tests/Tests.py	Fri May 25 11:08:58 2018 +0200
@@ -1130,14 +1130,11 @@
         self.assertEqual(0, len(DoGet(_LOCAL, '/patients')))
 
         # 1 Matching patient, track the job
-        a = set(DoGet(_REMOTE, '/jobs'))
-        CallMoveScu([ '--patient', '-k', '0008,0052=PATIENT', '-k', 'PatientID=12345678' ])
-        b = set(DoGet(_REMOTE, '/jobs'))
-        
-        diff = list(b - a)
-        self.assertEqual(1, len(diff))
-        self.assertTrue(WaitJobDone(_REMOTE, diff[0]))
-
+        self.assertTrue(MonitorJob(_REMOTE, lambda: CallMoveScu([
+            '--patient',
+            '-k', '0008,0052=PATIENT',
+            '-k', 'PatientID=12345678'
+        ])))
         self.assertEqual(1, len(DoGet(_LOCAL, '/patients')))
 
 
@@ -2635,14 +2632,12 @@
         self.assertEqual(0, len(DoGet(_LOCAL, '/patients')))
 
         # 1 Matching patient, track the job
-        a = set(DoGet(_REMOTE, '/jobs'))
-        CallMoveScu([ '--study', '-k', '0008,0052=STUDY', '-k', 'AccessionNumber=A10003245599' ])
-        b = set(DoGet(_REMOTE, '/jobs'))
+        self.assertTrue(MonitorJob(_REMOTE, lambda: CallMoveScu([
+            '--study',
+            '-k', '0008,0052=STUDY',
+            '-k', 'AccessionNumber=A10003245599'
+        ])))
         
-        diff = list(b - a)
-        self.assertEqual(1, len(diff))
-        self.assertTrue(WaitJobDone(_REMOTE, diff[0]))
-
         self.assertEqual(1, len(DoGet(_LOCAL, '/patients')))
 
 
--- a/Tests/Toolbox.py	Thu May 24 21:43:40 2018 +0200
+++ b/Tests/Toolbox.py	Fri May 25 11:08:58 2018 +0200
@@ -223,6 +223,18 @@
         
         time.sleep(0.1)
 
+def MonitorJob(orthanc, func):  # "func" is a lambda
+    a = set(DoGet(orthanc, '/jobs'))
+    func()
+    b = set(DoGet(orthanc, '/jobs'))
+        
+    diff = list(b - a)
+    if len(diff) != 1:
+        print('No job was created!')
+        return False
+    else:
+        return WaitJobDone(orthanc, diff[0])
+
 def GetDockerHostAddress():
     route = subprocess.check_output([ '/sbin/ip', 'route' ])
     m = re.search(r'default via ([0-9.]+)', route)