BASIN-3D/basin3d

Separate out test_plugins_usgs.py to mock and integration tests

Closed this issue · 0 comments

Is your feature request related to a problem? Please describe.
The current USGS plugin tests connect with USGS daily values service.

Describe the solution you'd like
We want to split this out so that we have a mock usgs plugin test and and integration test. This will result in the following files and will be accomplished by the following steps

  1. create a new directory tests/integration
  2. Copy tests/test_plugin_usgs.py to tests/integration
  3. Refactor tests/test_plugin_usgs.py to mock the results
  4. Each test file will have the same tests but differ in how they access the data to be transformed

Files

tests/integration/test_plugin_usgs.py - integration tests
tests/test_plugin_usgs.py - mock tests

Resources

  1. Example of mocking:
    See: https://github.com/Watershed-Function-SFA/wfsfa-broker/blob/main/tests/test_synthesis_api.py
    MagicMock and side_effect; monkeypatch
mock_get_url = MagicMock(side_effect=list([get_url_text(get_text("usgs_mtvp_sites.rdb")), get_url(get_json("get_measurement_timeseries_udv.json"))]))    
monkeypatch.setattr(basin3d.plugins.usgs, 'get_url', mock_get_url)
  1. Hit the USGS data sources directly with the URLs generated within the tests. One approach is to configure the PyCharm debugger to run test_plugin_usgs.py. Put break points to stop the code so that you can inspect the URLs being sent to the data source. Then use something like PostMan to hit the datasource directly with those URLs and copy the return into json resource files.