biothings.api icon indicating copy to clipboard operation
biothings.api copied to clipboard

create a data plugin TestCase class

Open newgene opened this issue 4 years ago • 5 comments

Similar to BioThingsTestCase class, but only used for each data plugin to provide certain tests against the latest MongoDB collection after the "upload" step.

newgene avatar Nov 03 '20 23:11 newgene

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.

kevinxin90 avatar Nov 12 '20 23:11 kevinxin90

Per our discussion, the tests for a data plugin can work this way:

  1. 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.

Screenshot 2020-11-12 153100

We should also allow tests to be triggered automatically by a success upload, or manually triggered.

newgene avatar Nov 12 '20 23:11 newgene

For Amitesh:

  1. May need to check our current MongoDB client code for convenient access
  2. May need JSONpath or JSON pointer to fetch fields/subfields for validation

erikyao avatar May 19 '21 22:05 erikyao

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.

namespacestd0 avatar Jul 14 '21 23:07 namespacestd0

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

newgene avatar Jul 29 '21 22:07 newgene