Skip to content

Commit ba5f9e9

Browse files
committed
Merge branch 'fixrelated'
2 parents 4acec1f + 2321ab4 commit ba5f9e9

File tree

9 files changed

+405
-28
lines changed

9 files changed

+405
-28
lines changed

odm2api/ODM2/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ class RelatedModels(Base):
10241024
__tablename__ = 'relatedmodels'
10251025
__table_args__ = {u'schema': 'odm2'} # __table_args__ = {u'schema': Schema.getSchema()}
10261026

1027-
RelationID = Column('relationid', Integer, primary_key=True, nullable=False)
1027+
RelatedID = Column('relatedid', Integer, primary_key=True, nullable=False)
10281028
ModelID = Column('modelid', ForeignKey(Models.ModelID), nullable=False)
10291029
RelationshipTypeCV = Column('relationshiptypecv', ForeignKey(CVRelationshipType.Name), nullable=False,
10301030
index=True)

odm2api/ODM2/models_sqlite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ class RelatedModels(Base):
10161016
__tablename__ = 'relatedmodels'
10171017
# __table_args__ = {u'schema': 'odm2'} # # __table_args__ = {u'schema': Schema.getSchema()}
10181018

1019-
RelationID = Column('relationid', Integer, primary_key=True, nullable=False)
1019+
RelatedID = Column('relatedid', Integer, primary_key=True, nullable=False)
10201020
ModelID = Column('modelid', ForeignKey(Models.ModelID), nullable=False)
10211021
RelationshipTypeCV = Column('relationshiptypecv', ForeignKey(CVRelationshipType.Name), nullable=False,
10221022
index=True)

odm2api/ODM2/services/readService.py

-2
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@ def getRelatedModelsByID(self, modelid):
944944
:return: all models related to the specified id
945945
"""
946946
try:
947-
return self._session.query(RelatedModels).filter_by(RelatedModelID=modelid).all()
948947
except Exception as e:
949948
print(e)
950949
return None
@@ -956,7 +955,6 @@ def getRelatedModelsByCode(self, modelcode):
956955
:return: all models related to the provided model code
957956
"""
958957
try:
959-
return self._session.query(RelatedModels).join(Models, RelatedModels.RelatedModelID == Models.ModelID) \
960958
.filter(Models.ModelCode == modelcode).all()
961959
except Exception as e:
962960
print(e)

odm2api/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def __init__(self, session_factory, debug=False):
5454
#self._session_factory=""
5555
# def getSessionFactory( session = None):
5656
def getSession(self):
57+
if self._session is None:
58+
self._session = self._session_factory.getSession()
59+
5760
return self._session
5861

5962

tests/test_connection.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
["sqlite_wof","sqlite", "./tests/spatialite/wof2odm/ODM2.sqlite", None, None, None]
2121
]
2222
dbs_test = [
23-
["sqlite", "./tests/spatialite/odm2_test.sqlite", None, None, None]
2423

24+
# ["sqlite_local","sqlite", "./tests/spatialite/odm2_test.sqlite", None, None, None],
25+
["sqlite_memory", "sqlite", ":memory:", None, None, None]
2526
]
2627
class Connection:
2728
def __init__(self, request):

tests/test_odm2/data/populated.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -15947,7 +15947,7 @@ CREATE TABLE Models (
1594715947
INSERT INTO "Models" VALUES(1,'swat','soil and water assessment tool','The Soil and Water Assessment Tool (SWAT) is a public domain Model jointly developed by USDA Agricultural Research Service (USDA-ARS) and Texas A&M AgriLife Research, part of The Texas A&M University System. SWAT is a small watershed to river basin-scale Model to simulate the quality and quantity of surface and ground water and predict the environmental impact of land use, land management practices, and climate change.',NULL,NULL);
1594815948
INSERT INTO "Models" VALUES(2,'swmm','storm water management model','SWMM is a dynamic hydrology-hydraulic water quality simulation model. It is used for single event or long-term (continuous) simulation of runoff quantity and quality from primarily urban areas. The runoff component operates on a collection of sub catchment areas that receive precipitation and generate runoff and pollutant loads. The routing portion transports this runoff through a system of pipes, channels, storage/treatment devices, pumps, and regulators.','5.1.010','http://www.epa.gov/water-research/storm-water-management-model-swmm');
1594915949
CREATE TABLE RelatedModels (
15950-
RelationID INTEGER NOT NULL PRIMARY KEY,
15950+
RelatedID INTEGER NOT NULL PRIMARY KEY,
1595115951
ModelID INTEGER NOT NULL,
1595215952
RelationshipTypeCV VARCHAR (255) NOT NULL,
1595315953
RelatedModelID INTEGER NOT NULL,

tests/test_odm2/test_createservice.py

+27-19
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,32 @@ def test_createVariable(self):
113113
assert(res[5] == speciation) # speciation
114114
assert(res[6] == nodv ) # nodata
115115

116-
117-
116+
@pytest.mark.skipif(True, reason="implement")
118117
def test_createMethod(self):
119118
pass
120119

120+
@pytest.mark.skipif(True, reason="implement")
121121
def test_createProcessingLevel(self):
122-
pass
122+
pass
123123

124+
@pytest.mark.skipif(True, reason="implement")
124125
def test_createSamplingFeature(self):
125126
pass
126127

128+
@pytest.mark.skipif(True, reason="implement")
127129
def test_createUnit(self):
128130
pass
129-
131+
132+
@pytest.mark.skipif(True, reason="implement")
130133
def test_createOrganization(self):
131-
pass
134+
pass
132135

136+
@pytest.mark.skipif(True, reason="implement")
133137
def test_createPerson(self):
134138
pass
135139

136-
def test_createAffiliation(self):
140+
@pytest.mark.skipif(True, reason="implement")
141+
def test_createAffiliation(self):
137142
pass
138143

139144
def test_createDataset(self):
@@ -156,16 +161,19 @@ def test_createDataset(self):
156161
res = self.engine.execute('SELECT * from DataSets')
157162
assert(len(res.fetchall()) == 1)
158163

159-
164+
@pytest.mark.skipif(True, reason="implement")
160165
def test_createDatasetResults(self):
161166
pass
162-
167+
168+
@pytest.mark.skipif(True, reason="implement")
163169
def test_createAction(self):
164170
pass
165171

166-
def test_createActionBy(self):
172+
@pytest.mark.skipif(True, reason="implement")
173+
def test_createActionBy(self):
167174
pass
168-
175+
176+
@pytest.mark.skipif(True, reason="implement")
169177
def test_createFeatureAction(self):
170178
pass
171179

@@ -213,28 +221,28 @@ def test_createTimeSeriesResult(self):
213221
# assert that this basic tsr exists in the datbase
214222
res = self.engine.execute('SELECT * FROM TimeSeriesResults').first()
215223
assert(res is not None)
216-
217-
218224

225+
@pytest.mark.skipif(True, reason="implement")
219226
def test_createTimeSeriesResultValues(self):
220227
pass
221228

222-
223-
def test_createSite(self):
229+
@pytest.mark.skipif(True, reason="implement")
230+
def test_createSite(self):
224231
pass
225232

226-
227-
def test_createSpatialReference(self):
233+
@pytest.mark.skipif(True, reason="implement")
234+
def test_createSpatialReference(self):
228235
pass
229236

230-
def test_createDeploymentAction(self):
237+
@pytest.mark.skipif(True, reason="implement")
238+
def test_createDeploymentAction(self):
231239
pass
232240

233-
241+
@pytest.mark.skipif(True, reason="implement")
234242
def test_createModel(self):
235243
pass
236244

237-
245+
@pytest.mark.skipif(True, reason="implement")
238246
def test_createRelatedModel(self):
239247
pass
240248

0 commit comments

Comments
 (0)