@@ -76,7 +76,7 @@ def setup(self):
7676 self .db = globals_vars ['db' ]
7777
7878
79- # Sampling Features
79+ # Sampling Features
8080 def test_getAllSamplingFeatures (self ):
8181 # get all models from the database
8282 res = self .engine .execute ('SELECT * FROM SamplingFeatures' ).fetchall ()
@@ -91,6 +91,14 @@ def test_getSamplingFeatureByID(self):
9191 # get all simulations using the api
9292 resapi = self .reader .getSamplingFeatures (ids = [sfid ])
9393 assert resapi is not None
94+
95+ def test_getSamplingFeatureByCode (self ):
96+ # get all models from the database
97+ res = self .engine .execute ('SELECT * FROM SamplingFeatures' ).fetchone ()
98+ code = res [2 ]
99+ # get all simulations using the api
100+ resapi = self .reader .getSamplingFeatures (codes = [code ])
101+ assert resapi is not None
94102
95103#DataSets
96104 def test_getDataSets (self ):
@@ -121,8 +129,6 @@ def test_getDataSetsValues(self):
121129 assert len (values ) > 0
122130
123131
124-
125- #ToDo figure out how to actually test this function
126132 def test_getSamplingFeatureDataSets (self ):
127133
128134 #find a sampling feature that is associated with a dataset
@@ -151,18 +157,48 @@ def test_getSamplingFeatureDataSets(self):
151157 assert len (dsapi ) > 0
152158 assert ds [1 ] == dsapi [0 ].DataSetID
153159
160+ # Results
161+ def test_getAllResults (self ):
162+ # get all results from the database
163+ res = self .engine .execute ('SELECT * FROM Results' ).fetchall ()
164+ print (res )
165+ # get all results using the api
166+ resapi = self .reader .getResults ()
167+ assert len (res ) == len (resapi )
154168
155- # Models
156- """
157- TABLE Models
158- ModelID INTEGER NOT NULL PRIMARY KEY,
159- ModelCode VARCHAR (50) NOT NULL,
160- ModelName VARCHAR (255) NOT NULL,
161- ModelDescription VARCHAR (500) NULL,
162- Version VARCHAR (255) NULL,
163- ModelLink VARCHAR (255) NULL
164- """
169+ def test_getResultsByID (self ):
170+ # get a result from the database
171+ res = self .engine .execute ('SELECT * FROM Results' ).fetchone ()
172+ resultid = res [1 ]
173+
174+ # get the result using the api
175+ resapi = self .reader .getResults (ids = [resultid ])
176+ assert resapi is not None
165177
178+ def test_getResultsBySFID (self ):
179+ sf = self .engine .execute (
180+ 'SELECT * from SamplingFeatures as sf '
181+ 'inner join FeatureActions as fa on fa.SamplingFeatureID == sf.SamplingFeatureID '
182+ 'inner join Results as r on fa.FeatureActionID == r.FeatureActionID '
183+ ).fetchone ()
184+ assert len (sf ) > 0
185+ sfid = sf [0 ]
186+
187+ res = self .engine .execute (
188+ 'SELECT * from Results as r '
189+ 'inner join FeatureActions as fa on fa.FeatureActionID == r.FeatureActionID '
190+ 'where fa.SamplingFeatureID = ' + str (sfid )
191+ ).fetchone ()
192+
193+ assert len (res ) > 0
194+
195+ # get the result using the api
196+ resapi = self .reader .getResults (sfids = [sfid ])
197+ assert resapi is not None
198+ assert len (resapi ) > 0
199+ assert resapi [0 ].ResultID == res [0 ]
200+
201+ # Models
166202 def test_getAllModels (self ):
167203 # get all models from the database
168204 res = self .engine .execute ('SELECT * FROM Models' ).fetchall ()
@@ -179,19 +215,7 @@ def test_getModelByCode(self):
179215 assert resapi is not None
180216
181217
182- # RelatedModels
183- """
184- TABLE RelatedModels (
185- RelatedID INTEGER NOT NULL PRIMARY KEY,
186- ModelID INTEGER NOT NULL,
187- RelationshipTypeCV VARCHAR (255) NOT NULL,
188- RelatedModelID INTEGER NOT NULL,
189- FOREIGN KEY (RelationshipTypeCV) REFERENCES CV_RelationshipType (Name)
190- ON UPDATE NO ACTION ON DELETE NO ACTION,
191- FOREIGN KEY (ModelID) REFERENCES Models (ModelID)
192- ON UPDATE NO ACTION ON DELETE NO ACTION
193- """
194-
218+ # RelatedModels
195219 def test_getRelatedModelsByID (self ):
196220 # get related models by id using the api
197221 resapi = self .reader .getRelatedModels (id = 1 )
@@ -214,61 +238,7 @@ def test_getRelatedModelsByCode(self):
214238 # test invalid argument
215239 resapi = self .reader .getRelatedModels (code = 234123 )
216240 assert not resapi
217-
218-
219- # Results
220- """
221- TABLE Results (
222- ResultID INTEGER NOT NULL PRIMARY KEY,
223- ResultUUID VARCHAR(36) NOT NULL,
224- FeatureActionID INTEGER NOT NULL,
225- ResultTypeCV VARCHAR (255) NOT NULL,
226- VariableID INTEGER NOT NULL,
227- UnitsID INTEGER NOT NULL,
228- TaxonomicClassifierID INTEGER NULL,
229- ProcessingLevelID INTEGER NOT NULL,
230- ResultDateTime DATETIME NULL,
231- ResultDateTimeUTCOffset INTEGER NULL,
232- ValidDateTime DATETIME NULL,
233- ValidDateTimeUTCOffset INTEGER NULL,
234- StatusCV VARCHAR (255) NULL,
235- SampledMediumCV VARCHAR (255) NOT NULL,
236- ValueCount INTEGER NOT NULL
237- """
238- def test_getAllResults (self ):
239- # get all results from the database
240- res = self .engine .execute ('SELECT * FROM Results' ).fetchall ()
241- # print(res)
242- # get all results using the api
243- resapi = self .reader .getResults ()
244- assert len (res ) == len (resapi )
245-
246- def test_getResultsByID (self ):
247- # get a result from the database
248- res = self .engine .execute ('SELECT * FROM Results' ).fetchone ()
249- resultid = res [1 ]
250-
251- # get the result using the api
252- resapi = self .reader .getResults (ids = [resultid ])
253- assert resapi is not None
254-
255241# Simulations
256- """
257- TABLE Simulations (
258- SimulationID INTEGER NOT NULL PRIMARY KEY,
259- ActionID INTEGER NOT NULL,
260- SimulationName VARCHAR (255) NOT NULL,
261- SimulationDescription VARCHAR (500) NULL,
262- SimulationStartDateTime DATETIME NOT NULL,
263- SimulationStartDateTimeUTCOffset INTEGER NOT NULL,
264- SimulationEndDateTime DATETIME NOT NULL,
265- SimulationEndDateTimeUTCOffset INTEGER NOT NULL,
266- TimeStepValue FLOAT NOT NULL,
267- TimeStepUnitsID INTEGER NOT NULL,
268- InputDataSetID INTEGER NULL,
269- ModelID INTEGER NOT NULL,
270- """
271-
272242 def test_getAllSimulations (self ):
273243 # get all simulation from the database
274244 res = self .engine .execute ('SELECT * FROM Simulations' ).fetchall ()
0 commit comments