Skip to content

Commit 6bd3bb7

Browse files
committed
[#28] fixed broken test for getResultsBySimulationID
1 parent 381a1f5 commit 6bd3bb7

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

odm2api/ODM2/services/readService.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,11 @@ def getRelatedModelsByCode(self, modelcode):
964964

965965
def getResultsBySimulationID(self, simulationID):
966966
try:
967-
return self._session.query(Results).filter(Simulations.SimulationID == simulationID).all()
967+
return self._session.query(Results) \
968+
.join(FeatureActions) \
969+
.join(Actions) \
970+
.join(Simulations) \
971+
.filter(Simulations.SimulationID == simulationID).all()
968972
except Exception, e:
969973
print e
970974
return None

tests/test_odm2/test_readservice.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,21 @@ def test_getResultsBySimulationID(self):
214214
res = self.engine.execute('SELECT * FROM Simulations').fetchone()
215215
simulation = rawSql2Alchemy(res, models.Simulations)
216216

217+
# get the results id associated with the simulation
218+
res = self.engine.execute('SELECT * from Results as r '\
219+
'inner join FeatureActions as fa on fa.FeatureActionID == r.FeatureActionID ' \
220+
'inner join Actions as a on a.ActionID == fa.ActionID ' \
221+
'inner join Simulations as s on s.ActionID == a.ActionID '\
222+
'where s.SimulationID = 1').first()
223+
assert len(res) > 0
224+
res = rawSql2Alchemy(res, models.Results)
225+
print res
226+
217227
# get simulation by id using the api
218228
resapi = self.reader.getResultsBySimulationID(simulation.SimulationID)
219229
assert resapi is not None
220230
assert len(resapi) > 0
231+
assert res.ResultID == resapi[0].ResultID
221232

222-
# test simulation id that doesnt exist
223-
resapi = self.reader.getResultsBySimulationID(10)
224-
assert resapi is not None
225-
assert len(resapi) == 0
226-
227-
# test invalid argument
228-
resapi = self.reader.getResultsBySimulationID(models.ActionBy)
229-
assert resapi is None
230233

231234

0 commit comments

Comments
 (0)