4
4
from odm2api .ODM2 import models
5
5
from odm2api .ODMconnection import dbconnection
6
6
from odm2api .ODM2 .services .createService import CreateODM2
7
+ import uuid
7
8
# run this test from the root directory using:
8
9
# python -m pytest tests/test_odm2/test_createservice.py
9
10
@@ -63,8 +64,8 @@ def test_createVariable(self):
63
64
nodv = - 9999
64
65
speciation = "mg/L as PO4"
65
66
definition = "This is a test variable"
66
- v = models .Variables (VariableCode = code , VariableNameCV = name , VariableTypeCV = vType , NoDataValue = nodv , SpeciationCV = speciation ,
67
- VariableDefinition = definition )
67
+ v = models .Variables (VariableCode = code , VariableNameCV = name , VariableTypeCV = vType , NoDataValue = nodv , SpeciationCV = None ,
68
+ VariableDefinition = None )
68
69
# self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=None)
69
70
self .writer .createVariable (v )
70
71
# assert that this dataset has been successfully inserted
@@ -77,9 +78,9 @@ def test_createVariable(self):
77
78
assert (res [5 ] == None ) # speciation
78
79
assert (res [6 ] == nodv ) # nodata
79
80
80
- v = models .Variables (VariableCode = code , VariableName = name , VariableTypeCV = vType , NoDataValue = nodv , Speciation = speciation ,
81
- Definition = definition )
82
- # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None ,definition=None)
81
+ v = models .Variables (VariableCode = code , VariableNameCV = name , VariableTypeCV = vType , NoDataValue = nodv , SpeciationCV = speciation ,
82
+ VariableDefinition = None )
83
+ # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=speciation ,definition=None)
83
84
self .writer .createVariable (v )
84
85
85
86
# assert that this dataset has been successfully inserted
@@ -92,9 +93,9 @@ def test_createVariable(self):
92
93
assert (res [5 ] == speciation ) # speciation
93
94
assert (res [6 ] == nodv ) # nodata
94
95
95
- v = models .Variables (VariableCode = code , VariableName = name , VariableTypeCV = vType , NoDataValue = nodv , Speciation = speciation ,
96
- Definition = definition )
97
- # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=None )
96
+ v = models .Variables (VariableCode = code , VariableNameCV = name , VariableTypeCV = vType , NoDataValue = nodv , SpeciationCV = None ,
97
+ VariableDefinition = definition )
98
+ # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=definition )
98
99
self .writer .createVariable (v )
99
100
100
101
@@ -109,9 +110,9 @@ def test_createVariable(self):
109
110
assert (res [6 ] == nodv ) # nodata
110
111
111
112
112
- v = models .Variables (VariableCode = code , VariableName = name , VariableTypeCV = vType , NoDataValue = nodv , Speciation = speciation ,
113
- Definition = definition )
114
- # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None ,definition=None )
113
+ v = models .Variables (VariableCode = code , VariableNameCV = name , VariableTypeCV = vType , NoDataValue = nodv , SpeciationCV = speciation ,
114
+ VariableDefinition = definition )
115
+ # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=speciation ,definition=definition )
115
116
self .writer .createVariable (v )
116
117
117
118
@@ -163,8 +164,8 @@ def test_createDataset(self):
163
164
# dscode=code,
164
165
# dstitle=title,
165
166
# dsabstract=desc)
166
- #TODO uuid
167
- d = models .DataSets (DataSetTypeCV = type , DataSetCode = code , DataSetTitle = title , DataSetAbstract = desc )
167
+
168
+ d = models .DataSets (DataSetTypeCV = type , DataSetCode = code , DataSetTitle = title , DataSetAbstract = desc , DataSetUUID = uuid . uuid4 (). hex )
168
169
dataset = self .writer .createDataset (d )
169
170
170
171
@@ -201,7 +202,7 @@ def test_createResult(self):
201
202
# resulttypecv = 'time series',
202
203
# taxonomicclass=None, resultdatetime=None, resultdatetimeutcoffset=None,
203
204
# validdatetime=None, validdatetimeutcoffset=None, statuscv=None)
204
- #TODO uuid
205
+
205
206
r = models .Results (FeatureActionID = 1 ,
206
207
VariableID = 1 ,
207
208
UnitsID = 1 ,
@@ -214,7 +215,9 @@ def test_createResult(self):
214
215
ResultDateTimeUTCOffset = None ,
215
216
ValidDateTime = None ,
216
217
ValidDateTimeUTCOffset = None ,
217
- StatusCV = None
218
+ StatusCV = None ,
219
+ ResultUUID = uuid .uuid4 ().hex
220
+
218
221
)
219
222
self .writer .createResult (r )
220
223
@@ -235,14 +238,16 @@ def test_createTimeSeriesResult(self):
235
238
# create a basic result record
236
239
# self.writer.createResult(featureactionid = 1,variableid = 1,unitid = 1,processinglevelid = 1,
237
240
# valuecount = 0,sampledmedium = 'unknown',resulttypecv = 'time series')
238
- #TODO uuid
241
+
239
242
r = models .Results (FeatureActionID = 1 ,
240
243
VariableID = 1 ,
241
244
UnitsID = 1 ,
242
245
ProcessingLevelID = 1 ,
243
246
ValueCount = 0 ,
244
247
SampledMediumCV = 'unknown' ,
245
248
ResultTypeCV = 'time series' ,
249
+ ResultUUID = uuid .uuid4 ().hex
250
+
246
251
247
252
)
248
253
self .writer .createResult (r )
@@ -252,9 +257,9 @@ def test_createTimeSeriesResult(self):
252
257
253
258
# create most basic time series result record possible
254
259
# tsr = self.writer.createTimeSeriesResult(result=result, aggregationstatistic='unknown')
255
- t = models .TimeSeriesResults (ResultID = result .ResultID , AggregationStatisticCV = 'unknown' )
256
- tsr = self .writer .createResults (t )
257
- # assert that this basic tsr exists in the datbase
260
+ # t = models.TimeSeriesResults(ResultID = result.ResultID, AggregationStatisticCV = 'unknown')
261
+ # tsr= self.writer.createResult (t)
262
+ # assert that this basic tsr exists in the database
258
263
res = self .engine .execute ('SELECT * FROM TimeSeriesResults' ).first ()
259
264
assert (res is not None )
260
265
@@ -308,15 +313,16 @@ def test_createSimulation(self):
308
313
s = models .Simulations (ActionID = 1 ,
309
314
SimulationName = "MySimulation" ,
310
315
SimulationDescription = "My simulation description" ,
311
- SimulationsStartDateTime = st ,
316
+ SimulationStartDateTime = st ,
312
317
SimulationStartDateTimeUTCOffset = 6 ,
313
- SimulationEdnDateTime = et ,
318
+ SimulationEndDateTime = et ,
314
319
SimulationEndDateTimeUTCOffset = 6 ,
315
320
TimeStepValue = 1 ,
316
- TimeStepuUnitsID = 1 ,
317
- InputDataSetID = None
321
+ TimeStepUnitsID = 1 ,
322
+ InputDataSetID = None ,
323
+ ModelID = 1
318
324
)
319
- sim = self .writer .creatSimulation (s )
325
+ sim = self .writer .createSimulation (s )
320
326
321
327
# assert that this record has been successfully inserted
322
328
res = self .engine .execute ('SELECT * from Simulations' )
0 commit comments