Skip to content

Commit

Permalink
Merge pull request #1747 from florentcadot/feature/add-waypoints-exte…
Browse files Browse the repository at this point in the history
…rnal-resources

feat: add external_resources column to waypoints
  • Loading branch information
brunobesson authored Mar 5, 2024
2 parents 786e2d5 + d20638b commit 49d2462
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""add_column_external_resources_to_waypoints
Revision ID: 626354ffcda0
Revises: 305b064bdf66
Create Date: 2024-02-18 08:36:44.714268
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '626354ffcda0'
down_revision = '305b064bdf66'
branch_labels = None
depends_on = None

def upgrade():
op.add_column(
'waypoints_locales',
sa.Column(
'external_resources',
sa.String(),
nullable=True),
schema='guidebook')
op.add_column(
'waypoints_locales_archives',
sa.Column(
'external_resources',
sa.String(),
nullable=True),
schema='guidebook')


def downgrade():
op.drop_column('waypoints_locales', 'external_resources', schema='guidebook')
op.drop_column('waypoints_locales_archives', 'external_resources', schema='guidebook')
1 change: 1 addition & 0 deletions c2corg_api/models/common/fields_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'locales.title',
'locales.summary',
'locales.description',
'locales.external_resources',
'geometry.geom',
'elevation',
'maps_info',
Expand Down
5 changes: 4 additions & 1 deletion c2corg_api/models/waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,12 @@ class _WaypointLocaleMixin(object):
# date de deneigment ou d'ouverture (access)
access_period = Column(String)

# bibliographie et webographie
external_resources = Column(String)


attributes_locales = [
'access', 'access_period'
'access', 'access_period', 'external_resources'
]


Expand Down
26 changes: 26 additions & 0 deletions c2corg_api/tests/models/test_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,32 @@ def test_geometry_unique_version_document_id(self):
self.session.add(archive)
self.session.flush()

def test_set_local_external_resource(self):
en_external_resources = 'https://wikipedia.com/en'
fr_external_resources = 'https://wikipedia.com/fr'
waypoint = Waypoint(
waypoint_type='summit', elevation=2203,
locales=[
WaypointLocale(
lang='en', title='English', description='abc',
access='y', external_resources=en_external_resources),
WaypointLocale(
lang='fr', title='French', description='bcd',
access='y', external_resources=fr_external_resources)
],
geometry=DocumentGeometry(
geom='SRID=3857;POINT(635956.075332665 5723604.677994)')
)
self.session.add(waypoint)
self.session.flush()
self.session.refresh(waypoint)
fr_local = [local for local in waypoint.locales
if local.title == 'French'][0]
en_local = [local for local in waypoint.locales
if local.title == 'English'][0]
self.assertEqual(en_local.external_resources, en_external_resources)
self.assertEqual(fr_local.external_resources, fr_external_resources)

def _get_waypoint(self):
return Waypoint(
waypoint_type='summit', elevation=2203,
Expand Down
68 changes: 66 additions & 2 deletions c2corg_api/tests/views/test_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,70 @@ def search_documents(_, __):
def test_get_associations_history(self):
self._get_association_logs(self.waypoint)

def test_get_with_external_resources(self):
"""Test getting a document with locale and external resources.
"""
response = self.get(self.waypoint4)
locale_en = self.get_locale('en', response.get('locales'))
self.assertEqual(
locale_en.get('external_resources'),
'https://wikipedia.com/en'
)

def test_put_success_external_resource(self):
"""Test updating a document by adding a locale with external resources.
"""
external_resources = 'https://wikipedia.com/en'
body_put = {
'message': 'Update',
'document': {
'document_id': self.waypoint.document_id,
'version': self.waypoint.version,
'quality': quality_types[1],
'waypoint_type': 'summit',
'elevation': 1234,
'locales': [
{'lang': 'en', 'title': 'Mont Granier',
'description': 'A.', 'access': 'n',
'version': self.locale_en.version,
'external_resources': external_resources}
],
'geometry': None,
}
}
(body, waypoint) = self.put_success_all(
body_put, self.waypoint, cache_version=3)
locale_en = waypoint.get_locale('en')
self.assertEqual(locale_en.external_resources, external_resources)

def test_post_success_external_resource(self):
"""Test creating a document with external resources in locale.
"""
external_resources = 'https://wikipedia.com/en'
body = {
'geometry': {
'document_id': 5678, 'version': 6789,
'geom': '{"type": "Point", "coordinates": [635956, 5723604]}',
'geom_detail':
'{"type": "Point", "coordinates": [635956, 5723604]}'
},
'waypoint_type': 'summit',
'elevation': 3779,
'locales': [{
'id': 3456, 'version': 4567,
'lang': 'en', 'title': 'Mont Pourri',
'access': 'y', 'external_resources': external_resources}
],
'associations': {
'waypoint_children': [
{'document_id': self.waypoint2.document_id}
]
}
}
(body, waypoint) = self.post_success(body)
locale_en = waypoint.get_locale('en')
self.assertEqual(locale_en.external_resources, external_resources)

def _add_test_data(self):
self.waypoint = Waypoint(
waypoint_type='summit', elevation=2203)
Expand Down Expand Up @@ -1483,10 +1547,10 @@ def _add_test_data(self):
geom='SRID=3857;POINT(659775 5694854)'))
self.waypoint4.locales.append(WaypointLocale(
lang='en', title='Mont Granier', description='...',
access='yep'))
access='yep', external_resources='https://wikipedia.com/en'))
self.waypoint4.locales.append(WaypointLocale(
lang='fr', title='Mont Granier', description='...',
access='ouai'))
access='ouai', external_resources='https://wikipedia.com/fr'))
self.session.add(self.waypoint4)

self.waypoint5 = Waypoint(
Expand Down

0 comments on commit 49d2462

Please sign in to comment.