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

feat: Expose map processing status #1387

Merged
merged 3 commits into from
Aug 5, 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
10 changes: 10 additions & 0 deletions terraso_backend/apps/graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ type VisualizationConfigNode implements Node {
configuration: JSONString
createdBy: UserNode
mapboxTilesetId: String
mapboxTilesetStatus: SharedDataVisualizationConfigMapboxTilesetStatusChoices!
dataEntry: DataEntryNode!
owner: OwnerNode
}
Expand All @@ -680,6 +681,15 @@ value as specified by
"""
scalar DateTime

"""An enumeration."""
enum SharedDataVisualizationConfigMapboxTilesetStatusChoices {
"""Pending"""
PENDING

"""Ready"""
READY
}

type DataEntryNode implements Node {
createdAt: DateTime!
name: String!
Expand Down
13 changes: 8 additions & 5 deletions terraso_backend/apps/graphql/schema/visualization_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Meta:
"created_at",
"data_entry",
"mapbox_tileset_id",
"mapbox_tileset_status",
)
interfaces = (relay.Node,)
filterset_class = VisualizationConfigFilterSet
Expand Down Expand Up @@ -137,11 +138,13 @@ def resolve_mapbox_tileset_id(self, info):
return self.mapbox_tileset_id

# Check if tileset ready to be published and update status
published = get_publish_status(self.mapbox_tileset_id)
if published:
self.mapbox_tileset_status = VisualizationConfig.MAPBOX_TILESET_READY
self.save()
return self.mapbox_tileset_id
if self.mapbox_tileset_id:
published = get_publish_status(self.mapbox_tileset_id)
if published:
self.mapbox_tileset_status = VisualizationConfig.MAPBOX_TILESET_READY
self.save()

return self.mapbox_tileset_id


class VisualizationConfigAddMutation(BaseWriteMutation):
Expand Down
22 changes: 22 additions & 0 deletions terraso_backend/tests/graphql/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,28 @@ def visualization_configs(users, groups):
return visualizations


@pytest.fixture
def visualization_config_processing(users, groups):
creator = users[0]
creator_group = groups[1]
creator_group.membership_list.save_membership(
creator.email, group_collaboration_roles.ROLE_MEMBER, CollaborationMembership.APPROVED
)
visualizations = mixer.cycle(5).blend(
VisualizationConfig,
created_by=creator,
data_entry=lambda: mixer.blend(
SharedResource,
target=creator_group,
source=lambda: mixer.blend(DataEntry, created_by=creator, size=100),
).source,
owner=creator_group,
mapbox_tileset_id=lambda: uuid.uuid4(),
mapbox_tileset_status=VisualizationConfig.MAPBOX_TILESET_PENDING,
)
return visualizations


@pytest.fixture
def taxonomy_terms():
return mixer.cycle(10).blend(TaxonomyTerm)
Expand Down
23 changes: 23 additions & 0 deletions terraso_backend/tests/graphql/test_visualization_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from apps.collaboration.models import Membership as CollaborationMembership
from apps.core import group_collaboration_roles
from apps.shared_data.models import VisualizationConfig

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -192,3 +193,25 @@ def test_visualization_configs_returns_only_for_users_groups(
assert entries_result[0] == str(visualization_config_current_user.id)
assert edges[0]["node"]["title"] == visualization_config_current_user.title
assert edges[0]["node"]["description"] == visualization_config_current_user.description


def test_visualization_configs_query_processing_status(
client_query, visualization_config_processing
):
response = client_query(
"""
{visualizationConfigs {
edges {
node {
mapboxTilesetStatus
}
}
}}
"""
)
edges = response.json()["data"]["visualizationConfigs"]["edges"]
for edge in edges:
assert (
edge["node"]["mapboxTilesetStatus"]
== VisualizationConfig.MAPBOX_TILESET_PENDING.upper()
)
Loading