diff --git a/terraso_backend/apps/project_management/migrations/0028_site_elevation.py b/terraso_backend/apps/project_management/migrations/0028_site_elevation.py index 0a582568d..0d9376908 100644 --- a/terraso_backend/apps/project_management/migrations/0028_site_elevation.py +++ b/terraso_backend/apps/project_management/migrations/0028_site_elevation.py @@ -13,7 +13,7 @@ # 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.0.4 on 2024-05-07 18:52 +# Generated by Django 5.0.4 on 2024-05-09 17:51 from django.db import migrations, models @@ -28,6 +28,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name="site", name="elevation", - field=models.FloatField(null=True), + field=models.FloatField(blank=True, null=True), ), ] diff --git a/terraso_backend/apps/project_management/models/sites.py b/terraso_backend/apps/project_management/models/sites.py index 923266845..b97d6f775 100644 --- a/terraso_backend/apps/project_management/models/sites.py +++ b/terraso_backend/apps/project_management/models/sites.py @@ -39,7 +39,7 @@ class Meta(BaseModel.Meta): name = models.CharField(max_length=200) latitude = models.FloatField() longitude = models.FloatField() - elevation = models.FloatField(null=True) + elevation = models.FloatField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) owner = models.ForeignKey( diff --git a/terraso_backend/tests/graphql/mutations/test_sites.py b/terraso_backend/tests/graphql/mutations/test_sites.py index 535da5d0d..7718ed00c 100644 --- a/terraso_backend/tests/graphql/mutations/test_sites.py +++ b/terraso_backend/tests/graphql/mutations/test_sites.py @@ -70,6 +70,30 @@ def test_site_creation(client_query, user): assert log_result.metadata == expected_metadata +def test_site_creation_without_elevation(client_query, user): + kwargs = site_creation_keywords() + del kwargs["elevation"] + response = client_query(CREATE_SITE_QUERY, variables={"input": kwargs}) + content = json.loads(response.content) + assert "errors" not in content + id = content["data"]["addSite"]["site"]["id"] + site = Site.objects.get(pk=id) + assert str(site.id) == id + assert site.latitude == pytest.approx(site.latitude) + assert site.longitude == pytest.approx(site.longitude) + assert site.elevation is None + assert site.owner == user + assert site.privacy == "public" + logs = Log.objects.all() + assert len(logs) == 1 + log_result = logs[0] + assert log_result.event == CREATE.value + assert log_result.user == user + assert log_result.resource_object == site + expected_metadata = {"name": "Test Site", "latitude": 0.0, "longitude": 0.0, "elevation": None} + assert log_result.metadata == expected_metadata + + @pytest.mark.parametrize("project_user_w_role", ["MANAGER", "CONTRIBUTOR"], indirect=True) def test_site_creation_in_project(client, project_user_w_role, project): kwargs = site_creation_keywords()