Skip to content

Fix/merge test improvements#95

Merged
RichardKelly84 merged 53 commits into
feat/harvest-dashboardfrom
fix/merge-test-improvements
Jun 17, 2026
Merged

Fix/merge test improvements#95
RichardKelly84 merged 53 commits into
feat/harvest-dashboardfrom
fix/merge-test-improvements

Conversation

@vmehraOCN

@vmehraOCN vmehraOCN commented Jun 3, 2026

Copy link
Copy Markdown

Overview

This branch builds a comprehensive backend test suite on top of the OBIS integration work merged from feat/harvest-dashboard. It resolves several integration regressions, runtime errors, and broken test paths that surfaced during the branch merge.

Key Changes

➕ New Additions

  • Backend Test Infrastructure (tests/): Added a full pytest suite from scratch including 113 unit tests across 10 modules (covering ERDDAP, CKAN, and compliance tracking), an end-to-end chained integration test with mocked I/O, and standalone dependency wiring.

🛠️ Fixes Implemented

  • UnboundLocalError (erddap_harvester.py): Fixed a critical production risk where dataset_logger was referenced in an HTTP error block before assignment. It is now safely pre-initialized.
  • Prefect Context Failures: Resolved MissingContextError in unit tests by implementing a try/except fallback to standard Python logging.getLogger() when run outside active Prefect flows.
  • Prefect API Connection Failures: Updated database loader tests to invoke the underlying function directly via main.fn(...) and patched loggers to bypass local Prefect API connection attempts.
  • Legacy Imports & Legacy Test Types: Fixed broken imports resulting from the harvest_erddap.py to erddap_harvester.py rename, and corrected a mismatched exception assertion (ResponseTooLargeError) in the ERDDAP client tests.

Testing Checklist

  • Run backend unit and pipeline tests: cd tests && uv run pytest
  • Run backend integration smoke tests: uv run pytest tests/integration/

JessyBarrette and others added 30 commits August 28, 2025 12:53
Major update of the backend  to help strenghten the different aspects of the deployment: 
- Incremental update of the db
- API docs
- API CORS restriction optional
-
Release - fixes to downloader and nerc platform list
… remove gzip_types * since that is dangerous, and avoiding gzipping the frontend until verified
Hotfix: prevent JS bundle truncation on explore.cioos.ca (nginx gzip / sendfile)
…test. Use this as a baseline for further development
… how it went with resulting harvest reports, additionally, adding in documents too
…nd could possible remove, will keep it for now and review on git PR
Resolves conflicts in .env.production, docker-compose.production.yaml,
nginx/nginx.conf, and uv.lock after merging OBIS integration and
harvest-dashboard changes from master.
vmehraOCN added 2 commits June 5, 2026 11:12
Remove web-api/__tests__/, erddapServers.js, obisNodes.js,
scientificNames.js and restore modified web-api files to master
state. All web-api work is now tracked on feat/frontend-tests.
@vmehraOCN

Copy link
Copy Markdown
Author

Okay, I removed all of the web-api changes into a separate branch this one should be able to go through now unless we have some more comments or concerns. @RichardKelly84 @JessyBarrette

@vmehraOCN

Copy link
Copy Markdown
Author

Whoops, I removed some changes in the web-api, fixing....

@vmehraOCN vmehraOCN left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, review done on my side.

@JessyBarrette

JessyBarrette commented Jun 5, 2026

Copy link
Copy Markdown
Member

@vmehraOCN could you update the title and description of the PR to reflect the actual changes suggested.

The changes

  • For diagrams I would suggest using mermaid diagrams which I believe will be simpler to maintain and visualize.
  • test/.. I would move different tests to the component for which it is related. We can still keep a test for the whole workflow. But tests for harvester would ideally remain in the harvester direction. Same for db-loader, scheduler, frontend, web-api.

This will help reducing which tests are run when.

vmehraOCN added 2 commits June 5, 2026 13:59
Each package now owns its tests alongside its code:

  harvester/tests/
    conftest.py            shared ERDDAP fixtures and mock data
    pyproject.toml         depends on harvester + db-loader (for integration)
    unit/                  9 harvester unit tests + csv_generation + obis_geo_filter
    integration/           full pipeline test (harvest → CSV → db-load)

  db-loader/tests/
    conftest.py            standalone DataFrame fixtures
    pyproject.toml         depends on db-loader + harvester (runtime dep)
    unit/                  test_db_loader.py (13 tests)

Results: 141 harvester tests + 13 db-loader tests = 154 total (unchanged).
Remove top-level tests/ directory.
Replace ASCII art uml_diagram.txt with uml_diagram.md containing
two Mermaid diagrams (flowchart + classDiagram) and a component
table. Also updates stale references: harvest_erddap.py →
erddap_harvester.py, adds OBISHarvester, ObisGeoFilter,
HarvestResult, BaseHarvester, and harvest-dashboard service.
@vmehraOCN

Copy link
Copy Markdown
Author

Added in the changes requested @JessyBarrette.

@vmehraOCN

Copy link
Copy Markdown
Author

Note, I left the integration test I made within harvester since its is an integration test for the harvester.
We will need to think up of some more specific tests for cross component interactions.

@JessyBarrette JessyBarrette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db-loader

The added pyproject.toml in db-loader/tests/pyproject.toml needs to me integrated within the main pyproject of db-loader as a dev depedancies.

harvester

We need to migrate the pytest dependancies to dev. We dont need them in production.

Ideally we would also need to run those during the CI/CD. The question is when and how.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if those changes are coming from you or those are in development but not already in feat/harvest-dashboard, but they could be seperated if not already in development. I believe they are though

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is addressed too unless I haven't understood what you mean here.

Comment thread harvester/uml_diagram.txt Outdated
Comment thread db-loader/tests/pyproject.toml Outdated
Comment thread harvester/tests/pyproject.toml Outdated
Comment thread db-loader/tests/pyproject.toml Outdated
JessyBarrette and others added 2 commits June 5, 2026 15:09
- Rename test_downloader.yaml to test-unit-tests.yaml
- Consolidate into single job that detects changed components
- Uses dorny/paths-filter to identify which directories changed
- Installs all dependencies once from root pyproject.toml
- Runs pytest conditionally for each modified component (harvester, db-loader, downloader)
- Adds pytest dev dependencies to root pyproject.toml for shared test tooling

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@JessyBarrette

Copy link
Copy Markdown
Member

I added some of the depandcies to the pyprojects and reviewer the original test_downloader.yaml action to run the different unit tests. Now named test-unit-tests.yaml, it will run the unit tests within each modules if changes are made within them.

vmehraOCN and others added 3 commits June 15, 2026 15:03
…r tests. Updated uv.lock files to reflect the new dependancies. Added untracked files that are relevant to the testing and development process.
… import

Remove unused cde_harvester import from db-loader/__main__.py, add prefect
as an explicit runtime dependency, merge pytest config into db-loader/pyproject.toml,
and delete the now-redundant db-loader/tests/pyproject.toml and uv.lock.
…toml

Add pytest-cov and pytest config (testpaths, addopts) to harvester/pyproject.toml
and delete the now-redundant harvester/tests/pyproject.toml and uv.lock.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was linked to issues Jun 15, 2026
This was unlinked from issues Jun 15, 2026
@JessyBarrette JessyBarrette linked an issue Jun 15, 2026 that may be closed by this pull request
10 tasks
@vmehraOCN

Copy link
Copy Markdown
Author

That sounds pretty good to me!

@vmehraOCN

Copy link
Copy Markdown
Author

@RichardKelly84 @JessyBarrette I think I've addressed all current concerns on this PR. Please let me know if there is anything else to review.

@RichardKelly84 RichardKelly84 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the CSV_generation can probably be removed or updated, some other small comments.

Comment thread harvester/tests/unit/test_csv_generation.py Outdated
Comment thread harvester/tests/unit/test_csv_generation.py Outdated
Comment thread harvester/tests/unit/test_csv_generation.py Outdated
Comment thread harvester/tests/unit/test_csv_generation.py Outdated
Comment thread harvester/tests/unit/test_csv_generation.py Outdated
Comment thread harvester/tests/unit/test_csv_generation.py Outdated
Comment thread harvester/tests/unit/test_csv_generation.py Outdated
Comment thread harvester/tests/unit/test_csv_generation.py Outdated
# Tests: ASCII unescaping
# ---------------------------------------------------------------------------

class TestUnescapeAscii:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GAP: no test here for when there are actual escapes, for example: assert unescape_ascii(r"Caf\u00e9") == "Café"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this now

# ---------------------------------------------------------------------------

class TestGetProfilesHappyPath:
def test_returns_dataframe(self, single_station_dataset):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably remove this one.. If it doesn't return a df, other tests would fail anyways, I.E. test_result_is_not_empty.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for type is likely okay here. Its a bit redundant but it won't take much time and does ensure we are working with the correct datatype.

…via code from Dataset, Profiles, and Skipped datasets.
@RichardKelly84 RichardKelly84 merged commit b34dca1 into feat/harvest-dashboard Jun 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add testing

4 participants