ODM2 / ODM2PythonAPI

A set of Python functions that provides data read/write access to an ODM2 database by leveraging SQLAlchemy.
http://odm2.github.io/ODM2PythonAPI/
BSD 3-Clause "New" or "Revised" License
4 stars 13 forks source link

Fixed getSamplingFeatureDatasets issue #130 #131

Closed Elijahwalkerwest closed 6 years ago

Elijahwalkerwest commented 6 years ago

Additionally added ability to filter by SamplingFeatureTypeCV as per Mauriel's request.

lsetiawan commented 6 years ago

@Elijahwalkerwest Please fix the test also. I won't merge until we have passing Travis CI. Thanks. Let me know if you need my help.

=================================== FAILURES ===================================

_______________ TestReadService.test_getSamplingFeatureDataSets ________________

self = <tests.test_odm2.test_readservice.TestReadService instance at 0x7fd087c41170>

    def test_getSamplingFeatureDataSets(self):

        try:

            #find a sampling feature that is associated with a dataset

            sf = self.engine.execute(

                'SELECT * from SamplingFeatures as sf '

                'inner join FeatureActions as fa on fa.SamplingFeatureID == sf.SamplingFeatureID '

                'inner join Results as r on fa.FeatureActionID == r.FeatureActionID  '

                'inner join DataSetsResults as ds on r.ResultID == ds.ResultID '

            ).fetchone()

            assert len(sf) > 0

            #get the dataset associated with the sampling feature

            ds = self.engine.execute(

                'SELECT * from DataSetsResults as ds '

                'inner join Results as r on r.ResultID == ds.ResultID '

                'inner join FeatureActions as fa on fa.FeatureActionID == r.FeatureActionID '

                'where fa.SamplingFeatureID = ' + str(sf[0])

            ).fetchone()

            assert len(ds) > 0

            print (sf[0])

            # get the dataset associated with the sampling feature using hte api

            dsapi = self.reader.getSamplingFeatureDatasets(ids=[sf[0]])

            assert dsapi is not None

            assert len(dsapi) > 0

            assert dsapi[0].datasets is not None

            assert dsapi[0].SamplingFeatureID == sf[0]

            # assert ds[0] == dsapi[0]

        except Exception as ex:

>           assert False

E           assert False

tests/test_odm2/test_readservice.py:162: AssertionError

----------------------------- Captured stdout call -----------------------------

1

Error running Query: 'NoneType' object is not iterable

=============== 1 failed, 57 passed, 34 skipped in 4.79 seconds ================
lsetiawan commented 6 years ago

@Elijahwalkerwest What is the status of this?

lsetiawan commented 6 years ago

Seems like the failure reported on https://github.com/ODM2/ODM2PythonAPI/pull/131#issuecomment-350378335 wasn't because the test needed to be changed, but the actual getSamplingFeatureDatasets function. It didn't have a way to handle SamplingFeatures with either no dataset or related feature.

lsetiawan commented 6 years ago

I've tested the behavior of these changes. They all look good. Thanks @Elijahwalkerwest. Merging now. This resolves #130.