Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mock tests for fetch_data and format_forecast #32

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

siddharth7113
Copy link
Contributor

Pull Request

Description

This pull request introduces mock testing for fetch_data and format_forecast functions to enhance test reliability and isolate external dependencies.

fetch_data and fetch_data_using_sql:

  • Mock tests validate successful API and SQL query handling.
  • Added failure scenarios to ensure robust error handling.

format_to_forecast_sql:

  • Mocked data replaces real API calls while maintaining PostgreSQL container functionality.
  • Ensures compatibility with controlled input for seamless database interactions.

Fixes #27

How Has This Been Tested?

The following tests have been conducted:

  • Mock Testing:
    • Successful mock API/SQL responses were verified for correct DataFrame handling.
    • Failure scenarios ensure empty DataFrames and proper exception handling.
  • Integration Testing:
    • PostgreSQL container setup validated through real database interactions.
    • Real database checks preserved for comprehensive coverage.

Steps to reproduce:

  1. Run pytest tests/test_fetch_data.py -s.
  2. Run pytest tests/test_format_forecast.py -s.

Checklist

- Added mock testing for `fetch_data` and `fetch_data_using_sql` in `test_fetch_data.py`:
  - Validates API and SQL query functions with mocked responses.
  - Includes scenarios for successful data fetch and failure handling.

- refactor(tests): updated `test_format_forecast.py` to use mocked API data:
  - Isolated PostgreSQL container validation while maintaining real database checks.
  - Ensured compatibility with controlled mock data for `format_to_forecast_sql`.

- chore(dependencies): updated `pyproject.toml` to include dependencies for mocking and testing enhancements.
@peterdudfield
Copy link
Contributor

This good to go @siddharth7113 ?

@siddharth7113
Copy link
Contributor Author

This good to go @siddharth7113 ?

Yep, I tested it a while ago , should work well!

@peterdudfield peterdudfield merged commit 7203ed1 into openclimatefix:main Jan 27, 2025
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.

Refactor Tests to Use Mocked API Data
2 participants