Skip to content

Commit

Permalink
projects: add geoloation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ra committed Sep 17, 2024
1 parent 2381d35 commit 5433b4b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/8304.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- create project dashboard component for editing location
- enable geolocation for projects from the admin in organisations
- display location item in dashboard only if enable in the organisation
- test for geolocation field and serialiser in projects
49 changes: 49 additions & 0 deletions tests/projects/test_project_geolocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
from django.urls import reverse

from adhocracy4.projects.models import Project
from adhocracy4.test import helpers

# Define a GeoJSON point
geojson_point = {
"type": "Feature",
"properties": {},
"geometry": {"type": "Point", "coordinates": [1.0, 1.0]},
}


@pytest.mark.django_db
def test_project_with_geojson_point(project_factory):
project = project_factory(is_app_accessible=True)

# Create a Project instance with the GeoJSON point
project.point = geojson_point
project.save()

fetched_project = Project.objects.get(id=project.id)

# Check if the point is correctly stored
assert fetched_project.point == geojson_point
print(fetched_project.point)
assert fetched_project.point["geometry"]["coordinates"] == [
1.0,
1.0,
] # Check coordinates


@pytest.mark.django_db
def test_project_geojson_point_serialiser(
user, project_factory, module_factory, phase_factory, apiclient
):
project = project_factory(is_app_accessible=True, point=geojson_point)
module = module_factory(project=project)
# module_factory(project=project, is_draft=True)
phase = phase_factory(module=module)

url = reverse("app-projects-list")
apiclient.login(username=user.email, password="password")
with helpers.freeze_phase(phase):
response = apiclient.get(url, format="json")

assert response.status_code == 200
assert response.data[0]["point"] == str(geojson_point)

0 comments on commit 5433b4b

Please sign in to comment.