Skip to content

Commit 3bd605d

Browse files
committed
added a test case for createVariable
1 parent be17206 commit 3bd605d

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

tests/test_odm2/test_createservice.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,80 @@ def build_db(self):
4040

4141
globals['write'] = self.write
4242
globals['engine'] = self.engine
43+
globals['db'] = db
4344
# return self.write, self.engine
4445

4546
def setup(self):
4647

4748
self.writer = globals['write']
4849
self.engine = globals['engine']
50+
self.db = globals['db']
4951

5052
def test_createVariable(self):
51-
pass
53+
54+
# assert that there are no variables in the database
55+
res = self.engine.execute('SELECT * from Variables')
56+
assert(len(res.fetchall()) == 0)
57+
58+
59+
# create a new variable
60+
code = 'MyVar'
61+
name = 'My Test Variable'
62+
vType = 'Hydrology'
63+
nodv = -9999
64+
speciation="mg/L as PO4"
65+
definition="This is a test variable"
66+
self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=None)
67+
68+
# assert that this dataset has been successfully inserted
69+
res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first()
70+
assert(res is not None)
71+
assert(res[1] == vType ) # vType
72+
assert(res[2] == code ) # code
73+
assert(res[3] == name ) # name
74+
assert(res[4] == None) # definition
75+
assert(res[5] == None) # speciation
76+
assert(res[6] == nodv ) # nodata
77+
78+
self.writer.createVariable(code = code, name = name, vType = vType, nodv =nodv, speciation=speciation,definition=None)
79+
80+
# assert that this dataset has been successfully inserted
81+
res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first()
82+
assert(res is not None)
83+
assert(res[1] == vType ) # vType
84+
assert(res[2] == code ) # code
85+
assert(res[3] == name ) # name
86+
assert(res[4] == None) # definition
87+
assert(res[5] == speciation) # speciation
88+
assert(res[6] == nodv ) # nodata
89+
90+
91+
self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=definition)
92+
93+
# assert that this dataset has been successfully inserted
94+
res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first()
95+
assert(res is not None)
96+
assert(res[1] == vType ) # vType
97+
assert(res[2] == code ) # code
98+
assert(res[3] == name ) # name
99+
assert(res[4] == definition) # definition
100+
assert(res[5] == None) # speciation
101+
assert(res[6] == nodv ) # nodata
102+
103+
104+
self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=speciation,definition=definition)
105+
106+
# assert that this dataset has been successfully inserted
107+
res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first()
108+
assert(res is not None)
109+
assert(res[1] == vType ) # vType
110+
assert(res[2] == code ) # code
111+
assert(res[3] == name ) # name
112+
assert(res[4] == definition) # definition
113+
assert(res[5] == speciation) # speciation
114+
assert(res[6] == nodv ) # nodata
115+
116+
52117

53118
def test_createMethod(self):
54119
pass

0 commit comments

Comments
 (0)