def test_to_archive(self): waypoint = Waypoint( document_id=1, waypoint_type="summit", elevation=2203, locales=[ WaypointLocale(id=2, lang="en", title="A", description="abc"), WaypointLocale(id=3, lang="fr", title="B", description="bcd"), ], geometry=DocumentGeometry(document_id=1, geom=from_shape(Point(1, 1), srid=3857)), ) waypoint_archive = waypoint.to_archive() self.assertIsNone(waypoint_archive.id) self.assertEqual(waypoint_archive.document_id, waypoint.document_id) self.assertEqual(waypoint_archive.waypoint_type, waypoint.waypoint_type) self.assertEqual(waypoint_archive.elevation, waypoint.elevation) archive_locals = waypoint.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = waypoint.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title) self.assertEqual(locale_archive.description, locale.description) archive_geometry = waypoint.get_archive_geometry() self.assertIsNone(archive_geometry.id) self.assertIsNotNone(archive_geometry.document_id) self.assertEqual(archive_geometry.document_id, waypoint.document_id) self.assertIsNotNone(archive_geometry.geom)
def test_geometry_update_optimization_4326(self): lat = 46.0 geom1 = 'SRID=4326;POINT(' + str(lat) + ' 6.0)' waypoint_db = Waypoint( document_id=1, waypoint_type='summit', elevation=2203, geometry=DocumentGeometry( document_id=1, geom=geom1 ) ) waypoint_in = Waypoint( document_id=1, waypoint_type='summit', elevation=1234, geometry=DocumentGeometry( geom='SRID=4326;POINT(' + str(lat + 10**(-8)) + ' 6.0)') ) waypoint_db.update(waypoint_in) self.assertEqual(waypoint_db.geometry.geom, geom1) waypoint_in = Waypoint( document_id=1, waypoint_type='summit', elevation=1234, geometry=DocumentGeometry( geom='SRID=4326;POINT(' + str(lat + 10**(-7)) + ' 6.0)') ) waypoint_db.update(waypoint_in) self.assertNotEqual(waypoint_db.geometry.geom, geom1)
def test_version_concurrent_edit(self): """Test that a `StaleDataError` is thrown when trying to update a waypoint with an old version number. """ waypoint1 = Waypoint( waypoint_type="summit", elevation=2203, locales=[WaypointLocale(lang="en", title="A", description="abc")] ) # add the initial waypoint self.session.add(waypoint1) self.session.flush() self.session.expunge(waypoint1) version1 = waypoint1.version self.assertIsNotNone(version1) # change the waypoint waypoint2 = self.session.query(Waypoint).get(waypoint1.document_id) waypoint2.elevation = 1234 self.session.merge(waypoint2) self.session.flush() version2 = waypoint2.version self.assertNotEqual(version1, version2) self.assertNotEqual(waypoint1.version, waypoint2.version) self.assertNotEqual(waypoint1.elevation, waypoint2.elevation) # then try to update the waypoint again with the old version waypoint1.elevation = 2345 self.assertRaises(StaleDataError, self.session.merge, waypoint1)
def test_geometry_update_skip_optimization(self): geom1 = "SRID=3857;POINT(445278.0 334111.0)" waypoint_db = Waypoint( document_id=1, waypoint_type="summit", elevation=2203, geometry=DocumentGeometry(document_id=1, geom=geom1) ) waypoint_in = Waypoint(document_id=1, waypoint_type="summit", elevation=1234, geometry=None) waypoint_db.update(waypoint_in) self.assertEqual(waypoint_db.geometry.geom, geom1)
def test_version_is_incremented(self): waypoint = Waypoint( waypoint_type="summit", elevation=2203, locales=[WaypointLocale(lang="en", title="A", description="abc")] ) self.session.add(waypoint) self.session.flush() version1 = waypoint.version self.assertIsNotNone(version1) # make a change to the waypoint and check that the version changes # once the waypoint is persisted waypoint.elevation = 1234 self.session.merge(waypoint) self.session.flush() version2 = waypoint.version self.assertNotEqual(version1, version2)
def test_update(self): waypoint_db = Waypoint( document_id=1, waypoint_type='summit', elevation=2203, version=123, locales=[ WaypointLocale( id=2, culture='en', title='A', description='abc', version=345), WaypointLocale( id=3, culture='fr', title='B', description='bcd', version=678), ], geometry=DocumentGeometry( document_id=1, geom='SRID=3857;POINT(1 2)' ) ) waypoint_in = Waypoint( document_id=1, waypoint_type='summit', elevation=1234, version=123, locales=[ WaypointLocale( id=2, culture='en', title='C', description='abc', version=345), WaypointLocale( culture='es', title='D', description='efg'), ], geometry=DocumentGeometry(geom='SRID=3857;POINT(3 4)') ) waypoint_db.update(waypoint_in) self.assertEqual(waypoint_db.elevation, waypoint_in.elevation) self.assertEqual(len(waypoint_db.locales), 3) locale_en = waypoint_db.get_locale('en') locale_fr = waypoint_db.get_locale('fr') locale_es = waypoint_db.get_locale('es') self.assertEqual(locale_en.title, 'C') self.assertEqual(locale_fr.title, 'B') self.assertEqual(locale_es.title, 'D') self.assertEqual(waypoint_db.geometry.geom, 'SRID=3857;POINT(3 4)')
def test_version_is_incremented(self): waypoint = Waypoint( document_id=1, waypoint_type='summit', elevation=2203, locales=[ WaypointLocale( id=2, culture='en', title='A', description='abc') ] ) self.session.add(waypoint) self.session.flush() version1 = waypoint.version self.assertIsNotNone(version1) # make a change to the waypoint and check that the version changes # once the waypoint is persisted waypoint.elevation = 1234 self.session.merge(waypoint) self.session.flush() version2 = waypoint.version self.assertNotEqual(version1, version2)
def test_geometry_update_optimization_3857(self): geom1 = "SRID=3857;POINT(445278.0 1.0)" waypoint_db = Waypoint( document_id=1, waypoint_type="summit", elevation=2203, geometry=DocumentGeometry(document_id=1, geom=geom1) ) waypoint_in = Waypoint( document_id=1, waypoint_type="summit", elevation=1234, geometry=DocumentGeometry(geom="SRID=3857;POINT(445278.5 1.0)"), ) waypoint_db.update(waypoint_in) self.assertEqual(waypoint_db.geometry.geom, geom1) waypoint_in = Waypoint( document_id=1, waypoint_type="summit", elevation=14, geometry=DocumentGeometry(geom="SRID=3857;POINT(445279.0 1.0)"), ) waypoint_db.update(waypoint_in) self.assertNotEqual(waypoint_db.geometry.geom, geom1)
def test_to_archive(self): waypoint = Waypoint( document_id=1, waypoint_type='summit', elevation=2203, locales=[ WaypointLocale( id=2, culture='en', title='A', description='abc'), WaypointLocale( id=3, culture='fr', title='B', description='bcd'), ], geometry=DocumentGeometry( document_id=1, geom=from_shape(Point(1, 1), srid=3857)) ) waypoint_archive = waypoint.to_archive() self.assertIsNone(waypoint_archive.id) self.assertEqual(waypoint_archive.document_id, waypoint.document_id) self.assertEqual( waypoint_archive.waypoint_type, waypoint.waypoint_type) self.assertEqual(waypoint_archive.elevation, waypoint.elevation) archive_locals = waypoint.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = waypoint.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.culture, locale.culture) self.assertEqual(locale_archive.title, locale.title) self.assertEqual(locale_archive.description, locale.description) archive_geometry = waypoint.get_archive_geometry() self.assertIsNone(archive_geometry.id) self.assertIsNotNone(archive_geometry.document_id) self.assertEqual(archive_geometry.document_id, waypoint.document_id) self.assertIsNotNone(archive_geometry.geom)
def test_update(self): waypoint_db = Waypoint( document_id=1, waypoint_type="summit", elevation=2203, version=123, locales=[ WaypointLocale(id=2, lang="en", title="A", description="abc", version=345), WaypointLocale(id=3, lang="fr", title="B", description="bcd", version=678), ], geometry=DocumentGeometry(document_id=1, geom="SRID=3857;POINT(1 2)"), ) waypoint_in = Waypoint( document_id=1, waypoint_type="summit", elevation=1234, version=123, locales=[ WaypointLocale(id=2, lang="en", title="C", description="abc", version=345), WaypointLocale(lang="es", title="D", description="efg"), ], geometry=DocumentGeometry(geom="SRID=3857;POINT(3 4)"), ) waypoint_db.update(waypoint_in) self.assertEqual(waypoint_db.elevation, waypoint_in.elevation) self.assertEqual(len(waypoint_db.locales), 3) locale_en = waypoint_db.get_locale("en") locale_fr = waypoint_db.get_locale("fr") locale_es = waypoint_db.get_locale("es") self.assertEqual(locale_en.title, "C") self.assertEqual(locale_fr.title, "B") self.assertEqual(locale_es.title, "D") self.assertEqual(waypoint_db.geometry.geom, "SRID=3857;POINT(3 4)")
def test_fill_index(self): """Tests that documents are inserted into the ElasticSearch index. """ self.session.add( Waypoint(document_id=71171, waypoint_type='summit', elevation=2000, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Mont Granier', description='...', summary='Le Mont [b]Granier[/b]'), WaypointLocale(lang='en', title='Mont Granier', description='...', summary='The Mont Granier') ])) self.session.add( Waypoint(document_id=71172, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ])) self.session.add( Route(document_id=71173, activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', locales=[ RouteLocale(lang='en', title='Face N', description='...', gear='paraglider', title_prefix='Mont Blanc') ])) self.session.add( Waypoint(document_id=71174, redirects_to=71171, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ])) self.session.flush() # fill the ElasticSearch index fill_index(self.session) waypoint1 = SearchWaypoint.get(id=71171) self.assertIsNotNone(waypoint1) self.assertEqual(waypoint1.title_en, 'Mont Granier') self.assertEqual(waypoint1.title_fr, 'Mont Granier') self.assertEqual(waypoint1.summary_fr, 'Le Mont Granier ') self.assertEqual(waypoint1.doc_type, 'w') self.assertAlmostEqual(waypoint1.geom[0], 5.71288994) self.assertAlmostEqual(waypoint1.geom[1], 45.64476395) waypoint2 = SearchWaypoint.get(id=71172) self.assertIsNotNone(waypoint2) self.assertEqual(waypoint2.title_en, 'Mont Blanc') self.assertEqual(waypoint2.title_fr, '') self.assertEqual(waypoint2.doc_type, 'w') route = SearchRoute.get(id=71173) self.assertIsNotNone(route) self.assertEqual(route.title_en, 'Mont Blanc : Face N') self.assertEqual(route.title_fr, '') self.assertEqual(route.doc_type, 'r') # merged document is ignored self.assertIsNone(SearchWaypoint.get(id=71174, ignore=404)) # check that the sync. status was updated last_update, _ = es_sync.get_status(self.session) self.assertIsNotNone(last_update)
def _add_test_data(self): self.area1 = Area(area_type='range') self.locale_en = DocumentLocale(lang='en', title='Chartreuse') self.locale_fr = DocumentLocale(lang='fr', title='Chartreuse') self.area1.locales.append(self.locale_en) self.area1.locales.append(self.locale_fr) self.area1.geometry = DocumentGeometry( geom_detail='SRID=3857;POLYGON((668518.249382151 5728802.39591739,668518.249382151 5745465.66808356,689156.247019149 5745465.66808356,689156.247019149 5728802.39591739,668518.249382151 5728802.39591739))' # noqa ) self.session.add(self.area1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.area1, user_id) self.area1_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.area1.document_id). \ filter(DocumentVersion.lang == 'en').first() self.area2 = Area(area_type='range') self.session.add(self.area2) self.area3 = Area(area_type='range') self.session.add(self.area3) self.area4 = Area(area_type='admin_limits') self.area4.locales.append(DocumentLocale( lang='en', title='Isère')) self.area4.locales.append(DocumentLocale( lang='fr', title='Isère')) self.session.add(self.area4) self.waypoint1 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(677461.381691516 5740879.44638645)') ) self.waypoint2 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(693666.031687976 5741108.7574713)') ) route_geom = 'SRID=3857;LINESTRING(668518 5728802, 668528 5728812)' self.route = Route( activities=['skitouring'], geometry=DocumentGeometry(geom_detail=route_geom)) self.session.add_all([self.waypoint1, self.waypoint2, self.route]) self.session.add(AreaAssociation( document=self.waypoint2, area=self.area1)) self.image = Image( filename='image.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale( lang='en', title='Mont Blanc from the air', description='...') ]) self.session.add(self.image) self.session.flush() self.session.add(Association.create(self.area1, self.image)) self.session.flush()
def _add_test_data(self): user_id = self.global_userids['contributor'] self.waypoint1 = Waypoint(waypoint_type='summit', elevation=2203) self.session.add(self.waypoint1) self.waypoint2 = Waypoint(waypoint_type='summit', elevation=200) self.session.add(self.waypoint2) self.session.flush() self.waypoint3 = Waypoint(waypoint_type='summit', elevation=200, redirects_to=self.waypoint1.document_id) self.session.add(self.waypoint3) self.route1 = Route(activities=['skitouring']) self.session.add(self.route1) self.session.add(self.waypoint2) self.route2 = Route(activities=['skitouring']) self.session.add(self.route2) self.image1 = Image(filename='image.jpg', locales=[ DocumentLocale(lang='en', title='Mont Blanc from the air') ]) self.session.add(self.image1) self.session.flush() DocumentRest.create_new_version(self.image1, user_id) self.article1 = Article( categories=['site_info'], activities=['hiking'], article_type='collab', locales=[DocumentLocale(lang='en', title='Lac d\'Annecy')]) self.session.add(self.article1) self.session.flush() DocumentRest.create_new_version(self.article1, user_id) self.article2 = Article( categories=['site_info'], activities=['hiking'], article_type='personal', locales=[DocumentLocale(lang='en', title='Lac d\'Annecy')]) self.session.add(self.article2) self.session.flush() DocumentRest.create_new_version(self.article2, user_id) self.report1 = Xreport( event_activity='alpine_climbing', locales=[XreportLocale(lang='en', title='Lac d\'Annecy')]) self.session.add(self.report1) self.session.flush() DocumentRest.create_new_version(self.report1, user_id) self.outing = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1)) self.session.add(self.outing) self.session.flush() self.session.add( Association(parent_document_id=user_id, parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing.document_id, child_document_type=OUTING_TYPE)) update_feed_document_create(self.outing, user_id) self.session.flush() # create a 2nd feed entry for the outing feed_change = self.get_feed_change(self.outing.document_id) user_id = self.global_userids['moderator'] feed_change2 = feed_change.copy() feed_change2.change_type = 'added_photos' feed_change2.user_id = user_id feed_change2.user_ids = list( set(feed_change.user_ids).union([user_id])) self.session.add(feed_change2) self.session.flush()
def _add_test_data(self): self.image = Image(filename='image.jpg', activities=['paragliding'], height=1500, image_type='collaborative') self.locale_en = DocumentLocale( lang='en', title='Mont Blanc from the air', description='...', document_topic=DocumentTopic(topic_id=1)) self.locale_fr = DocumentLocale(lang='fr', title='Mont Blanc du ciel', description='...') self.image.locales.append(self.locale_en) self.image.locales.append(self.locale_fr) self.image.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.image) self.session.flush() self.article1 = Article(categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article1) self.session.flush() self.session.add( Association.create(parent_document=self.article1, child_document=self.image)) self.book1 = Book(activities=['hiking'], book_types=['biography']) self.session.add(self.book1) self.session.flush() self.session.add( Association.create(parent_document=self.book1, child_document=self.image)) user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.image, user_id) self.image_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.image.document_id). \ filter(DocumentVersion.lang == 'en').first() self.image2 = Image(filename='image2.jpg', activities=['paragliding'], height=1500) self.session.add(self.image2) self.image3 = Image(filename='image3.jpg', activities=['paragliding'], height=1500) self.session.add(self.image3) self.image4 = Image(filename='image4.jpg', activities=['paragliding'], height=1500, image_type='personal') self.image4.locales.append( DocumentLocale(lang='en', title='Mont Blanc from the air', description='...')) self.image4.locales.append( DocumentLocale(lang='fr', title='Mont Blanc du ciel', description='...')) self.session.add(self.image4) self.session.flush() DocumentRest.create_new_version(self.image3, self.global_userids['contributor2']) DocumentRest.create_new_version(self.image4, user_id) self.session.add( Association.create(parent_document=self.image, child_document=self.image2)) self.waypoint = Waypoint( waypoint_type='summit', elevation=4, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.waypoint.locales.append( WaypointLocale(lang='en', title='Mont Granier (en)', description='...', access='yep')) self.session.add(self.waypoint) self.session.flush() update_feed_document_create(self.waypoint, user_id) self.session.flush() self.area = Area(area_type='range', locales=[DocumentLocale(lang='fr', title='France')]) self.session.add(self.area) self.session.flush() self.session.add(Association.create(self.area, self.image)) self.session.flush() self.outing1 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add(self.outing1) self.session.flush() self.session.add( Association.create(parent_document=self.outing1, child_document=self.image)) self.session.add( Association(parent_document_id=self.global_userids['contributor'], parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing1.document_id, child_document_type=OUTING_TYPE)) update_feed_document_create(self.outing1, user_id) self.session.flush()
def _add_test_data(self): self.xreport1 = Xreport(event_activity='skitouring', event_type='stone_ice_fall') self.locale_en = XreportLocale(lang='en', title='Lac d\'Annecy', place='some place descrip. in english') self.locale_fr = XreportLocale(lang='fr', title='Lac d\'Annecy', place='some place descrip. in french') self.xreport1.locales.append(self.locale_en) self.xreport1.locales.append(self.locale_fr) self.session.add(self.xreport1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.xreport1, user_id) self.xreport1_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.xreport1.document_id). \ filter(DocumentVersion.lang == 'en').first() user_id3 = self.global_userids['contributor3'] self._add_association(Association( parent_document_id=user_id3, parent_document_type=USERPROFILE_TYPE, child_document_id=self.xreport1.document_id, child_document_type=XREPORT_TYPE), user_id) self.xreport2 = Xreport(event_activity='skitouring', event_type='avalanche', nb_participants=5) self.session.add(self.xreport2) self.xreport3 = Xreport(event_activity='skitouring', event_type='avalanche', nb_participants=5) self.session.add(self.xreport3) self.xreport4 = Xreport(event_activity='skitouring', event_type='avalanche', nb_participants=5, nb_impacted=5, age=50) self.xreport4.locales.append(DocumentLocale( lang='en', title='Lac d\'Annecy')) self.xreport4.locales.append(DocumentLocale( lang='fr', title='Lac d\'Annecy')) self.session.add(self.xreport4) self.article2 = Article( categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article2) self.session.flush() self.image2 = Image( filename='image2.jpg', activities=['paragliding'], height=1500) self.session.add(self.image2) self.session.flush() self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2203) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='climbing_outdoor', elevation=2, rock_types=[], geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') ) self.session.add(self.waypoint2) self.session.flush() self.outing3 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 2, 1), date_end=datetime.date(2016, 2, 2) ) self.session.add(self.outing3) self.route3 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=500, height_diff_down=500, durations='1') self.session.add(self.route3) self.session.flush() self._add_association(Association.create( parent_document=self.outing3, child_document=self.xreport1), user_id) self._add_association(Association.create( parent_document=self.route3, child_document=self.xreport1), user_id) self.session.flush()
def setUp(self): # noqa super(TestDocumentDeleteRest, self).setUp() self._prefix = '/documents/delete/' user_id = self.global_userids['contributor'] self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2000, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale( lang='fr', title='Dent de Crolles', description='...', summary='La Dent de Crolles') ]) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale( lang='en', title='Mont Blanc', description='...', document_topic=DocumentTopic(topic_id=1), summary='The heighest point in Europe') ]) self.session.add(self.waypoint2) self.waypoint3 = Waypoint( waypoint_type='summit', elevation=3, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)')) self.waypoint3.locales.append(WaypointLocale( lang='en', title='Mont Granier', description='...', access='yep', document_topic=DocumentTopic(topic_id=2))) self.waypoint3.locales.append(WaypointLocale( lang='fr', title='Mont Granier', description='...', access='ouai', document_topic=DocumentTopic(topic_id=3))) self.session.add(self.waypoint3) self.session.flush() self.waypoint4 = Waypoint( waypoint_type='summit', elevation=3, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)')) self.waypoint4.locales.append(WaypointLocale( lang='en', title='Mont Ventoux', description='...')) self.session.add(self.waypoint4) self.session.flush() DocumentRest.create_new_version(self.waypoint1, user_id) update_feed_document_create(self.waypoint1, user_id) DocumentRest.create_new_version(self.waypoint2, user_id) update_feed_document_create(self.waypoint2, user_id) DocumentRest.create_new_version(self.waypoint3, user_id) update_feed_document_create(self.waypoint3, user_id) DocumentRest.create_new_version(self.waypoint4, user_id) update_feed_document_create(self.waypoint4, user_id) self.session.flush() route1_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route1 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', main_waypoint_id=self.waypoint1.document_id, geometry=route1_geometry ) self.route1.locales.append(RouteLocale( lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider')) self.session.add(self.route1) route2_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route2 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', geometry=route2_geometry ) self.route2.locales.append(RouteLocale( lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider', document_topic=DocumentTopic(topic_id=4))) self.session.add(self.route2) self.session.flush() self._add_association(self.waypoint1, self.route1) self._add_association(self.waypoint2, self.route2) self.session.flush() route3_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route3 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', geometry=route3_geometry ) self.route3.locales.append(RouteLocale( lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider', document_topic=DocumentTopic(topic_id=5))) self.session.add(self.route3) self.session.flush() DocumentRest.create_new_version(self.route1, user_id) update_feed_document_create(self.route1, user_id) DocumentRest.create_new_version(self.route2, user_id) update_feed_document_create(self.route2, user_id) DocumentRest.create_new_version(self.route3, user_id) update_feed_document_create(self.route3, user_id) self._add_association(self.waypoint1, self.route3) self._add_association(self.waypoint2, self.route3) self._add_association(self.waypoint3, self.route3) self.session.flush() outing1_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.outing1 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), geometry=outing1_geometry, locales=[ OutingLocale( lang='en', title='...', description='...', weather='sunny', document_topic=DocumentTopic(topic_id=6)) ] ) self.session.add(self.outing1) self.session.flush() DocumentRest.create_new_version(self.outing1, user_id) update_feed_document_create(self.outing1, user_id) self._add_association(self.route1, self.outing1) self.session.flush() outing1b_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.outing1b = Outing( activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), geometry=outing1b_geometry, redirects_to=self.outing1.document_id, locales=[ OutingLocale( lang='en', title='...', description='...', weather='sunny') ] ) self.session.add(self.outing1b) self.session.flush() DocumentRest.create_new_version(self.outing1b, user_id) self.session.flush() outing2_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.outing2 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), geometry=outing2_geometry, locales=[ OutingLocale( lang='en', title='...', description='...', weather='sunny', document_topic=DocumentTopic(topic_id=7)) ] ) self.session.add(self.outing2) self.session.flush() DocumentRest.create_new_version(self.outing2, user_id) update_feed_document_create(self.outing2, user_id) self._add_association(self.route2, self.outing2) self._add_association(self.route3, self.outing2) self.session.flush() self.article1 = Article( activities=['skitouring'], categories=['gear'], article_type='personal', locales=[ DocumentLocale( lang='en', title='Some article', description='Some content', document_topic=DocumentTopic(topic_id=8)) ] ) self.session.add(self.article1) self.session.flush() DocumentRest.create_new_version(self.article1, user_id) update_feed_document_create(self.article1, user_id) self.session.flush() self.article1.locales[0].title = 'Some other article title' article1_lang = self.article1.locales[0].lang self.session.flush() DocumentRest.update_version( self.article1, user_id, 'new title', [UpdateType.LANG], [article1_lang]) self.session.flush() self._add_association(self.route2, self.article1) self._add_association(self.outing2, self.article1) self.session.flush() self.article2 = Article( activities=['skitouring'], categories=['gear'], article_type='personal', locales=[ DocumentLocale( lang='en', title='Some other article', description='Some content') ] ) self.session.add(self.article2) self.session.flush() # Make the article older than 24h old written_at = datetime.datetime(2016, 1, 1, 0, 0, 0) DocumentRest.create_new_version(self.article2, user_id, written_at) update_feed_document_create(self.article2, user_id) self.session.flush() self.book1 = Book( activities=['skitouring'], book_types=['biography'], locales=[ DocumentLocale( lang='en', title='Some book', description='Some content', document_topic=DocumentTopic(topic_id=9)) ] ) self.session.add(self.book1) self.session.flush() DocumentRest.create_new_version(self.book1, user_id) update_feed_document_create(self.book1, user_id) self._add_association(self.book1, self.route2) self._add_association(self.book1, self.route3) self.session.flush() self.xreport1 = Xreport( activities=['hiking'], event_type=['stone_fall'], locales=[ XreportLocale( lang='en', title='Lac d\'Annecy', place='some place descrip. in english', document_topic=DocumentTopic(topic_id=10)), XreportLocale( lang='fr', title='Lac d\'Annecy', place='some place descrip. in french', document_topic=DocumentTopic(topic_id=11)) ] ) self.session.add(self.xreport1) self.session.flush() DocumentRest.create_new_version(self.xreport1, user_id) update_feed_document_create(self.xreport1, user_id) self._add_association(self.outing2, self.xreport1) self._add_association(self.route3, self.xreport1) self.session.flush() self.image1 = Image( filename='image1.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale( lang='en', title='Mont Blanc from the air', description='...', document_topic=DocumentTopic(topic_id=12))]) self.session.add(self.image1) self.session.flush() DocumentRest.create_new_version(self.image1, user_id) self._add_association(self.outing1, self.image1) self._add_association(self.route3, self.image1) self._add_association(self.waypoint3, self.image1) self.session.flush() update_feed_images_upload( [self.image1], [{ 'filename': 'image1.jpg', 'activities': ['paragliding'], 'image_type': 'collaborative', 'height': 1500, 'locales': [ {'lang': 'en', 'title': 'Mont Blanc from the air'} ], 'associations': { 'outings': [{'document_id': self.outing1.document_id}], 'routes': [{'document_id': self.route3.document_id}], 'waypoints': [{'document_id': self.waypoint3.document_id}] } }], user_id) self.image1.filename = 'image1.1.jpg' self.session.flush() DocumentRest.update_version( self.image1, user_id, 'changed filename', [UpdateType.FIGURES], []) self.session.flush() self.topo_map1 = TopoMap( code='3232ET', editor='IGN', scale='25000', locales=[ DocumentLocale(lang='fr', title='Belley') ], geometry=DocumentGeometry(geom_detail='SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))') # noqa ) self.session.add(self.topo_map1) self.session.flush() self.session.add(TopoMapAssociation( document=self.waypoint2, topo_map=self.topo_map1)) self.session.add(TopoMapAssociation( document=self.waypoint3, topo_map=self.topo_map1)) self.session.add(TopoMapAssociation( document=self.route2, topo_map=self.topo_map1)) self.session.add(TopoMapAssociation( document=self.route3, topo_map=self.topo_map1)) self.session.flush() self.area1 = Area( area_type='range', geometry=DocumentGeometry( geom_detail='SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))' # noqa ) ) self.session.add(self.area1) self.session.flush() self.session.add(AreaAssociation( document=self.waypoint2, area=self.area1)) self.session.add(AreaAssociation( document=self.waypoint3, area=self.area1)) self.session.add(AreaAssociation( document=self.route2, area=self.area1)) self.session.add(AreaAssociation( document=self.route3, area=self.area1)) self.session.flush()
def _add_test_data(self): _, date_now = es_sync.get_status(self.session) es_sync.mark_as_updated(self.session, date_now) self.waypoint1 = Waypoint( document_id=71171, waypoint_type='summit', elevation=2000, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Mont Granier', description='...', summary='Le Mont [b]Granier[/b]'), WaypointLocale(lang='en', title='Mont Granier', description='...', summary='The Mont Granier') ]) self.waypoint2 = Waypoint( document_id=71172, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.route1 = Route(document_id=71173, activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', locales=[ RouteLocale(lang='en', title='Face N', description='...', gear='paraglider', title_prefix='Mont Blanc') ]) self.waypoint3 = Waypoint( document_id=71174, redirects_to=71171, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.outing1 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add_all([ self.waypoint1, self.waypoint2, self.waypoint3, self.route1, self.outing1 ]) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.waypoint1, user_id) DocumentRest.create_new_version(self.waypoint2, user_id) DocumentRest.create_new_version(self.waypoint3, user_id) DocumentRest.create_new_version(self.route1, user_id) DocumentRest.create_new_version(self.outing1, user_id) association_wr = Association.create(self.waypoint1, self.route1) association_ww = Association.create(self.waypoint2, self.waypoint1) association_ro = Association.create(self.route1, self.outing1) user = self.session.query(UserProfile).get( self.global_userids['contributor']) association_uo = Association.create(user, self.outing1) self.session.add_all([ association_wr, association_ww, association_ro, association_uo, association_wr.get_log(user_id), association_ww.get_log(user_id), association_ro.get_log(user_id), association_uo.get_log(user_id) ]) self.session.flush()
def setUp(self): # noqa super(TestSearchRest, self).setUp() self._prefix = '/search' self.article1 = Article( document_id=534684, categories=['site_info'], activities=['hiking'], article_type='collab', geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ DocumentLocale(lang='en', title='Lac d\'Annecy', description='...', summary='Lac d\'Annecy'), DocumentLocale(lang='en', title='Lac d\'Annecy', description='...', summary='Lac d\'Annecy') ]) self.session.add(self.article1) self.waypoint1 = Waypoint( document_id=534681, waypoint_type='summit', elevation=2000, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Dent de Crolles', description='...', summary='La Dent de Crolles'), WaypointLocale(lang='en', title='Dent de Crolles', description='...', summary='The Dent de Crolles') ]) self.session.add(self.waypoint1) self.session.add( Waypoint(document_id=534682, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ])) self.session.add( Route(document_id=534683, activities=['skitouring'], elevation_max=1500, elevation_min=700, locales=[ RouteLocale(lang='fr', title='Mont Blanc du ciel', description='...', summary='Ski') ])) self.book1 = Book( document_id=534685, activities=['hiking'], book_types=['biography'], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ DocumentLocale(lang='en', title='Lac d\'Annecy', description='...', summary='Lac d\'Annecy'), DocumentLocale(lang='en', title='Lac d\'Annecy', description='...', summary='Lac d\'Annecy') ]) self.session.add(self.book1) self.session.flush() fill_index(self.session) # make sure the search index is built force_search_index()
def _add_test_data(self): self.route = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1') self.locale_en = RouteLocale(lang='en', title='Mont Blanc from the air', description='...', gear='paraglider', title_prefix='Main waypoint title') self.locale_fr = RouteLocale(lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider') self.route.locales.append(self.locale_en) self.route.locales.append(self.locale_fr) self.route.geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.session.add(self.route) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.route, user_id) self.route_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.route.document_id). \ filter(DocumentVersion.lang == 'en').first() self.route2 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', locales=[ RouteLocale(lang='en', title='Mont Blanc from the air', description='...', gear='paraglider'), RouteLocale(lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider') ]) self.session.add(self.route2) self.session.flush() DocumentRest.create_new_version(self.route2, user_id) self.route3 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=500, height_diff_down=500, durations='1') self.session.add(self.route3) self.route4 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=500, height_diff_down=500, durations='1') self.route4.locales.append( RouteLocale(lang='en', title='Mont Blanc from the air', description='...', gear='paraglider')) self.route4.locales.append( RouteLocale(lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider')) self.session.add(self.route4) # add a map self.session.add( TopoMap( code='3232ET', editor='IGN', scale='25000', locales=[DocumentLocale(lang='fr', title='Belley')], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((635900 5723600, 635900 5723700, 636000 5723700, 636000 5723600, 635900 5723600))' ) # noqa )) # add some associations self.waypoint = Waypoint( waypoint_type='summit', elevation=4, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.waypoint.locales.append( WaypointLocale(lang='en', title='Mont Granier (en)', description='...', access='yep')) self.waypoint.locales.append( WaypointLocale(lang='fr', title='Mont Granier (fr)', description='...', access='ouai')) self.session.add(self.waypoint) self.waypoint2 = Waypoint( waypoint_type='summit', elevation=4, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.waypoint2.locales.append( WaypointLocale(lang='en', title='Mont Granier (en)', description='...', access='yep')) self.session.add(self.waypoint2) self.session.flush() self.session.add( Association(parent_document_id=self.route.document_id, child_document_id=self.route4.document_id)) self.session.add( Association(parent_document_id=self.route4.document_id, child_document_id=self.route.document_id)) self.session.add( Association(parent_document_id=self.waypoint.document_id, child_document_id=self.route.document_id)) self.outing1 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add(self.outing1) self.session.flush() self.session.add( Association(parent_document_id=self.route.document_id, child_document_id=self.outing1.document_id)) self.outing2 = Outing(redirects_to=self.outing1.document_id, activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add(self.outing2) self.session.flush() self.session.add( Association(parent_document_id=self.route.document_id, child_document_id=self.outing2.document_id)) self.session.flush() # add areas self.area1 = Area( area_type='range', geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((635900 5723600, 635900 5723700, 636000 5723700, 636000 5723600, 635900 5723600))' # noqa )) self.area2 = Area(area_type='range', locales=[DocumentLocale(lang='fr', title='France')]) self.session.add_all([self.area1, self.area2]) self.session.flush()
def _add_test_data(self): self.book1 = Book(activities=['hiking'], book_types=['biography']) self.locale_en = DocumentLocale(lang='en', title='Escalades au Thaurac') self.locale_fr = DocumentLocale(lang='fr', title='Escalades au Thaurac') self.book1.locales.append(self.locale_en) self.book1.locales.append(self.locale_fr) self.session.add(self.book1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.book1, user_id) self.book1_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.book1.document_id). \ filter(DocumentVersion.lang == 'en').first() self.book2 = Book( activities=['hiking'], book_types=['biography']) self.session.add(self.book2) self.book3 = Book( activities=['hiking'], book_types=['biography']) self.session.add(self.book3) self.book4 = Book( activities=['hiking'], book_types=['biography']) self.book4.locales.append(DocumentLocale( lang='en', title='Escalades au Thaurac')) self.book4.locales.append(DocumentLocale( lang='fr', title='Escalades au Thaurac')) self.session.add(self.book4) self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2203) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='climbing_outdoor', elevation=2, rock_types=[], geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') ) self.session.add(self.waypoint2) self.session.flush() self.article2 = Article( categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article2) self.session.flush() self.image = Image( filename='image.jpg', activities=['paragliding'], height=1500, image_type='collaborative') self.locale_en_img = DocumentLocale( lang='en', title='Mont Blanc from the air', description='...', document_topic=DocumentTopic(topic_id=1)) self.locale_fr_img = DocumentLocale( lang='fr', title='Mont Blanc du ciel', description='...') self.image.locales.append(self.locale_en_img) self.image.locales.append(self.locale_fr_img) self.image.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.image) self.session.flush() self.image2 = Image( filename='image2.jpg', activities=['paragliding'], height=1500) self.session.add(self.image2) self.session.flush() self.route2 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', locales=[ RouteLocale( lang='en', title='Mont Blanc from the air', description='...', gear='paraglider'), RouteLocale( lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider')] ) self.session.add(self.route2) self.session.flush() self.route3 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=500, height_diff_down=500, durations='1') self.session.add(self.route3) self.session.flush() # self._add_association(Association.create( # parent_document=self.book1, # child_document=self.image2), user_id) self._add_association(Association.create( parent_document=self.book1, child_document=self.route3), user_id) self._add_association(Association.create( parent_document=self.book2, child_document=self.waypoint2), user_id) self.session.flush()
def _add_test_data(self): contributor_id = self.global_userids['contributor'] self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2000, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Dent de Crolles', description='...', summary='La Dent de Crolles') ]) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='summit', elevation=4810, geometry=DocumentGeometry(geom='SRID=3857;POINT(635957 5723605)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The highest point in Europe') ]) self.session.add(self.waypoint2) self.waypoint3 = Waypoint( waypoint_type='summit', elevation=2432, geometry=DocumentGeometry(geom='SRID=3857;POINT(635958 5723606)'), locales=[ WaypointLocale(lang='en', title='Mont de Grange', description='...', summary='Some nice peak') ]) self.session.add(self.waypoint3) self.session.flush() self.initial_route1_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route1 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, main_waypoint_id=self.waypoint2.document_id, geometry=self.initial_route1_geometry, locales=[ RouteLocale(lang='fr', title='Mont Blanc du ciel', description='...', summary='Ski') ]) self.session.add(self.route1) self.session.flush() DocumentRest.create_new_version(self.waypoint1, contributor_id) DocumentRest.create_new_version(self.waypoint2, contributor_id) DocumentRest.create_new_version(self.route1, contributor_id) update_feed_document_create(self.waypoint1, contributor_id) update_feed_document_create(self.waypoint2, contributor_id) update_feed_document_create(self.route1, contributor_id) self.session.flush() association = Association.create(parent_document=self.waypoint1, child_document=self.route1) self.session.add(association) self.session.add(association.get_log(contributor_id)) association = Association.create(parent_document=self.waypoint2, child_document=self.route1) self.session.add(association) self.session.add(association.get_log(contributor_id)) self.session.flush() self.waypoint2.elevation = 8848 for locale in self.waypoint2.locales: if locale.lang == 'en': locale.title = 'Mount Everest' locale.summary = 'The highest point in the world' self.waypoint2.geometry.geom = 'SRID=3857;POINT(0 0)' self.route1.activities = ['skitouring', 'hiking'] self.route1.elevation_max = 4500 self.route1.main_waypoint_id = self.waypoint3.document_id for locale in self.route1.locales: if locale.lang == 'fr': locale.title = 'Some new route name' self.route1.geometry.geom = 'SRID=3857;POINT(0 0)' self.session.flush() DocumentRest.update_version( self.waypoint2, contributor_id, 'new version', [UpdateType.FIGURES, UpdateType.GEOM, UpdateType.LANG], ['en']) DocumentRest.update_version( self.route1, contributor_id, 'new version', [UpdateType.FIGURES, UpdateType.GEOM, UpdateType.LANG], ['fr']) self.session.flush() association = Association.create(parent_document=self.waypoint3, child_document=self.route1) self.session.add(association) self.session.add(association.get_log(contributor_id)) self.session.flush()
def _add_test_data(self): self.contributor = self.session.query(User).get( self.global_userids['contributor']) self.contributor2 = self.session.query(User).get( self.global_userids['contributor2']) DocumentRest.create_new_version(self.contributor.profile, self.contributor.id) ml = Mailinglist( listname='avalanche', user_id=self.contributor.id, email=self.contributor.email) self.session.add(ml) area = Area( area_type='range', locales=[DocumentLocale(lang='fr', title='Chartreuse')], geometry=DocumentGeometry( geom_detail='SRID=3857;POLYGON((668518.249382151 5728802.39591739,668518.249382151 5745465.66808356,689156.247019149 5745465.66808356,689156.247019149 5728802.39591739,668518.249382151 5728802.39591739))' # noqa ) ) self.session.add(area) self.session.add(AreaAssociation( document=self.contributor.profile, area=area)) self.session.flush() self.map1 = TopoMap( code='3232ET', editor='IGN', scale='25000', locales=[ DocumentLocale(lang='fr', title='Belley') ], geometry=DocumentGeometry(geom_detail='SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))') # noqa ) self.session.add(self.map1) self.session.flush() self.session.add(TopoMapAssociation( document=self.contributor.profile, topo_map=self.map1)) self.session.flush() self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2203, locales=[WaypointLocale(lang='en', title='Mont Granier')], geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)')) self.session.add(self.waypoint1) self.session.flush() DocumentRest.create_new_version(self.waypoint1, self.contributor.id) update_feed_document_create(self.waypoint1, self.contributor.id) route1_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route1 = Route( activities=['skitouring'], geometry=route1_geometry) self.route1.locales.append(RouteLocale( lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider')) self.session.add(self.route1) self.session.flush() DocumentRest.create_new_version(self.route1, self.contributor.id) update_feed_document_create(self.route1, self.contributor.id) self.session.add(Association.create( parent_document=self.waypoint1, child_document=self.route1)) self.outing1 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), elevation_max=1500, locales=[OutingLocale(lang='en', title='foo')], geometry=DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)' # noqa ) ) self.session.add(self.outing1) self.session.flush() DocumentRest.create_new_version(self.outing1, self.contributor.id) update_feed_document_create(self.outing1, self.contributor.id) self.outing2 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), elevation_max=1500, locales=[OutingLocale(lang='en', title='foo')], geometry=DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)' # noqa ) ) self.session.add(self.outing2) self.session.flush() DocumentRest.create_new_version(self.outing2, self.contributor.id) update_feed_document_create(self.outing2, self.contributor.id) self.session.add(Association( parent_document_id=self.contributor.id, parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing1.document_id, child_document_type=OUTING_TYPE)) self.session.add(Association( parent_document_id=self.contributor.id, parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing2.document_id, child_document_type=OUTING_TYPE)) self.session.add(Association( parent_document_id=self.contributor2.id, parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing2.document_id, child_document_type=OUTING_TYPE)) self.session.add(DocumentTag( document_id=self.route1.document_id, document_type=ROUTE_TYPE, user_id=self.contributor.id)) self.session.add(DocumentTagLog( document_id=self.route1.document_id, document_type=ROUTE_TYPE, user_id=self.contributor.id, is_creation=True)) self.session.flush()
def _add_test_data(self): self.outing = Outing( activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800 ) self.locale_en = OutingLocale( lang='en', title='Mont Blanc from the air', description='...', weather='sunny') self.locale_fr = OutingLocale( lang='fr', title='Mont Blanc du ciel', description='...', weather='grand beau') self.outing.locales.append(self.locale_en) self.outing.locales.append(self.locale_fr) self.outing.geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)') self.session.add(self.outing) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.outing, user_id) self.outing_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.outing.document_id). \ filter(DocumentVersion.lang == 'en').first() self.outing2 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 2, 1), date_end=datetime.date(2016, 2, 1) ) self.session.add(self.outing2) self.outing3 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 2, 1), date_end=datetime.date(2016, 2, 2) ) self.session.add(self.outing3) self.outing4 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 2, 1), date_end=datetime.date(2016, 2, 3) ) self.outing4.locales.append(OutingLocale( lang='en', title='Mont Granier (en)', description='...')) self.outing4.locales.append(OutingLocale( lang='fr', title='Mont Granier (fr)', description='...')) self.session.add(self.outing4) self.waypoint = Waypoint( waypoint_type='summit', elevation=4, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)')) self.waypoint.locales.append(WaypointLocale( lang='en', title='Mont Granier (en)', description='...', access='yep')) self.waypoint.locales.append(WaypointLocale( lang='fr', title='Mont Granier (fr)', description='...', access='ouai')) self.session.add(self.waypoint) self.image = Image(filename='20160101-00:00:00.jpg') self.image.locales.append(DocumentLocale(lang='en', title='...')) self.session.add(self.image) self.session.flush() # add some associations self.route = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', geometry=DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', # noqa geom='SRID=3857;POINT(635961 5723624)' )) self.route.locales.append(RouteLocale( lang='en', title='Mont Blanc from the air', description='...', gear='paraglider', title_prefix='Main waypoint title')) self.route.locales.append(RouteLocale( lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider')) self.session.add(self.route) self.session.flush() self.session.add(Association( parent_document_id=self.waypoint.document_id, child_document_id=self.route.document_id)) self.session.add(Association( parent_document_id=self.route.document_id, child_document_id=self.outing.document_id)) self.session.add(Association( parent_document_id=user_id, child_document_id=self.outing.document_id)) self.session.add(Association( parent_document_id=self.outing.document_id, child_document_id=self.image.document_id)) self.session.flush()
def setUp(self): # noqa super(TestDocumentMergeRest, self).setUp() self._prefix = '/documents/merge' contributor_id = self.global_userids['contributor'] self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2000, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Dent de Crolles', description='...', summary='La Dent de Crolles') ]) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.session.add(self.waypoint2) self.session.flush() self.waypoint3 = Waypoint( waypoint_type='summit', elevation=4985, redirects_to=self.waypoint1.document_id, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.session.add(self.waypoint3) self.waypoint4 = Waypoint( waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.session.add(self.waypoint4) self.session.flush() self.route1 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, main_waypoint_id=self.waypoint1.document_id, locales=[ RouteLocale(lang='fr', title='Mont Blanc du ciel', description='...', summary='Ski') ]) self.session.add(self.route1) self.route2 = Route(activities=['skitouring'], elevation_max=1400, elevation_min=700, main_waypoint_id=self.waypoint1.document_id, locales=[ RouteLocale(lang='fr', title='Mont Blanc du soleil', description='...', summary='Ski') ]) self.session.add(self.route2) self.session.flush() DocumentRest.create_new_version(self.waypoint1, contributor_id) update_feed_document_create(self.waypoint1, contributor_id) DocumentRest.create_new_version(self.route1, contributor_id) update_feed_document_create(self.route1, contributor_id) DocumentRest.create_new_version(self.route2, contributor_id) update_feed_document_create(self.route2, contributor_id) association = Association.create(parent_document=self.waypoint1, child_document=self.route1) self.session.add(association) self.session.add( association.get_log(self.global_userids['contributor'])) association = Association.create(parent_document=self.waypoint1, child_document=self.route2) self.session.add(association) self.session.add( association.get_log(self.global_userids['contributor'])) association = Association.create(parent_document=self.waypoint1, child_document=self.waypoint4) self.session.add(association) self.session.add( association.get_log(self.global_userids['contributor'])) association = Association.create(parent_document=self.waypoint2, child_document=self.waypoint4) self.session.add(association) self.session.add( association.get_log(self.global_userids['contributor'])) self.session.flush() self.image1 = Image(filename='image1.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale(lang='en', title='Mont Blanc from the air', description='...') ]) self.session.add(self.image1) self.image2 = Image(filename='image2.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale(lang='en', title='Mont Blanc from the air', description='...') ]) self.session.add(self.image2) self.session.flush() DocumentRest.create_new_version(self.image1, contributor_id) self.session.flush() self.image1.filename = 'image1.1.jpg' self.session.flush() DocumentRest.update_version(self.image1, contributor_id, 'changed filename', [UpdateType.FIGURES], []) self.session.flush() self.session.add( DocumentTag(document_id=self.route1.document_id, document_type=ROUTE_TYPE, user_id=contributor_id)) self.session.add( DocumentTagLog(document_id=self.route1.document_id, document_type=ROUTE_TYPE, user_id=contributor_id, is_creation=True)) self.session.flush()
def _add_test_data(self): _, date_now = es_sync.get_status(self.session) es_sync.mark_as_updated(self.session, date_now) self.waypoint1 = Waypoint( document_id=71171, waypoint_type='summit', elevation=2000, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Mont Granier', description='...', summary='Le Mont [b]Granier[/b]'), WaypointLocale(lang='en', title='Mont Granier', description='...', summary='The Mont Granier') ]) self.waypoint2 = Waypoint( document_id=71172, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.route1 = Route(document_id=71173, activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', locales=[ RouteLocale(lang='en', title='Face N', description='...', gear='paraglider', title_prefix='Mont Blanc') ]) self.waypoint3 = Waypoint( document_id=71174, redirects_to=71171, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.session.add_all( [self.waypoint1, self.waypoint2, self.waypoint3, self.route1]) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.waypoint1, user_id) DocumentRest.create_new_version(self.waypoint2, user_id) DocumentRest.create_new_version(self.waypoint3, user_id) DocumentRest.create_new_version(self.route1, user_id)
def test_fill_index(self): """Tests that documents are inserted into the ElasticSearch index. """ self.session.add( Waypoint(document_id=71171, waypoint_type='summit', elevation=2000, quality='medium', access_time='15min', geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Mont Granier', description='...', summary='Le Mont [b]Granier[/b]'), WaypointLocale(lang='en', title='Mont Granier', description='...', summary='The Mont Granier') ])) self.session.add( Waypoint(document_id=71172, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ])) self.session.add( Route(document_id=71173, activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations=['1'], locales=[ RouteLocale(lang='en', title='Face N', description='...', gear='paraglider', title_prefix='Mont Blanc') ])) self.session.add( Waypoint(document_id=71174, redirects_to=71171, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ])) self.session.add( Outing(document_id=71175, activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), frequentation='overcrowded', locales=[ OutingLocale(lang='en', title='Mont Blanc : Face N !', description='...', weather='sunny') ])) self.session.add( Article(document_id=71176, categories=['site_info'], activities=['hiking'], article_type='collab', geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ DocumentLocale(lang='en', title='Lac d\'Annecy', description='...', summary=''), DocumentLocale(lang='fr', title='Lac d\'Annecy', description='...', summary='') ])) self.session.flush() self.session.add( Book(document_id=71177, activities=['hiking'], book_types=['biography'], author='Denis Dainat', publication_date='', locales=[ DocumentLocale(lang='fr', title='Escalades au Thaurac', description='...', summary=''), DocumentLocale(lang='en', title='Escalades au Thaurac', description='...', summary='') ])) self.session.flush() self.session.add( Xreport(document_id=71178, event_type=['roped_fall'], activities=['skitouring'], nb_participants=10, elevation=1500, date=datetime.date(2016, 1, 1), locales=[ XreportLocale(lang='en', title='Death in the mountains', description='...', place='some place description') ])) self.session.flush() # fill the ElasticSearch index fill_index(self.session) waypoint1 = SearchWaypoint.get(id=71171) self.assertIsNotNone(waypoint1) self.assertEqual(waypoint1.title_en, 'Mont Granier') self.assertEqual(waypoint1.title_fr, 'Mont Granier') # self.assertEqual(waypoint1.summary_fr, 'Le Mont Granier ') self.assertEqual(waypoint1.doc_type, 'w') self.assertEqual(waypoint1.quality, 2) self.assertEqual(waypoint1.access_time, 3) self.assertAlmostEqual(waypoint1.geom[0], 5.71288994) self.assertAlmostEqual(waypoint1.geom[1], 45.64476395) waypoint2 = SearchWaypoint.get(id=71172) self.assertIsNotNone(waypoint2) self.assertEqual(waypoint2.title_en, 'Mont Blanc') self.assertEqual(waypoint2.title_fr, '') self.assertEqual(waypoint2.doc_type, 'w') route = SearchRoute.get(id=71173) self.assertIsNotNone(route) self.assertEqual(route.title_en, 'Mont Blanc : Face N') self.assertEqual(route.title_fr, '') self.assertEqual(route.doc_type, 'r') self.assertEqual(route.durations, [0]) outing = SearchOuting.get(id=71175) self.assertIsNotNone(outing) self.assertEqual(outing.title_en, 'Mont Blanc : Face N !') self.assertEqual(outing.title_fr, '') self.assertEqual(outing.doc_type, 'o') self.assertEqual(outing.frequentation, 3) article = SearchArticle.get(id=71176) self.assertIsNotNone(article) self.assertEqual(article.title_en, 'Lac d\'Annecy') self.assertEqual(article.title_fr, 'Lac d\'Annecy') self.assertEqual(article.doc_type, 'c') book = SearchBook.get(id=71177) self.assertIsNotNone(book) self.assertEqual(book.title_en, 'Escalades au Thaurac') self.assertEqual(book.title_fr, 'Escalades au Thaurac') self.assertEqual(book.doc_type, 'b') self.assertEqual(book.book_types, ['biography']) xreport = SearchXreport.get(id=71178) self.assertIsNotNone(xreport) self.assertEqual(xreport.title_en, 'Death in the mountains') self.assertEqual(xreport.doc_type, 'x') # merged document is ignored self.assertIsNone(SearchWaypoint.get(id=71174, ignore=404)) # check that the sync. status was updated last_update, _ = es_sync.get_status(self.session) self.assertIsNotNone(last_update)