Skip to content

Commit

Permalink
test: Add test to make sure depth dependent data deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Dec 19, 2023
1 parent 4dfaf4b commit 83c83fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def save(self, *args, **kwargs):
# delete project intervals...
ProjectDepthInterval.objects.filter(project=self).delete()
# delete related soil data
DepthDependentSoilData.delete_in_project(self.id)
DepthDependentSoilData.delete_in_project(self.project.id)
# create new intervals
self.apply_preset()
return result
Expand Down
25 changes: 16 additions & 9 deletions terraso_backend/tests/graphql/mutations/test_soil_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,26 +669,33 @@ def test_update_project_soil_settings(client, user, project_manager, project):
assert payload == new_data


def test_update_project_depth_interval_preset_no_change(
client, project, project_manager, site_with_soil_data
@pytest.mark.parametrize("depth_interval_preset", ["LANDPKS", "NRCS"])
def test_update_project_depth_interval_preset_depth_dependent_data(
depth_interval_preset, client, project, project_manager, site_with_soil_data
):
original_depth_interval_preset = project.soil_settings.depth_interval_preset
original_preset = project.soil_settings.depth_interval_preset
input_data = {
"projectId": str(project.id),
"depthIntervalPreset": original_depth_interval_preset,
"depthIntervalPreset": depth_interval_preset,
}
client.force_login(project_manager)
response = graphql_query(UPDATE_PROJECT_SETTINGS_QUERY, input_data=input_data, client=client)
payload = response.json()
assert "errors" not in payload
intervals = match_json("*..depthIntervals", payload)
assert intervals[0] == make_intervals(LandPKSIntervalDefaults)
# make sure soil data was not deleted
expected_intervals = make_intervals(
{"LANDPKS": LandPKSIntervalDefaults, "NRCS": NRCSIntervalDefaults}[depth_interval_preset]
)
assert intervals[0] == expected_intervals
# make sure soil data was handled correctly
project.refresh_from_db()
assert project.soil_settings.depth_interval_preset == original_depth_interval_preset
assert project.soil_settings.depth_interval_preset == depth_interval_preset
site_with_soil_data.refresh_from_db()
assert len(project.soil_settings.depth_intervals.all()) > 0
assert len(site_with_soil_data.soil_data.depth_dependent_data.all()) > 0
assert project.soil_settings.depth_intervals.exists()
if original_preset == depth_interval_preset:
assert site_with_soil_data.soil_data.depth_dependent_data.exists()
else:
assert not site_with_soil_data.soil_data.depth_dependent_data.exists()


UPDATE_SOIL_DEPTH_PRESET_GRAPHQL = """
Expand Down

0 comments on commit 83c83fb

Please sign in to comment.