biothings.api
biothings.api copied to clipboard
create a data plugin TestCase class
Similar to BioThingsTestCase
class, but only used for each data plugin to provide certain tests against the latest MongoDB collection after the "upload" step.
One thing i forgot to mention in the meeting is I think it's a good idea to test/validate the total number of docs in a mongodb collection.
Per our discussion, the tests for a data plugin can work this way:
- add a "tests.py" file under the data plugin folder. Here are some psudeocode:
class TestDBNSFP(BiothingsDataPluginTestCase):
src_collection = 'dbnsfp_collection'
def test_check_fields(self):
# for a _id, a list fields should exist
def test_check_field_1(self)
# test a _id, a field should exist and have an expected value
def test_check_field_2(self):
# same as above for another field
def test_check_field_should_not_exist(self):
# test a _id, a field should not exist
def test_some_query(self):
# test some queries, might require indexing on certain fields
def test_total_count(self)
BiothingsDataPluginTestCase
should be able to test against a mongodb collection, or a list/generator out of an uploader class.
And we should implement a BiothingsDataPluginTester
class to trigger these tests. A "Tests" tab can be added to the Data source page to trigger tests and show the tests results.
We should also allow tests to be triggered automatically by a success upload
, or manually triggered.
For Amitesh:
- May need to check our current MongoDB client code for convenient access
- May need
JSONpath
orJSON pointer
to fetch fields/subfields for validation
The next step for this issue is to create a feature that is registered in the hub to run the tests and report the result.
User TestCase can be written like this:
class TestDBNSFP(BiothingsDataPluginTestCase):
# these should enable some basic/common tests based on user provided data below
ids_should_exist = []
fields_should_match = [
(_id, field, value),
...
]
# add any other customized test below if any
def other_test_001(self):
pass