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

fix: set correct defaults for project soil settings #1540

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright © 2024 Technology Matters
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.


# Generated by Django 5.1.2 on 2024-11-06 23:19

from django.db import migrations, models

import apps.soil_id.models.soil_data_history


class Migration(migrations.Migration):

dependencies = [
("soil_id", "0019_soildatahistory"),
]

operations = [
migrations.AlterField(
model_name="projectsoilsettings",
name="slope_required",
field=models.BooleanField(blank=True, default=True),
),
migrations.AlterField(
model_name="projectsoilsettings",
name="soil_color_required",
field=models.BooleanField(blank=True, default=True),
),
migrations.AlterField(
model_name="projectsoilsettings",
name="soil_pit_required",
field=models.BooleanField(blank=True, default=True),
),
migrations.AlterField(
model_name="projectsoilsettings",
name="soil_texture_required",
field=models.BooleanField(blank=True, default=True),
),
migrations.AlterField(
model_name="soildatahistory",
name="soil_data_changes",
field=models.JSONField(encoder=apps.soil_id.models.soil_data_history.JSONEncoder),
),
]
8 changes: 4 additions & 4 deletions terraso_backend/apps/soil_id/models/project_soil_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class Meta(BaseModel.Meta):
choices=DepthIntervalPreset.choices,
)

soil_pit_required = models.BooleanField(blank=True, default=False)
slope_required = models.BooleanField(blank=True, default=False)
soil_texture_required = models.BooleanField(blank=True, default=False)
soil_color_required = models.BooleanField(blank=True, default=False)
soil_pit_required = models.BooleanField(blank=True, default=True)
slope_required = models.BooleanField(blank=True, default=True)
soil_texture_required = models.BooleanField(blank=True, default=True)
soil_color_required = models.BooleanField(blank=True, default=True)
vertical_cracking_required = models.BooleanField(blank=True, default=False)
carbonates_required = models.BooleanField(blank=True, default=False)
ph_required = models.BooleanField(blank=True, default=False)
Expand Down
35 changes: 35 additions & 0 deletions terraso_backend/tests/graphql/mutations/test_soil_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,41 @@ def test_update_project_soil_settings(client, user, project_manager, project):
assert payload == new_data


def test_project_soil_settings_defaults(client, project_manager, project):
client.force_login(project_manager)

expected_defaults = {
"depthIntervalPreset": "NRCS",
"soilPitRequired": True,
"slopeRequired": True,
"soilTextureRequired": True,
"soilColorRequired": True,
"verticalCrackingRequired": False,
"carbonatesRequired": False,
"phRequired": False,
"soilOrganicCarbonMatterRequired": False,
"electricalConductivityRequired": False,
"sodiumAdsorptionRatioRequired": False,
"soilStructureRequired": False,
"landUseLandCoverRequired": False,
"soilLimitationsRequired": False,
"photosRequired": False,
"notesRequired": False,
}

response = graphql_query(
UPDATE_PROJECT_SETTINGS_QUERY,
variables={"input": {"projectId": str(project.id)}},
client=client,
)

assert response.json()["data"]["updateProjectSoilSettings"]["errors"] is None
payload = response.json()["data"]["updateProjectSoilSettings"]["projectSoilSettings"]
intervals = payload.pop("depthIntervals")
assert intervals == []
assert payload == expected_defaults


@pytest.mark.parametrize("depth_interval_preset", ["NRCS", "BLM", "CUSTOM"])
def test_update_project_depth_interval_preset_depth_dependent_data(
depth_interval_preset, client, project, project_manager, site_with_soil_data
Expand Down
Loading