Mercurial > hg > orthanc-tests
comparison PerfsDb/TestConfig.py @ 156:f1a75985caa8
first Db test framework - work in progress
author | am@osimis.io |
---|---|
date | Thu, 16 Aug 2018 17:13:32 +0200 |
parents | |
children | df1f9946571c |
comparison
equal
deleted
inserted
replaced
155:e0996602b306 | 156:f1a75985caa8 |
---|---|
1 import typing | |
2 import subprocess | |
3 import os | |
4 from orthancRestApi import OrthancClient | |
5 | |
6 from DbSize import DbSize | |
7 from DbType import DbType | |
8 from ConfigFileBuilder import ConfigFileBuilder | |
9 from DbServer import DbServer | |
10 from DbPopulator import DbPopulator | |
11 from Tests import * | |
12 from TestResult import TestResult | |
13 | |
14 class TestConfig: | |
15 | |
16 def __init__(self, | |
17 label: str, | |
18 dbSize: DbSize, | |
19 dbType: DbType=None, | |
20 dbServer: DbServer=None | |
21 ): | |
22 | |
23 self._dbSize = dbSize | |
24 self._dbServer = dbServer | |
25 self._label = label | |
26 self._port = None | |
27 self._name = "unknown" | |
28 self._orthancProcess = None | |
29 self._repeatCount = 10 | |
30 | |
31 if dbServer is not None: | |
32 self._dbType = dbServer.dbType | |
33 self._dbServer.setLabel(self._label) | |
34 self._port = dbServer.port | |
35 else: | |
36 self._dbType = dbType | |
37 | |
38 def setName(self, name: str): | |
39 self._name = name | |
40 | |
41 def setRepeatCount(self, repeatCount: int): | |
42 self._repeatCount = repeatCount | |
43 | |
44 def launchDbServer(self): | |
45 if self._dbServer is not None: | |
46 self._dbServer.launch() | |
47 | |
48 def launchOrthanc(self, orthancPath): | |
49 orthanc = OrthancClient("http://127.0.0.1:8042") | |
50 | |
51 print("Checking if Orthanc is already running") | |
52 if orthanc.isAlive(): | |
53 print("Orthanc is already running") | |
54 return | |
55 | |
56 print("Launching Orthanc") | |
57 self._orthancProcess = subprocess.Popen([ | |
58 os.path.join(orthancPath, "Orthanc"), | |
59 os.path.join("ConfigFiles", self._name + ".json"), | |
60 ]) | |
61 | |
62 print("Waiting for Orthanc to start") | |
63 orthanc.waitStarted(timeout=30) | |
64 print("Orthanc has started") | |
65 | |
66 def stopOrthanc(self): | |
67 if self._orthancProcess is not None: | |
68 self._orthancProcess.terminate() | |
69 self._orthancProcess.wait() | |
70 | |
71 def initializeDb(self): | |
72 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | |
73 dbPopulator.populate() | |
74 | |
75 def runTests(self) -> typing.List[TestResult]: | |
76 allTests = [ | |
77 TestFindStudyByStudyDescription1Result(), | |
78 TestFindStudyByPatientId1Result(), | |
79 TestFindStudyByStudyDescription0Results(), | |
80 TestFindStudyByPatientId0Results(), | |
81 TestFindStudyByPatientId5Results(), | |
82 TestUploadFile() | |
83 ] | |
84 | |
85 results = [] | |
86 for test in allTests: | |
87 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) | |
88 test.setRepeatCount(self._repeatCount) | |
89 result = test.run() | |
90 print(str(result)) | |
91 | |
92 results.append(result) | |
93 return results | |
94 | |
95 def clearDb(self): | |
96 if self._dbServer is not None: | |
97 self._dbServer.clear() | |
98 | |
99 def generateOrthancConfigurationFile(self, pluginsPath: str): | |
100 | |
101 ConfigFileBuilder.generate( | |
102 outputPath="ConfigFiles/{name}.json".format(name=self._name), | |
103 plugins=[pluginsPath], | |
104 storagePath="Storages/{name}".format(name=self._name), | |
105 dbType=self._dbType, | |
106 dbSize=self._dbSize, | |
107 port=self._port | |
108 ) |