Skip to content

Commit 69656fa

Browse files
author
sreeder
committed
test sfresult function
1 parent 00834dd commit 69656fa

File tree

1 file changed

+53
-77
lines changed

1 file changed

+53
-77
lines changed

tests/test_odm2/test_readservice.py

Lines changed: 53 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
@@ -92,17 +92,57 @@ def test_getSamplingFeatureByID(self):
9292
resapi = self.reader.getSamplingFeatures(ids=[sfid])
9393
assert resapi is not None
9494

95-
# Models
96-
"""
97-
TABLE Models
98-
ModelID INTEGER NOT NULL PRIMARY KEY,
99-
ModelCode VARCHAR (50) NOT NULL,
100-
ModelName VARCHAR (255) NOT NULL,
101-
ModelDescription VARCHAR (500) NULL,
102-
Version VARCHAR (255) NULL,
103-
ModelLink VARCHAR (255) NULL
104-
"""
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
102+
103+
# Results
104+
def test_getAllResults(self):
105+
# get all results from the database
106+
res = self.engine.execute('SELECT * FROM Results').fetchall()
107+
print(res)
108+
# get all results using the api
109+
resapi = self.reader.getResults()
110+
assert len(res) == len(resapi)
111+
112+
def test_getResultsByID(self):
113+
# get a result from the database
114+
res = self.engine.execute('SELECT * FROM Results').fetchone()
115+
resultid = res[1]
116+
117+
# get the result using the api
118+
resapi = self.reader.getResults(ids=[resultid])
119+
assert resapi is not None
120+
121+
def test_getResultsBySFID(self):
122+
sf = self.engine.execute(
123+
'SELECT * from SamplingFeatures as sf '
124+
'inner join FeatureActions as fa on fa.SamplingFeatureID == sf.SamplingFeatureID '
125+
'inner join Results as r on fa.FeatureActionID == r.FeatureActionID '
126+
).fetchone()
127+
assert len(sf) > 0
128+
sfid = sf[0]
129+
130+
res = self.engine.execute(
131+
'SELECT * from Results as r '
132+
'inner join FeatureActions as fa on fa.FeatureActionID == r.FeatureActionID '
133+
'where fa.SamplingFeatureID = ' + str(sfid)
134+
).fetchone()
135+
136+
assert len(res) > 0
137+
138+
# get the result using the api
139+
resapi = self.reader.getResults(sfids=[sfid])
140+
141+
assert resapi is not None
142+
assert len(resapi) > 0
143+
assert resapi[0].ResultID == res[0]
105144

145+
# Models
106146
def test_getAllModels(self):
107147
# get all models from the database
108148
res = self.engine.execute('SELECT * FROM Models').fetchall()
@@ -119,19 +159,7 @@ def test_getModelByCode(self):
119159
assert resapi is not None
120160

121161

122-
# RelatedModels
123-
"""
124-
TABLE RelatedModels (
125-
RelatedID INTEGER NOT NULL PRIMARY KEY,
126-
ModelID INTEGER NOT NULL,
127-
RelationshipTypeCV VARCHAR (255) NOT NULL,
128-
RelatedModelID INTEGER NOT NULL,
129-
FOREIGN KEY (RelationshipTypeCV) REFERENCES CV_RelationshipType (Name)
130-
ON UPDATE NO ACTION ON DELETE NO ACTION,
131-
FOREIGN KEY (ModelID) REFERENCES Models (ModelID)
132-
ON UPDATE NO ACTION ON DELETE NO ACTION
133-
"""
134-
162+
# RelatedModels
135163
def test_getRelatedModelsByID(self):
136164
# get related models by id using the api
137165
resapi = self.reader.getRelatedModels(id=1)
@@ -156,59 +184,7 @@ def test_getRelatedModelsByCode(self):
156184
assert not resapi
157185

158186

159-
# Results
160-
"""
161-
TABLE Results (
162-
ResultID INTEGER NOT NULL PRIMARY KEY,
163-
ResultUUID VARCHAR(36) NOT NULL,
164-
FeatureActionID INTEGER NOT NULL,
165-
ResultTypeCV VARCHAR (255) NOT NULL,
166-
VariableID INTEGER NOT NULL,
167-
UnitsID INTEGER NOT NULL,
168-
TaxonomicClassifierID INTEGER NULL,
169-
ProcessingLevelID INTEGER NOT NULL,
170-
ResultDateTime DATETIME NULL,
171-
ResultDateTimeUTCOffset INTEGER NULL,
172-
ValidDateTime DATETIME NULL,
173-
ValidDateTimeUTCOffset INTEGER NULL,
174-
StatusCV VARCHAR (255) NULL,
175-
SampledMediumCV VARCHAR (255) NOT NULL,
176-
ValueCount INTEGER NOT NULL
177-
"""
178-
def test_getAllResults(self):
179-
# get all results from the database
180-
res = self.engine.execute('SELECT * FROM Results').fetchall()
181-
print(res)
182-
# get all results using the api
183-
resapi = self.reader.getResults()
184-
assert len(res) == len(resapi)
185-
186-
def test_getResultsByID(self):
187-
# get a result from the database
188-
res = self.engine.execute('SELECT * FROM Results').fetchone()
189-
resultid = res[1]
190-
191-
# get the result using the api
192-
resapi = self.reader.getResults(ids=[resultid])
193-
assert resapi is not None
194-
195-
# Simulations
196-
"""
197-
TABLE Simulations (
198-
SimulationID INTEGER NOT NULL PRIMARY KEY,
199-
ActionID INTEGER NOT NULL,
200-
SimulationName VARCHAR (255) NOT NULL,
201-
SimulationDescription VARCHAR (500) NULL,
202-
SimulationStartDateTime DATETIME NOT NULL,
203-
SimulationStartDateTimeUTCOffset INTEGER NOT NULL,
204-
SimulationEndDateTime DATETIME NOT NULL,
205-
SimulationEndDateTimeUTCOffset INTEGER NOT NULL,
206-
TimeStepValue FLOAT NOT NULL,
207-
TimeStepUnitsID INTEGER NOT NULL,
208-
InputDataSetID INTEGER NULL,
209-
ModelID INTEGER NOT NULL,
210-
"""
211-
187+
# Simulations
212188
def test_getAllSimulations(self):
213189
# get all simulation from the database
214190
res = self.engine.execute('SELECT * FROM Simulations').fetchall()

0 commit comments

Comments
 (0)