Skip to content

Commit

Permalink
More unit tests - cover more use cases (#1761)
Browse files Browse the repository at this point in the history
More unit tests to cover more use cases
  • Loading branch information
Sybrand authored Mar 4, 2022
1 parent 2e841f8 commit 6ec13ac
Show file tree
Hide file tree
Showing 9 changed files with 1,420 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/app/tests/fixtures/wf1/lookup.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
"{'size': '1000', 'page': 0, 'startingTimestamp': 1590091200000, 'endingTimestamp': 1590523200000, 'stationIds': ['bfe0a6e2-e27e-0210-e053-259e228e58c7']}": {
"None": "wfwx/v1/dailies/search__startingTimestamp_1590091200000_endingTimestamp_1590523200000_station_230_page_0_size_1000.json"
},
"{'size': '1000', 'page': 0, 'startingTimestamp': 1589486400000, 'endingTimestamp': 1589659200000, 'stationIds': ['bfe0a6e2-e27e-0210-e053-259e228e58c7', 'bfe0a6e2-e286-0210-e053-259e228e58c7']}": {
"None": "wfwx/v1/dailies/search__startingTimestamp_1589486400000_endingTimestamp_1589659200000_station_230_239_page_0_size_1000.json"
},
"{'size': '1000', 'page': 0, 'startingTimestamp': 1590091200000, 'endingTimestamp': 1590264000000, 'stationIds': ['bfe0a6e2-e27e-0210-e053-259e228e58c7', 'bfe0a6e2-e286-0210-e053-259e228e58c7']}": {
"None": "wfwx/v1/dailies/search__startingTimestamp_1590091200000_endingTimestamp_1590264000000_station_230_239_page_0_size_1000.json"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
{
"_embedded": {
"dailies": [
{
"id": "dae7f61d-fa45-4f3f-b88e-25d8bb996fc0",
"createdBy": "SYBRAND",
"lastEntityUpdateTimestamp": 1590192000000,
"updateDate": "2020-05-22T17:00:00.000+0000",
"lastModifiedBy": "CVANEATO",
"archive": false,
"startIndices": false,
"station": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7",
"stationId": "bfe0a6e2-e27e-0210-e053-259e228e58c7",
"weatherTimestamp": 1589486400000,
"temperature": 23.0,
"temperatureMin": null,
"temperatureMax": null,
"relativeHumidity": 36.0,
"relativeHumidityMin": null,
"relativeHumidityMax": null,
"windSpeed": 7.0,
"precipitation": 1.8,
"dangerForest": 3,
"dangerGrassland": 1,
"dangerScrub": 5,
"recordType": {
"id": "FORECAST",
"displayLabel": "Forecast",
"displayOrder": 2,
"createdBy": "DATA_LOAD",
"lastModifiedBy": "DATA_LOAD"
},
"windDirection": 300.0,
"fineFuelMoistureCode": 84.294,
"duffMoistureCode": 79.937,
"droughtCode": 463.498,
"initialSpreadIndex": 2.724,
"buildUpIndex": 111.71,
"fireWeatherIndex": 12.966,
"dailySeverityRating": null,
"grasslandCuring": null,
"observationValidInd": true,
"observationValidComment": null,
"missingHourlyData": null,
"previousState": null,
"businessKey": "1627329600000-bfe0a6e2-e27e-0210-e053-259e228e58c7",
"_links": {
"self": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"daily": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"station": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7"
}
}
},
{
"id": "dae7f61d-fa45-4f3f-b88e-25d8bb996fc0",
"createdBy": "SYBRAND",
"lastEntityUpdateTimestamp": 1590192000000,
"updateDate": "2020-05-22T17:00:00.000+0000",
"lastModifiedBy": "CVANEATO",
"archive": false,
"startIndices": false,
"station": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7",
"stationId": "bfe0a6e2-e27e-0210-e053-259e228e58c7",
"weatherTimestamp": 1589659200000,
"temperature": 21.0,
"temperatureMin": null,
"temperatureMax": null,
"relativeHumidity": 34.0,
"relativeHumidityMin": null,
"relativeHumidityMax": null,
"windSpeed": 5.0,
"precipitation": 0.8,
"dangerForest": 2,
"dangerGrassland": 0,
"dangerScrub": 4,
"recordType": {
"id": "FORECAST",
"displayLabel": "Forecast",
"displayOrder": 2,
"createdBy": "DATA_LOAD",
"lastModifiedBy": "DATA_LOAD"
},
"windDirection": 200.0,
"fineFuelMoistureCode": 54.294,
"duffMoistureCode": 59.937,
"droughtCode": 363.498,
"initialSpreadIndex": 1.724,
"buildUpIndex": 11.71,
"fireWeatherIndex": 2.966,
"dailySeverityRating": null,
"grasslandCuring": null,
"observationValidInd": true,
"observationValidComment": null,
"missingHourlyData": null,
"previousState": null,
"businessKey": "1627329600000-bfe0a6e2-e27e-0210-e053-259e228e58c7",
"_links": {
"self": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"daily": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"station": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7"
}
}
},
{
"id": "aae7f61d-fa45-4f3f-b88e-25d8bb996fc0",
"createdBy": "SYBRAND",
"lastEntityUpdateTimestamp": 1590192000000,
"updateDate": "2020-05-22T17:00:00.000+0000",
"lastModifiedBy": "CVANEATO",
"archive": false,
"startIndices": false,
"station": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7",
"stationId": "bfe0a6e2-e286-0210-e053-259e228e58c7",
"weatherTimestamp": 1589486400000,
"temperature": 23.0,
"temperatureMin": null,
"temperatureMax": null,
"relativeHumidity": 36.0,
"relativeHumidityMin": null,
"relativeHumidityMax": null,
"windSpeed": 7.0,
"precipitation": 1.8,
"dangerForest": 3,
"dangerGrassland": 1,
"dangerScrub": 5,
"recordType": {
"id": "FORECAST",
"displayLabel": "Forecast",
"displayOrder": 2,
"createdBy": "DATA_LOAD",
"lastModifiedBy": "DATA_LOAD"
},
"windDirection": 300.0,
"fineFuelMoistureCode": 84.294,
"duffMoistureCode": 79.937,
"droughtCode": 463.498,
"initialSpreadIndex": 2.724,
"buildUpIndex": 111.71,
"fireWeatherIndex": 12.966,
"dailySeverityRating": null,
"grasslandCuring": null,
"observationValidInd": true,
"observationValidComment": null,
"missingHourlyData": null,
"previousState": null,
"businessKey": "1627329600000-bfe0a6e2-e27e-0210-e053-259e228e58c7",
"_links": {
"self": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"daily": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"station": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7"
}
}
},
{
"id": "aae7f61d-fa45-4f3f-b88e-25d8bb996fc0",
"createdBy": "SYBRAND",
"lastEntityUpdateTimestamp": 1590192000000,
"updateDate": "2020-05-22T17:00:00.000+0000",
"lastModifiedBy": "CVANEATO",
"archive": false,
"startIndices": false,
"station": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7",
"stationId": "bfe0a6e2-e286-0210-e053-259e228e58c7",
"weatherTimestamp": 1589572800000,
"temperature": 3.0,
"temperatureMin": null,
"temperatureMax": null,
"relativeHumidity": 6.0,
"relativeHumidityMin": null,
"relativeHumidityMax": null,
"windSpeed": 1.0,
"precipitation": 0.8,
"dangerForest": 2,
"dangerGrassland": 2,
"dangerScrub": 2,
"recordType": {
"id": "FORECAST",
"displayLabel": "Forecast",
"displayOrder": 2,
"createdBy": "DATA_LOAD",
"lastModifiedBy": "DATA_LOAD"
},
"windDirection": 320.0,
"fineFuelMoistureCode": 94.294,
"duffMoistureCode": 89.937,
"droughtCode": 473.498,
"initialSpreadIndex": 3.724,
"buildUpIndex": 121.71,
"fireWeatherIndex": 13.866,
"dailySeverityRating": null,
"grasslandCuring": null,
"observationValidInd": true,
"observationValidComment": null,
"missingHourlyData": null,
"previousState": null,
"businessKey": "1627329600000-bfe0a6e2-e27e-0210-e053-259e228e58c7",
"_links": {
"self": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"daily": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"station": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7"
}
}
},
{
"id": "aae7f61d-fa45-4f3f-b88e-25d8bb996fc0",
"createdBy": "SYBRAND",
"lastEntityUpdateTimestamp": 1590192000000,
"updateDate": "2020-05-22T17:00:00.000+0000",
"lastModifiedBy": "CVANEATO",
"archive": false,
"startIndices": false,
"station": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7",
"stationId": "bfe0a6e2-e286-0210-e053-259e228e58c7",
"weatherTimestamp": 1589659200000,
"temperature": 13.0,
"temperatureMin": null,
"temperatureMax": null,
"relativeHumidity": 13.0,
"relativeHumidityMin": null,
"relativeHumidityMax": null,
"windSpeed": 2.3,
"precipitation": 0.2,
"dangerForest": 2,
"dangerGrassland": 2,
"dangerScrub": 3,
"recordType": {
"id": "FORECAST",
"displayLabel": "Forecast",
"displayOrder": 2,
"createdBy": "DATA_LOAD",
"lastModifiedBy": "DATA_LOAD"
},
"windDirection": 120.0,
"fineFuelMoistureCode": 14.294,
"duffMoistureCode": 39.937,
"droughtCode": 233.498,
"initialSpreadIndex": 1.123,
"buildUpIndex": 101.71,
"fireWeatherIndex": 10.966,
"dailySeverityRating": null,
"grasslandCuring": null,
"observationValidInd": true,
"observationValidComment": null,
"missingHourlyData": null,
"previousState": null,
"businessKey": "1627329600000-bfe0a6e2-e27e-0210-e053-259e228e58c7",
"_links": {
"self": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"daily": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/dae7f61d-fa45-4f3f-b88e-25d8bb996fc0"
},
"station": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/stations/bfe0a6e2-e27e-0210-e053-259e228e58c7"
}
}
}
]
},
"_links": {
"self": {
"href": "https://bcwsapi.nrs.gov.bc.ca/wfwx-fireweather-api/v1/dailies/search/findDailiesByStationIdIsInAndWeatherTimestampBetweenOrderByStationIdAscWeatherTimestampAsc?startingTimestamp=1627329600000&endingTimestamp=1627329600000&stationIds=bfe0a6e2-e27e-0210-e053-259e228e58c7&page=0&size=10"
}
}
}
11 changes: 7 additions & 4 deletions api/app/tests/hfi/test_hfi_endpoint_request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Feature: /hfi/
And the response is <response_json>

Examples:
| request_json | status_code | response_json |
# TODO: These test currently exposes a "bug" in the code where removing a station from one area, means it's removed from all.
| request_json | status_code | response_json |
# Test perfect scenario, we have 2 stations, they're both selected, and they have data for all days.
| test_hfi_endpoint_request.json | 200 | test_hfi_endpoint_response.json |
# Test scenario where we have 1 station selected, one station deselected, and data for all days.
# Test less than ideal scenario, we have 2 stations, they're both selected, one of them is missing data for some days.
| test_hfi_endpoint_request.json | 200 | test_hfi_endpoint_response.json |
# Test scenario where we have 1 station selected, one station deselected, and data for all days.
| test_hfi_endpoint_request_1_of_2_stations_selected.json | 200 | test_hfi_endpoint_response_1_of_2_stations_selected.json |
# Test less than ideal scenario, we have 2 stations, they're both selected, one of them is missing data for one day.
| test_hfi_endpoint_request_missing_data.json | 200 | test_hfi_endpoint_response_missing_data.json |
33 changes: 32 additions & 1 deletion api/app/tests/hfi/test_hfi_endpoint_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,38 @@
import app.main
from app.tests.common import default_mock_client_get
from app.tests import load_json_file, load_json_file_with_name
from app.tests.hfi import mock_station_crud
from app.schemas.shared import FuelType
from app.db.models.hfi_calc import PlanningWeatherStation


def mock_station_crud(monkeypatch):
code1 = 230
code2 = 239
all_station_codes = [{'station_code': code1}, {'station_code': code2}]

def mock_get_all_stations(__):
""" Returns mocked WFWXWeatherStations codes. """
return all_station_codes

def mock_get_fire_centre_stations(_, fire_centre_id: int):
""" Returns mocked WFWXWeatherStation with fuel types. """
def get_fuel_type_code_by_station_code(code: int):
if code == 230:
return 'C3'
return 'C7B'
result = []
for station_code, planning_area_id in [(230, 1), (239, 1), (230, 2)]:
planning_station = PlanningWeatherStation(
station_code=station_code, planning_area_id=planning_area_id)
fuel_type_code = get_fuel_type_code_by_station_code(station_code)
fuel_type = FuelType(abbrev=fuel_type_code, fuel_type_code=fuel_type_code,
description=fuel_type_code,
percentage_conifer=100, percentage_dead_fir=0)
result.append((planning_station, fuel_type))
return result

monkeypatch.setattr(app.utils.hfi_calculator, 'get_all_stations', mock_get_all_stations)
monkeypatch.setattr(app.routers.hfi_calc, 'get_fire_centre_stations', mock_get_fire_centre_stations)


@pytest.mark.usefixtures('mock_jwt_decode')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"start_date": "2020-05-21",
"end_date": "2020-05-23",
"planning_area_station_info": {
"1": [
{
"station_code": 230,
"selected": true,
"fuel_type_id": 1
}
],
"2": [
{
"station_code": 239,
"selected": true,
"fuel_type_id": 2
}
]
},
"selected_station_code_ids": [
230
],
"selected_fire_center_id": 1,
"planning_area_fire_starts": {},
"persist_request": true
}
Loading

0 comments on commit 6ec13ac

Please sign in to comment.