Skip to content

Commit fabd2d7

Browse files
author
stephanie
committed
update create functions
1 parent edb3e0d commit fabd2d7

File tree

6 files changed

+47
-73
lines changed

6 files changed

+47
-73
lines changed

.cache/v/cache/lastfailed

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,16 @@
11
{
2-
"tests/test_SessionFactory.py::test_aSessionFactory[setup0]": true,
3-
"tests/test_SessionFactory.py::test_aSessionFactory[setup1]": true,
4-
"tests/test_SessionFactory.py::test_aSessionFactory[setup2]": true,
5-
"tests/test_SessionFactory.py::test_aSessionFactory[setup3]": true,
62
"tests/test_SessionFactory.py::test_aSessionFactory[setup4]": true,
73
"tests/test_SessionFactory.py::test_aSessionFactory[setup5]": true,
84
"tests/test_SessionFactory.py::test_aSessionFactory[setup6]": true,
9-
"tests/test_connection.py::test_connection[setup0]": true,
10-
"tests/test_connection.py::test_connection[setup1]": true,
115
"tests/test_connection.py::test_connection[setup2]": true,
126
"tests/test_connection.py::test_connection[setup3]": true,
13-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createAction": true,
14-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createActionBy": true,
15-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createAffiliation": true,
16-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createDataset": true,
17-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createDatasetResults": true,
18-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createDeploymentAction": true,
19-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createFeatureAction": true,
20-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createMethod": true,
21-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createModel": true,
22-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createOrganization": true,
23-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createPerson": true,
24-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createProcessingLevel": true,
25-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createRelatedModel": true,
26-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createSamplingFeature": true,
27-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createSimulation": true,
28-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createSite": true,
29-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createSpatialReference": true,
307
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createTimeSeriesResult": true,
31-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createTimeSeriesResultValues": true,
32-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createUnit": true,
33-
"tests/test_odm2/test_createservice.py::TestCreateService::()::test_createVariable": true,
34-
"tests/test_odm2/test_model.py::test_cvelevationdatum[setup0]": true,
35-
"tests/test_odm2/test_model.py::test_cvelevationdatum[setup1]": true,
368
"tests/test_odm2/test_model.py::test_cvelevationdatum[setup2]": true,
379
"tests/test_odm2/test_model.py::test_cvelevationdatum[setup3]": true,
38-
"tests/test_odm2/test_model.py::test_cvsamplingfeatuergeotype[setup0]": true,
39-
"tests/test_odm2/test_model.py::test_cvsamplingfeatuergeotype[setup1]": true,
4010
"tests/test_odm2/test_model.py::test_cvsamplingfeatuergeotype[setup2]": true,
4111
"tests/test_odm2/test_model.py::test_cvsamplingfeatuergeotype[setup3]": true,
42-
"tests/test_odm2/test_model.py::test_cvsamplingfeaturetype[setup0]": true,
43-
"tests/test_odm2/test_model.py::test_cvsamplingfeaturetype[setup1]": true,
4412
"tests/test_odm2/test_model.py::test_cvsamplingfeaturetype[setup2]": true,
4513
"tests/test_odm2/test_model.py::test_cvsamplingfeaturetype[setup3]": true,
46-
"tests/test_odm2/test_model.py::test_sampling_feature[setup0]": true,
47-
"tests/test_odm2/test_model.py::test_sampling_feature[setup1]": true,
4814
"tests/test_odm2/test_model.py::test_sampling_feature[setup2]": true,
49-
"tests/test_odm2/test_model.py::test_sampling_feature[setup3]": true,
50-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getAllModels": true,
51-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getAllResults": true,
52-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getAllSamplingFeatures": true,
53-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getAllSimulations": true,
54-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getModelByCode": true,
55-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getRelatedModelsByCode": true,
56-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getRelatedModelsByID": true,
57-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getResultsByID": true,
58-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getResultsBySimulationID": true,
59-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getSamplingFeatureByID": true,
60-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getSimulationByActionID": true,
61-
"tests/test_odm2/test_readservice.py::TestReadService::()::test_getSimulationByName": true
15+
"tests/test_odm2/test_model.py::test_sampling_feature[setup3]": true
6216
}

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ environment:
1818
POSTGRES_ENV_POSTGRES_USER: postgres
1919
POSTGRES_ENV_POSTGRES_PASSWORD: Password12!
2020
POSTGRES_ENV_POSTGRES_DB: odm2
21-
POSTGRES_PATH: C:\Program Files\PostgreSQL\9.4
21+
POSTGRES_PATH: C:\Program Files\PostgreSQL\9.5
2222
PGUSER: postgres
2323
PGPASSWORD: Password12!
2424

@@ -27,7 +27,7 @@ environment:
2727
MYSQL_ENV_MYSQL_USER: root
2828
MYSQL_ENV_MYSQL_PASSWORD: Password12!
2929
MYSQL_ENV_MYSQL_DATABASE: odm2
30-
MYSQL_PATH: C:\Program Files\MySql\MySQL Server 5.6
30+
MYSQL_PATH: C:\Program Files\MySql\MySQL Server 5.7
3131
MYSQL_PWD: Password12!
3232

3333
# sql server

odm2api/ODM2/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ class Simulations(Base):
889889
Model = relationship(Models)
890890
Unit = relationship(Units)
891891

892+
def __repr__(self):
893+
return "<Simulations('%s', '%s', '%s', '%s')>" % \
894+
(self.SimulationID, self.ActionID, self.SimulationName, self.SimulationStartDateTime)
895+
892896

893897
# Part of the Provenance table, needed here to meet dependancies
894898
class Citations(Base):
@@ -1650,9 +1654,10 @@ class TimeSeriesResults(Results):
16501654
__mapper_args__ = {'polymorphic_identity':'Time series coverage'}
16511655

16521656
def __repr__(self):
1653-
return "<TimeSeriesResults('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')>" % \
1654-
(self.ResultID, self.XLocation, self.YLocation, self.XLocation,
1655-
self.ResultTypeCV, self.XLocationUnitsObj, self.SpatialReferenceObj,
1657+
return "<TimeSeriesResult('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')>" % \
1658+
( self.FeatureActionID, self.ProcessingLevelID, self.VariableID, self.ProcessinglevelID,
1659+
self.self.XLocation, self.YLocation,
1660+
self.ResultTypeCV,
16561661
self.IntendedTimeSpacing, self.AggregationStatisticCV)
16571662

16581663

odm2api/ODM2/services/createService.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def createProcessingLevel(self, proclevel):
4646

4747
return proclevel
4848

49+
#send in any type of sampling feature
4950
def createSamplingFeature(self, samplingfeature):
5051
self._session.add(samplingfeature)
5152
self._session.commit()
@@ -97,12 +98,18 @@ def createActionby(self, actionby):
9798
self._session.commit()
9899
return actionby
99100

101+
def createFeatureAction(self, action):
102+
self._session.add(action)
103+
self._session.commit()
104+
return action
105+
100106
def createRelatedAction(self, relatedaction):
101107
self._session.add(relatedaction)
102108
self._session.commit()
103109

104110
return relatedaction
105111

112+
#send in any type of result object
106113
def createResult(self, result):
107114
self._session.add(result)
108115
self._session.commit()

odm2api/ODMconnection.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ def __init__(self, debug=False):
5151
@classmethod
5252
def createConnection(self, engine, address, db=None, user=None, password=None, dbtype = 2.0, echo=False):
5353

54-
# if engine == 'sqlite':
55-
# connection_string = engine +':///'+address
56-
# s = SessionFactory(connection_string, echo = echo, version= dbtype)
57-
# setSchema(s.engine)
58-
# return s
59-
#
60-
# else:
61-
connection_string = dbconnection.buildConnDict(dbconnection(), engine, address, db, user, password)
62-
if self.isValidConnection(connection_string, dbtype):
63-
s= SessionFactory(connection_string, echo = echo, version= dbtype)
54+
if engine == 'sqlite':
55+
connection_string = engine +':///'+address
56+
s = SessionFactory(connection_string, echo = echo, version= dbtype)
6457
setSchema(s.engine)
6558
return s
66-
else :
67-
return None
59+
60+
else:
61+
connection_string = dbconnection.buildConnDict(dbconnection(), engine, address, db, user, password)
62+
if self.isValidConnection(connection_string, dbtype):
63+
s= SessionFactory(connection_string, echo = echo, version= dbtype)
64+
setSchema(s.engine)
65+
return s
66+
else :
67+
return None
6868
# if self.testConnection(connection_string):
6969

7070
@classmethod

tests/test_odm2/test_createservice.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ def test_createDataset(self):
171171

172172
d = models.DataSets(DataSetTypeCV = type, DataSetCode =code, DataSetTitle=title, DataSetAbstract = desc, DataSetUUID = uuid.uuid4().hex)
173173
dataset = self.writer.createDataset(d)
174-
174+
assert(dataset == d)
175+
assert (dataset.DataSetID ==1)
175176

176177
# assert that this dataset has been successfully inserted
177178
res = self.engine.execute('SELECT * from DataSets').fetchall()
178179

179180
assert(len(res) == 1)
180-
assert(res[0]==dataset.DataSetID)
181+
assert(res[0][0]==dataset.DataSetID)
181182

182183
def test_createDatasetResults(self):
183184
pass
@@ -246,21 +247,27 @@ def test_createTimeSeriesResult(self):
246247
ValueCount = 0,
247248
SampledMediumCV = 'unknown',
248249
ResultTypeCV = 'time series',
249-
ResultUUID = uuid.uuid4().hex,
250+
ResultUUID = str(uuid.uuid4()),
250251
AggregationStatisticCV = 'unknown'
251252

253+
)
252254

253255

254-
)
255256
newres=self.writer.createResult(r)
257+
258+
# assert that this basic tsr exists in the database
259+
tsr = self.engine.execute('SELECT * FROM TimeSeriesResults').first()
260+
assert(tsr is not None)
261+
262+
assert (newres == r)
256263
result = self.engine.execute('SELECT * FROM Results').first()
257264
assert(result is not None)
265+
266+
assert(newres.ResultID ==1)
258267
assert(result[0] ==newres.ResultID)
259268

260269

261-
# assert that this basic tsr exists in the database
262-
res = self.engine.execute('SELECT * FROM TimeSeriesResults').first()
263-
assert(res is not None)
270+
264271

265272

266273

@@ -322,9 +329,10 @@ def test_createSimulation(self):
322329
ModelID = 1
323330
)
324331
sim = self.writer.createSimulation(s)
325-
332+
assert (s == sim)
333+
assert (s.SimulationID == 1)
326334
# assert that this record has been successfully inserted
327335
res = self.engine.execute('SELECT * from Simulations').fetchall()
328336
assert(len(res) == 1)
329-
assert(res[0]==sim.SimulationID)
337+
assert(res[0][0]==s.SimulationID)
330338

0 commit comments

Comments
 (0)