예제 #1
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(search_document, document,
                                   SearchOuting.FIELDS)

        SearchDocument.copy_enum_range_fields(search_document, document,
                                              SearchOuting.ENUM_RANGE_FIELDS,
                                              SearchOuting)

        if document.associated_waypoints_ids:
            # add the document ids of associated waypoints and of the parent
            # and grand-parents of these waypoints
            search_document['waypoints'] = \
                document.associated_waypoints_ids.waypoint_ids

        if document.associated_users_ids:
            # add the document ids of associated users
            search_document['users'] = \
                document.associated_users_ids.user_ids

        if document.associated_routes_ids:
            # add the document ids of associated routes
            search_document['routes'] = \
                document.associated_routes_ids.route_ids

        return search_document
예제 #2
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(
            search_document, document, SearchOuting.FIELDS)

        SearchDocument.copy_enum_range_fields(
            search_document, document, SearchOuting.ENUM_RANGE_FIELDS,
            SearchOuting)

        if document.associated_waypoints_ids:
            # add the document ids of associated waypoints and of the parent
            # and grand-parents of these waypoints
            search_document['waypoints'] = \
                document.associated_waypoints_ids.waypoint_ids

        if document.associated_users_ids:
            # add the document ids of associated users
            search_document['users'] = \
                document.associated_users_ids.user_ids

        if document.associated_routes_ids:
            # add the document ids of associated routes
            search_document['routes'] = \
                document.associated_routes_ids.route_ids

        return search_document
예제 #3
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(search_document, document,
                                   SearchRoute.FIELDS)

        SearchDocument.copy_enum_range_fields(search_document, document,
                                              SearchRoute.ENUM_RANGE_FIELDS,
                                              SearchRoute)

        for locale in document.locales:
            search_document['title_' + locale.lang] = \
                get_title(locale.title, locale.title_prefix)

        if document.associated_waypoints_ids:
            # add the document ids of associated waypoints and of the parent
            # and grand-parents of these waypoints
            search_document['waypoints'] = \
                document.associated_waypoints_ids.waypoint_ids

        if document.associated_users_ids:
            # add the document ids of associated users
            search_document['users'] = \
                document.associated_users_ids.user_ids

        return search_document
예제 #4
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(search_document, document, SearchBook.FIELDS)

        return search_document
예제 #5
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(
            search_document, document, SearchBook.FIELDS)

        return search_document
예제 #6
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(
            document, index, include_areas=False)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(search_document, document,
                                   SearchArea.FIELDS)

        return search_document
예제 #7
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(
            document, index, include_areas=False)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(
            search_document, document, SearchArea.FIELDS)

        return search_document
예제 #8
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(search_document, document,
                                   SearchWaypoint.FIELDS)
        search_document['has_phone'] = not (not (document.phone
                                                 or document.phone_custodian))

        return search_document
예제 #9
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        search_document['article_categories'] = document.categories

        SearchDocument.copy_fields(
            search_document, document, SearchArticle.FIELDS)

        return search_document
예제 #10
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(
            search_document, document, SearchWaypoint.FIELDS)
        search_document['has_phone'] = not(not(
            document.phone or document.phone_custodian))

        return search_document
예제 #11
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(
            search_document, document, SearchXreport.FIELDS)

        SearchDocument.copy_enum_range_fields(
            search_document, document, SearchXreport.ENUM_RANGE_FIELDS,
            SearchXreport)

        return search_document
예제 #12
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(search_document, document,
                                   SearchRoute.FIELDS)

        for locale in document.locales:
            search_document['title_' + locale.lang] = \
                get_title(locale.title, locale.title_prefix)

        return search_document
예제 #13
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(
            search_document, document, SearchXreport.FIELDS)

        SearchDocument.copy_enum_range_fields(
            search_document, document, SearchXreport.ENUM_RANGE_FIELDS,
            SearchXreport)

        return search_document
예제 #14
0
    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(
                    culture='fr', title='Mont Granier',
                    description='...',
                    summary='Le Mont [b]Granier[/b]'),
                WaypointLocale(
                    culture='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(
                    culture='en', title='Mont Blanc',
                    description='...',
                    summary='The heighest point in Europe')
            ]))
        self.session.flush()

        # fill the ElasticSearch index
        fill_index(self.session)

        waypoint1 = SearchDocument.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')

        waypoint2 = SearchDocument.get(id=71172)
        self.assertIsNotNone(waypoint2)
        self.assertEqual(waypoint2.title_en, 'Mont Blanc')
        self.assertEqual(waypoint2.title_fr, '')
        self.assertEqual(waypoint2.doc_type, 'w')
예제 #15
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        SearchDocument.copy_fields(search_document, document, SearchRoute.FIELDS)

        SearchDocument.copy_enum_range_fields(search_document, document, SearchRoute.ENUM_RANGE_FIELDS, SearchRoute)

        for locale in document.locales:
            search_document["title_" + locale.lang] = get_title(locale.title, locale.title_prefix)

        if document.associated_waypoints_ids:
            # add the document ids of associated waypoints and of the parent
            # and grand-parents of these waypoints
            search_document["waypoints"] = document.associated_waypoints_ids.waypoint_ids

        return search_document
예제 #16
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        for locale in document.locales:
            search_document['title_' + locale.lang] = '{0} {1}'.format(
                document.name or '', document.forum_username or '')

        return search_document
예제 #17
0
    def to_search_document(document, index):
        search_document = SearchDocument.to_search_document(document, index)

        if document.redirects_to:
            return search_document

        for locale in document.locales:
            search_document['title_' + locale.lang] = '{0} {1}'.format(
                document.username or '', document.name or '')

        return search_document
예제 #18
0
    def test_sync_search_index_update(self):
        """Tests that already existing documents are updated.
        """
        index = elasticsearch_config['index']
        waypoint = Waypoint(
            document_id=51252,
            waypoint_type='summit', elevation=2000,
            geometry=DocumentGeometry(
                geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(
                    culture='fr', title='Mont Granier',
                    description='...',
                    summary='Le Mont Granier')
            ])

        # insert the document
        t = transaction.begin()
        sync_search_index(waypoint)
        t.commit()

        # then update the document (add a new language)
        waypoint = Waypoint(
            document_id=51252,
            waypoint_type='summit', elevation=2000,
            geometry=DocumentGeometry(
                geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(
                    culture='fr', title='Mont Granier',
                    description='...',
                    summary='Le Mont Granier'),
                WaypointLocale(
                    culture='en', title='Mont Granier',
                    description='...',
                    summary='The Mont Granier')
            ])

        t = transaction.begin()
        sync_search_index(waypoint)
        t.commit()

        doc = SearchDocument.get(id=51252, index=index)
        self.assertEqual(doc['title_fr'], 'Mont Granier')
        self.assertEqual(doc['summary_fr'], 'Le Mont Granier')
        self.assertEqual(doc['title_en'], 'Mont Granier')
        self.assertEqual(doc['summary_en'], 'The Mont Granier')
예제 #19
0
    def post_success(self, request_body):
        response = self.app.post_json(self._prefix, request_body, status=403)

        headers = self.add_authorization_header(username='******')
        response = self.app.post_json(self._prefix, request_body,
                                      headers=headers, status=200)

        body = response.json
        document_id = body.get('document_id')
        self.assertIsNotNone(body.get('version'))
        self.assertIsNotNone(document_id)

        # check that the version was created correctly
        doc = self.session.query(self._model).get(document_id)
        versions = doc.versions
        self.assertEqual(len(versions), 1)
        version = versions[0]

        culture = body.get('locales')[0].get('culture')
        self.assertEqual(version.culture, culture)

        meta_data = version.history_metadata
        self.assertEqual(meta_data.comment, 'creation')
        self.assertIsNotNone(meta_data.written_at)

        archive_doc = version.document_archive
        self.assertEqual(archive_doc.document_id, document_id)
        self.assertEqual(archive_doc.version, doc.version)

        archive_locale = version.document_locales_archive
        waypoint_locale_en = doc.locales[0]
        self.assertEqual(
            archive_locale.version, waypoint_locale_en.version)
        self.assertEqual(archive_locale.document_id, document_id)
        self.assertEqual(archive_locale.culture, culture)

        # check updates to the search index
        search_doc = SearchDocument.get(
            id=doc.document_id,
            index=elasticsearch_config['index'])

        self.assertEqual(search_doc['doc_type'], doc.type)
        self.assertEqual(search_doc['title_en'], waypoint_locale_en.title)

        return (body, doc)
예제 #20
0
    def test_sync_search_index_insert(self):
        """Tests that new documents are inserted in the index.
        """
        index = elasticsearch_config['index']
        waypoint = Waypoint(
            document_id=51251,
            waypoint_type='summit', elevation=2000,
            geometry=DocumentGeometry(
                geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(
                    culture='fr', title='Mont Granier',
                    description='...',
                    summary='Le Mont [b]Granier[/b]')
            ])

        t = transaction.begin()
        sync_search_index(waypoint)
        t.commit()

        doc = SearchDocument.get(id=51251, index=index)
        self.assertEqual(doc['title_fr'], 'Mont Granier')
        self.assertEqual(doc['summary_fr'], 'Le Mont  Granier ')
예제 #21
0
    def put_success_all(self, request_body, document):
        """Test updating a document with changes to the figures and locales.
        """
        response = self.app.put_json(
            self._prefix + '/' + str(document.document_id), request_body,
            status=403)

        headers = self.add_authorization_header(username='******')
        response = self.app.put_json(
            self._prefix + '/' + str(document.document_id), request_body,
            headers=headers, status=200)

        body = response.json
        document_id = body.get('document_id')
        self.assertNotEquals(
            body.get('version'), document.version)
        self.assertEquals(body.get('document_id'), document_id)

        # check that the document was updated correctly
        self.session.expire_all()
        document = self.session.query(self._model).get(document_id)
        self.assertEquals(len(document.locales), 2)
        locale_en = document.get_locale('en')

        # check that a new archive_document was created
        archive_count = self.session.query(self._model_archive). \
            filter(
                getattr(self._model_archive, 'document_id') == document_id). \
            count()
        self.assertEqual(archive_count, 2)

        # check that only one new archive_document_locale was created (only
        # for 'en' not 'fr')
        archive_locale_count = \
            self.session.query(self._model_archive_locale). \
            filter(
                document_id == getattr(
                    self._model_archive_locale, 'document_id')
            ). \
            count()
        self.assertEqual(archive_locale_count, 3)

        # check that new versions were created
        versions = document.versions
        self.assertEqual(len(versions), 4)

        # version with culture 'en'
        version_en = versions[2]

        self.assertEqual(version_en.culture, 'en')

        meta_data_en = version_en.history_metadata
        self.assertEqual(meta_data_en.comment, 'Update')
        self.assertIsNotNone(meta_data_en.written_at)

        archive_document_en = version_en.document_archive
        self.assertEqual(archive_document_en.document_id, document_id)
        self.assertEqual(
            archive_document_en.version, document.version)

        archive_locale = version_en.document_locales_archive
        self.assertEqual(archive_locale.document_id, document_id)
        self.assertEqual(archive_locale.version, locale_en.version)
        self.assertEqual(archive_locale.culture, 'en')

        # version with culture 'fr'
        version_fr = versions[3]

        self.assertEqual(version_fr.culture, 'fr')

        meta_data_fr = version_fr.history_metadata
        self.assertIs(meta_data_en, meta_data_fr)

        archive_document_fr = version_fr.document_archive
        self.assertIs(archive_document_en, archive_document_fr)

        archive_locale_fr = version_fr.document_locales_archive
        self.assertEqual(archive_locale_fr.document_id, document_id)
        self.assertEqual(
            archive_locale_fr.version, self.locale_fr.version)
        self.assertEqual(archive_locale_fr.culture, 'fr')

        # check updates to the search index
        search_doc = SearchDocument.get(
            id=document.document_id,
            index=elasticsearch_config['index'])

        self.assertEqual(search_doc['doc_type'], document.type)
        self.assertEqual(search_doc['title_en'], archive_locale.title)
        self.assertEqual(search_doc['title_fr'], archive_locale_fr.title)

        return (body, document)
예제 #22
0
 def to_search_document(document, index):
     return SearchDocument.to_search_document(document, index)
예제 #23
0
 def to_search_document(document, index):
     return SearchDocument.to_search_document(document, index)
예제 #24
0
 def to_search_document(document, index):
     return SearchDocument.to_search_document(
         document, index, include_areas=False)
예제 #25
0
    def put_success_new_lang(self, request_body, document):
        """Test updating a document by adding a new locale.
        """
        response = self.app.put_json(
            self._prefix + '/' + str(document.document_id), request_body,
            status=403)

        headers = self.add_authorization_header(username='******')
        response = self.app.put_json(
            self._prefix + '/' + str(document.document_id), request_body,
            headers=headers, status=200)

        headers = self.add_authorization_header(username='******')
        body = response.json
        document_id = body.get('document_id')
        # document version does not change!
        self.assertEquals(body.get('version'), document.version)
        self.assertEquals(body.get('document_id'), document_id)

        # check that the document was updated correctly
        self.session.expire_all()
        document = self.session.query(self._model).get(document_id)
        self.assertEquals(len(document.locales), 3)

        # check that no new archive_document was created
        archive_count = self.session.query(self._model_archive). \
            filter(
                getattr(self._model_archive, 'document_id') == document_id). \
            count()
        self.assertEqual(archive_count, 1)

        # check that one new archive_document_locale was created
        archive_locale_count = \
            self.session.query(self._model_archive_locale). \
            filter(
                document_id == getattr(
                    self._model_archive_locale, 'document_id')
            ). \
            count()
        self.assertEqual(archive_locale_count, 3)

        # check that one new version was created
        versions = document.versions
        self.assertEqual(len(versions), 3)

        # version with culture 'en'
        version_en = versions[0]

        self.assertEqual(version_en.culture, 'en')

        meta_data_en = version_en.history_metadata

        # version with culture 'fr'
        version_fr = versions[1]

        self.assertEqual(version_fr.culture, 'fr')

        meta_data_fr = version_fr.history_metadata
        self.assertIs(meta_data_en, meta_data_fr)

        archive_document_en = version_en.document_archive
        archive_document_fr = version_fr.document_archive
        self.assertIs(archive_document_en, archive_document_fr)

        # version with culture 'es'
        version_es = versions[2]

        self.assertEqual(version_es.culture, 'es')

        meta_data_es = version_es.history_metadata
        self.assertIsNot(meta_data_en, meta_data_es)

        archive_document_es = version_es.document_archive
        self.assertIs(archive_document_es, archive_document_fr)

        # check updates to the search index
        search_doc = SearchDocument.get(
            id=document.document_id,
            index=elasticsearch_config['index'])

        self.assertEqual(search_doc['doc_type'], document.type)
        self.assertEqual(
            search_doc['title_en'], document.get_locale('en').title)
        self.assertEqual(
            search_doc['title_fr'], document.get_locale('fr').title)
        self.assertEqual(
            search_doc['title_es'], document.get_locale('es').title)

        return (body, document)
예제 #26
0
 def to_search_document(document, index):
     return SearchDocument.to_search_document(document,
                                              index,
                                              include_areas=False)