Skip to content

Commit be17206

Browse files
committed
[#4] added unit tests for create timeseries and timeseries results
1 parent 2c51116 commit be17206

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

tests/test_odm2/test_createservice.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import datetime
33
from os.path import *
4+
from odm2api.ODM2 import models
45
from odm2api.ODMconnection import dbconnection
56
from odm2api.ODM2.services.createService import CreateODM2
67
# run this test from the root directory using:
@@ -104,10 +105,50 @@ def test_createFeatureAction(self):
104105
pass
105106

106107
def test_createResult(self):
107-
pass
108+
109+
# assert that there are no results
110+
res = self.engine.execute('SELECT * FROM Results')
111+
assert(len(res.fetchall()) == 0)
112+
113+
# create a result record
114+
self.writer.createResult(featureactionid = 1,
115+
variableid = 1,
116+
unitid = 1,
117+
processinglevelid = 1,
118+
valuecount = 0,
119+
sampledmedium = 'unknown',
120+
resulttypecv = 'time series',
121+
taxonomicclass=None, resultdatetime=None, resultdatetimeutcoffset=None,
122+
validdatetime=None, validdatetimeutcoffset=None, statuscv=None)
123+
124+
125+
# assert that there are results
126+
res = self.engine.execute('SELECT * FROM Results')
127+
assert(len(res.fetchall()) == 1)
108128

109129
def test_createTimeSeriesResult(self):
110-
pass
130+
131+
# assert that there are no time series results in the database
132+
res = self.engine.execute('SELECT * FROM TimeSeriesResults').first()
133+
assert(res is None)
134+
135+
# create a result record if it doesnt exist (required to test foriegn key relationship)
136+
result = self.engine.execute('SELECT * FROM Results').first()
137+
if result is None:
138+
# create a basic result record
139+
self.writer.createResult(featureactionid = 1,variableid = 1,unitid = 1,processinglevelid = 1,
140+
valuecount = 0,sampledmedium = 'unknown',resulttypecv = 'time series')
141+
result = self.engine.execute('SELECT * FROM Results').first()
142+
assert(result is not None)
143+
144+
145+
# create most basic time series result record possible
146+
tsr = self.writer.createTimeSeriesResult(result=result, aggregationstatistic='unknown')
147+
148+
# assert that this basic tsr exists in the datbase
149+
res = self.engine.execute('SELECT * FROM TimeSeriesResults').first()
150+
assert(res is not None)
151+
111152

112153

113154
def test_createTimeSeriesResultValues(self):

0 commit comments

Comments
 (0)