44from odm2api .ODM2 import models
55from odm2api .ODMconnection import dbconnection
66from odm2api .ODM2 .services .createService import CreateODM2
7+ import uuid
78# run this test from the root directory using:
89# python -m pytest tests/test_odm2/test_createservice.py
910
@@ -63,8 +64,8 @@ def test_createVariable(self):
6364 nodv = - 9999
6465 speciation = "mg/L as PO4"
6566 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 )
6869 # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=None)
6970 self .writer .createVariable (v )
7071 # assert that this dataset has been successfully inserted
@@ -77,9 +78,9 @@ def test_createVariable(self):
7778 assert (res [5 ] == None ) # speciation
7879 assert (res [6 ] == nodv ) # nodata
7980
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)
8384 self .writer .createVariable (v )
8485
8586 # assert that this dataset has been successfully inserted
@@ -92,9 +93,9 @@ def test_createVariable(self):
9293 assert (res [5 ] == speciation ) # speciation
9394 assert (res [6 ] == nodv ) # nodata
9495
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 )
9899 self .writer .createVariable (v )
99100
100101
@@ -109,9 +110,9 @@ def test_createVariable(self):
109110 assert (res [6 ] == nodv ) # nodata
110111
111112
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 )
115116 self .writer .createVariable (v )
116117
117118
@@ -163,8 +164,8 @@ def test_createDataset(self):
163164 # dscode=code,
164165 # dstitle=title,
165166 # 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 )
168169 dataset = self .writer .createDataset (d )
169170
170171
@@ -201,7 +202,7 @@ def test_createResult(self):
201202 # resulttypecv = 'time series',
202203 # taxonomicclass=None, resultdatetime=None, resultdatetimeutcoffset=None,
203204 # validdatetime=None, validdatetimeutcoffset=None, statuscv=None)
204- #TODO uuid
205+
205206 r = models .Results (FeatureActionID = 1 ,
206207 VariableID = 1 ,
207208 UnitsID = 1 ,
@@ -214,7 +215,9 @@ def test_createResult(self):
214215 ResultDateTimeUTCOffset = None ,
215216 ValidDateTime = None ,
216217 ValidDateTimeUTCOffset = None ,
217- StatusCV = None
218+ StatusCV = None ,
219+ ResultUUID = uuid .uuid4 ().hex
220+
218221 )
219222 self .writer .createResult (r )
220223
@@ -235,14 +238,16 @@ def test_createTimeSeriesResult(self):
235238 # create a basic result record
236239 # self.writer.createResult(featureactionid = 1,variableid = 1,unitid = 1,processinglevelid = 1,
237240 # valuecount = 0,sampledmedium = 'unknown',resulttypecv = 'time series')
238- #TODO uuid
241+
239242 r = models .Results (FeatureActionID = 1 ,
240243 VariableID = 1 ,
241244 UnitsID = 1 ,
242245 ProcessingLevelID = 1 ,
243246 ValueCount = 0 ,
244247 SampledMediumCV = 'unknown' ,
245248 ResultTypeCV = 'time series' ,
249+ ResultUUID = uuid .uuid4 ().hex
250+
246251
247252 )
248253 self .writer .createResult (r )
@@ -252,9 +257,9 @@ def test_createTimeSeriesResult(self):
252257
253258 # create most basic time series result record possible
254259 # 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
258263 res = self .engine .execute ('SELECT * FROM TimeSeriesResults' ).first ()
259264 assert (res is not None )
260265
@@ -308,15 +313,16 @@ def test_createSimulation(self):
308313 s = models .Simulations (ActionID = 1 ,
309314 SimulationName = "MySimulation" ,
310315 SimulationDescription = "My simulation description" ,
311- SimulationsStartDateTime = st ,
316+ SimulationStartDateTime = st ,
312317 SimulationStartDateTimeUTCOffset = 6 ,
313- SimulationEdnDateTime = et ,
318+ SimulationEndDateTime = et ,
314319 SimulationEndDateTimeUTCOffset = 6 ,
315320 TimeStepValue = 1 ,
316- TimeStepuUnitsID = 1 ,
317- InputDataSetID = None
321+ TimeStepUnitsID = 1 ,
322+ InputDataSetID = None ,
323+ ModelID = 1
318324 )
319- sim = self .writer .creatSimulation (s )
325+ sim = self .writer .createSimulation (s )
320326
321327 # assert that this record has been successfully inserted
322328 res = self .engine .execute ('SELECT * from Simulations' )
0 commit comments