diff --git a/terraso_backend/apps/soil_id/migrations/0020_alter_projectsoilsettings_slope_required_and_more.py b/terraso_backend/apps/soil_id/migrations/0020_alter_projectsoilsettings_slope_required_and_more.py new file mode 100644 index 000000000..2e37d743d --- /dev/null +++ b/terraso_backend/apps/soil_id/migrations/0020_alter_projectsoilsettings_slope_required_and_more.py @@ -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), + ), + ] diff --git a/terraso_backend/apps/soil_id/models/project_soil_settings.py b/terraso_backend/apps/soil_id/models/project_soil_settings.py index e91e25dbd..370cb3064 100644 --- a/terraso_backend/apps/soil_id/models/project_soil_settings.py +++ b/terraso_backend/apps/soil_id/models/project_soil_settings.py @@ -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) diff --git a/terraso_backend/tests/graphql/mutations/test_soil_data.py b/terraso_backend/tests/graphql/mutations/test_soil_data.py index 29e495ee3..8b2a4eb43 100644 --- a/terraso_backend/tests/graphql/mutations/test_soil_data.py +++ b/terraso_backend/tests/graphql/mutations/test_soil_data.py @@ -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