Example #1
0
    def _add_test_data(self):
        self.map1 = TopoMap(editor='IGN', scale='25000', code='3431OT')

        self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy')
        self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy')

        self.map1.locales.append(self.locale_en)
        self.map1.locales.append(self.locale_fr)

        self.map1.geometry = DocumentGeometry(
            geom_detail='SRID=3857;POINT(635956 5723604)')

        self.session.add(self.map1)
        self.session.flush()

        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.map1, user_id)

        self.map2 = TopoMap(
            editor='IGN', scale='25000', code='3432OT')
        self.session.add(self.map2)
        self.map3 = TopoMap(
            editor='IGN', scale='25000', code='3433OT')
        self.session.add(self.map3)
        self.map4 = TopoMap(
            editor='IGN', scale='25000', code='3434OT')
        self.map4.locales.append(DocumentLocale(
            lang='en', title='Lac d\'Annecy'))
        self.map4.locales.append(DocumentLocale(
            lang='fr', title='Lac d\'Annecy'))
        self.session.add(self.map4)
        self.session.flush()
Example #2
0
    def _add_test_data(self):
        self.map1 = TopoMap(editor='IGN', scale='25000', code='3431OT')

        self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy')
        self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy')

        self.map1.locales.append(self.locale_en)
        self.map1.locales.append(self.locale_fr)

        self.map1.geometry = DocumentGeometry(
            geom_detail='SRID=3857;POINT(635956 5723604)')

        self.session.add(self.map1)
        self.session.flush()

        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.map1, user_id)

        self.map2 = TopoMap(editor='IGN', scale='25000', code='3432OT')
        self.session.add(self.map2)
        self.map3 = TopoMap(editor='IGN', scale='25000', code='3433OT')
        self.session.add(self.map3)
        self.map4 = TopoMap(editor='IGN', scale='25000', code='3434OT')
        self.map4.locales.append(
            DocumentLocale(lang='en', title='Lac d\'Annecy'))
        self.map4.locales.append(
            DocumentLocale(lang='fr', title='Lac d\'Annecy'))
        self.session.add(self.map4)
        self.session.flush()
Example #3
0
    def test_process_task(self):
        """Tests that the syncer listens to messages and sends changes to
        ElasticSearch.
        """
        waypoint = Waypoint(
            document_id=51251,
            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]')
            ])
        self.session.add(waypoint)
        self.session.flush()
        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(waypoint, user_id)
        self.session.flush()

        t = transaction.begin()
        notify_es_syncer(self.queue_config)
        t.commit()

        syncer = SyncWorker(
            self.queue_config.connection, self.queue_config.queue, 1000,
            session=self.session)
        next(syncer.consume(limit=1))

        index = elasticsearch_config['index']
        doc = SearchWaypoint.get(id=51251, index=index)
        self.assertEqual(doc['title_fr'], 'Mont Granier')
        # self.assertEqual(doc['summary_fr'], 'Le Mont  Granier ')
        self.assertEqual(doc['doc_type'], 'w')
Example #4
0
    def post(self):
        """ Mark the given document as editable.

        Request:
            `POST` `/documents/unprotect`

        Request body:
            {'document_id': @document_id@}

        """
        document_id = self.request.validated['document_id']
        document = _get_document(document_id)

        # Do nothing if document is already not protected.
        if not document.protected:
            return {}

        document.protected = False

        user_id = self.request.authenticated_userid
        DocumentRest.update_version(document, user_id, 'Unprotected document',
                                    [UpdateType.FIGURES], [])

        update_cache_version_direct(document_id)

        return {}
Example #5
0
    def test_update_cache_version_user_document_version(self):
        """ Test that a document is invalidated if a user name of a user that
         edited one of the document versions is changed.
        """
        waypoint = Waypoint(waypoint_type='summit',
                            elevation=2203,
                            locales=[
                                WaypointLocale(lang='en',
                                               title='...',
                                               description='...')
                            ])

        user_profile = UserProfile()
        user = User(name='test_user',
                    username='******',
                    email='*****@*****.**',
                    forum_username='******',
                    password='******',
                    email_validated=True,
                    profile=user_profile)
        self.session.add_all([waypoint, user_profile, user])
        self.session.flush()

        DocumentRest.create_new_version(waypoint, user.id)

        update_cache_version(user_profile)
        cache_version_user_profile = self.session.query(CacheVersion).get(
            user_profile.document_id)
        cache_version_waypoint = self.session.query(CacheVersion).get(
            waypoint.document_id)

        self.assertEqual(cache_version_waypoint.version, 2)
        self.assertEqual(cache_version_user_profile.version, 2)
Example #6
0
    def post(self):
        user = schema_create_user.objectify(self.request.validated)
        user.password = self.request.validated['password']
        user.update_validation_nonce(
                Purpose.registration,
                VALIDATION_EXPIRE_DAYS)

        # directly create the user profile, the document id of the profile
        # is the user id
        lang = user.lang
        user.profile = UserProfile(
            categories=['amateur'],
            locales=[DocumentLocale(lang=lang, title='')]
        )

        DBSession.add(user)
        try:
            DBSession.flush()
        except:
            log.warning('Error persisting user', exc_info=True)
            raise HTTPInternalServerError('Error persisting user')

        # also create a version for the profile
        DocumentRest.create_new_version(user.profile, user.id)

        # The user needs validation
        email_service = get_email_service(self.request)
        nonce = user.validation_nonce
        settings = self.request.registry.settings
        link = settings['mail.validate_register_url_template'] % nonce
        email_service.send_registration_confirmation(user, link)

        return to_json_dict(user, schema_user)
Example #7
0
    def test_process_task(self):
        """Tests that the syncer listens to messages and sends changes to
        ElasticSearch.
        """
        waypoint = Waypoint(
            document_id=51251,
            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]')
            ])
        self.session.add(waypoint)
        self.session.flush()
        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(waypoint, user_id)
        self.session.flush()

        t = transaction.begin()
        notify_es_syncer(self.queue_config)
        t.commit()

        syncer = SyncWorker(
            self.queue_config.connection, self.queue_config.queue,
            session=self.session)
        next(syncer.consume(limit=1))

        index = elasticsearch_config['index']
        doc = SearchWaypoint.get(id=51251, index=index)
        self.assertEqual(doc['title_fr'], 'Mont Granier')
        self.assertEqual(doc['summary_fr'], 'Le Mont  Granier ')
        self.assertEqual(doc['doc_type'], 'w')
Example #8
0
    def test_update_cache_version_user_document_version(self):
        """ Test that a document is invalidated if a user name of a user that
         edited one of the document versions is changed.
        """
        waypoint = Waypoint(
            waypoint_type='summit', elevation=2203, locales=[
                WaypointLocale(lang='en', title='...', description='...')])

        user_profile = UserProfile()
        user = User(
            name='test_user',
            username='******', email='*****@*****.**',
            forum_username='******', password='******',
            email_validated=True, profile=user_profile)
        self.session.add_all([waypoint, user_profile, user])
        self.session.flush()

        DocumentRest.create_new_version(waypoint, user.id)

        update_cache_version(user_profile)
        cache_version_user_profile = self.session.query(CacheVersion).get(
            user_profile.document_id)
        cache_version_waypoint = self.session.query(CacheVersion).get(
            waypoint.document_id)

        self.assertEqual(cache_version_waypoint.version, 2)
        self.assertEqual(cache_version_user_profile.version, 2)
Example #9
0
    def setUp(self):  # noqa
        super(BaseProtectTest, self).setUp()
        contributor_id = self.global_userids['contributor']

        self.waypoint = Waypoint(waypoint_type='summit', elevation=2203)

        self.locale = WaypointLocale(lang='en',
                                     title='Mont Granier',
                                     description='...')
        self.waypoint.locales.append(self.locale)

        self.waypoint.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')
        self.session.add(self.waypoint)
        self.session.flush()

        DocumentRest.create_new_version(self.waypoint, contributor_id)

        self.waypoint2 = Waypoint(protected=True,
                                  waypoint_type='summit',
                                  elevation=2203)

        self.locale2 = WaypointLocale(lang='en',
                                      title='Mont Granier2',
                                      description='...')
        self.waypoint2.locales.append(self.locale2)

        self.waypoint2.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')
        self.session.add(self.waypoint2)
        self.session.flush()

        DocumentRest.create_new_version(self.waypoint2, contributor_id)

        self.session.flush()
Example #10
0
    def post(self):
        user = schema_create_user.objectify(self.request.validated)
        user.password = self.request.validated['password']
        user.update_validation_nonce(Purpose.registration,
                                     VALIDATION_EXPIRE_DAYS)

        # directly create the user profile, the document id of the profile
        # is the user id
        lang = user.lang
        user.profile = UserProfile(
            categories=['amateur'],
            locales=[DocumentLocale(lang=lang, title='')])

        DBSession.add(user)
        try:
            DBSession.flush()
        except:
            log.warning('Error persisting user', exc_info=True)
            raise HTTPInternalServerError('Error persisting user')

        # also create a version for the profile
        DocumentRest.create_new_version(user.profile, user.id)

        # The user needs validation
        email_service = get_email_service(self.request)
        nonce = user.validation_nonce
        settings = self.request.registry.settings
        link = settings['mail.validate_register_url_template'] % nonce
        email_service.send_registration_confirmation(user, link)

        return to_json_dict(user, schema_user)
Example #11
0
    def _add_test_data(self):
        self.article1 = Article(categories=['site_info'],
                                activities=['hiking'],
                                article_type='collab')
        self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy')
        self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy')

        self.article1.locales.append(self.locale_en)
        self.article1.locales.append(self.locale_fr)

        self.session.add(self.article1)
        self.session.flush()

        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.article1, user_id)
        self.article1_version = self.session.query(DocumentVersion). \
            filter(DocumentVersion.document_id == self.article1.document_id). \
            filter(DocumentVersion.lang == 'en').first()

        self.article2 = Article(categories=['site_info'],
                                activities=['hiking'],
                                article_type='collab')
        self.session.add(self.article2)
        self.article3 = Article(categories=['site_info'],
                                activities=['hiking'],
                                article_type='collab')
        self.session.add(self.article3)
        self.article4 = Article(categories=['site_info'],
                                activities=['hiking'],
                                article_type='personal')
        self.article4.locales.append(
            DocumentLocale(lang='en', title='Lac d\'Annecy'))
        self.article4.locales.append(
            DocumentLocale(lang='fr', title='Lac d\'Annecy'))
        self.session.add(self.article4)
        self.session.flush()

        DocumentRest.create_new_version(self.article4, user_id)
        self.article4_version = self.session.query(DocumentVersion). \
            filter(DocumentVersion.document_id == self.article4.document_id). \
            filter(DocumentVersion.lang == 'en').first()

        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.session.add(
            Association.create(parent_document=self.article1,
                               child_document=self.article4))
        self.session.add(
            Association.create(parent_document=self.article3,
                               child_document=self.article1))
        self.session.flush()
Example #12
0
    def post(self):
        """ Merges a document into another document.

        - Associations and tags of the source document are transferred to
          the target document.
        - The association log entries are rewritten to the target document.
        - The time of the log entries is updated, so that the ES syncer will
          pick up the new associations of the target document.
        - The attribute `redirects_to` of the source document is set.
        - A new version is created for the source document. This makes sure
          that the ES syncer removes the document from ES index.
        - Update the cache version of the source document.
        - Update the cache version of the target document and its associations.
        - Removes the feed entries of the source document.


        Request:
            `POST` `/documents/merge`

        Request body:
            {
                'source_document_id': @document_id@,
                'target_document_id': @document_id@
            }

        """
        source_document_id = self.request.validated['source_document_id']
        target_document_id = self.request.validated['target_document_id']
        source_doc = DBSession.query(Document).get(source_document_id)

        # transfer associations from source to target
        transfer_associations(source_document_id, target_document_id)

        # transfer tags from source to target
        transfer_tags(source_document_id, target_document_id)

        # if waypoint, update main waypoint of routes
        if source_doc.type == WAYPOINT_TYPE:
            _transfer_main_waypoint(source_document_id, target_document_id)

        # set redirection and create a new version
        source_doc.redirects_to = target_document_id
        DocumentRest.update_version(
            source_doc, self.request.authenticated_userid,
            'merged with {}'.format(target_document_id), [UpdateType.FIGURES],
            [])

        # update the cache version for the source and target document
        update_cache_version_direct(source_document_id)
        update_cache_version_full(target_document_id, source_doc.type)

        _remove_feed_entry(source_document_id)

        if source_doc.type == IMAGE_TYPE:
            delete_all_files_for_image(source_document_id, self.request)

        notify_es_syncer(self.request.registry.queue_config)

        return {}
Example #13
0
    def _add_test_data(self):
        self.map1 = TopoMap(editor='IGN', scale='25000', code='3431OT')

        self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy')
        self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy')

        self.map1.locales.append(self.locale_en)
        self.map1.locales.append(self.locale_fr)

        self.map1.geometry = DocumentGeometry(
            geom_detail='SRID=3857;POINT(635956 5723604)')

        self.session.add(self.map1)
        self.session.flush()

        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.map1, user_id)

        self.map2 = TopoMap(
            editor='IGN', scale='25000', code='3432OT')
        self.session.add(self.map2)
        self.map3 = TopoMap(
            editor='IGN', scale='25000', code='3433OT')
        self.session.add(self.map3)
        self.map4 = TopoMap(
            editor='IGN', scale='25000', code='3434OT')
        self.map4.locales.append(DocumentLocale(
            lang='en', title='Lac d\'Annecy'))
        self.map4.locales.append(DocumentLocale(
            lang='fr', title='Lac d\'Annecy'))
        self.session.add(self.map4)
        self.session.flush()

        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(TopoMapAssociation(
            document=self.waypoint2, topo_map=self.map1))
        self.session.flush()
Example #14
0
    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.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.session.flush()
Example #15
0
    def _add_test_data(self):
        self.image = Image(
            activities=['paragliding'], height=1500,
            image_type='collaborative')

        self.locale_en = DocumentLocale(
            lang='en', title='Mont Blanc from the air', description='...')

        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()

        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.image, user_id)

        self.image2 = Image(
            activities=['paragliding'], height=1500)
        self.session.add(self.image2)
        self.image3 = Image(
            activities=['paragliding'], height=1500)
        self.session.add(self.image3)
        self.image4 = Image(
            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.image4, user_id)

        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()
Example #16
0
    def test_delete_former_main_waypoint(self):
        """ Test that a former main waypoint can be deleted.
        """
        self.route3.main_waypoint_id = self.waypoint3.document_id
        self.session.flush()
        DocumentRest.update_version(self.route3,
                                    self.global_userids['contributor'],
                                    'Update', [UpdateType.FIGURES], [])

        self.route3.main_waypoint_id = self.waypoint1.document_id
        self.session.flush()
        DocumentRest.update_version(self.route3,
                                    self.global_userids['contributor'],
                                    'Update', [UpdateType.FIGURES], [])

        self._delete(self.waypoint3.document_id, 200)
Example #17
0
    def _add_test_data(self):
        self.map1 = TopoMap(editor='IGN', scale='25000', code='3431OT')

        self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy')
        self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy')

        self.map1.locales.append(self.locale_en)
        self.map1.locales.append(self.locale_fr)

        self.map1.geometry = DocumentGeometry(
            geom_detail='SRID=3857;POLYGON((611774 5706934,611774 5744215,'
            '642834 5744215,642834 5706934,611774 5706934))')

        self.session.add(self.map1)
        self.session.flush()

        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.map1, user_id)

        self.map2 = TopoMap(editor='IGN', scale='25000', code='3432OT')
        self.session.add(self.map2)
        self.map3 = TopoMap(editor='IGN', scale='25000', code='3433OT')
        self.session.add(self.map3)
        self.map4 = TopoMap(editor='IGN', scale='25000', code='3434OT')
        self.map4.locales.append(
            DocumentLocale(lang='en', title='Lac d\'Annecy'))
        self.map4.locales.append(
            DocumentLocale(lang='fr', title='Lac d\'Annecy'))
        self.session.add(self.map4)
        self.session.flush()

        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(
            TopoMapAssociation(document=self.waypoint2, topo_map=self.map1))
        self.session.flush()
Example #18
0
    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.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.session.flush()
    def _add_test_data(self):
        user_id = self.global_userids['contributor']
        self.profile1 = self.session.query(UserProfile).get(user_id)
        self.locale_en = self.profile1.get_locale('en')
        self.locale_fr = self.profile1.get_locale('fr')
        DocumentRest.create_new_version(self.profile1, user_id)

        self.profile2 = UserProfile(categories=['amateur'])
        self.session.add(self.profile2)
        self.profile3 = UserProfile(categories=['amateur'])
        self.session.add(self.profile3)
        self.profile4 = UserProfile(categories=['amateur'])
        self.profile4.locales.append(
            DocumentLocale(lang='en', description='You', title=''))
        self.profile4.locales.append(
            DocumentLocale(lang='fr', description='Toi', title=''))
        self.session.add(self.profile4)

        self.session.flush()

        # create users for the profiles
        self.user2 = User(name='user2',
                          username='******',
                          email='*****@*****.**',
                          forum_username='******',
                          password='******',
                          email_validated=True,
                          profile=self.profile2)
        self.user3 = User(name='user3',
                          username='******',
                          email='*****@*****.**',
                          forum_username='******',
                          password='******',
                          email_validated=False,
                          profile=self.profile3)
        self.user4 = User(name='user4',
                          username='******',
                          email='*****@*****.**',
                          forum_username='******',
                          password='******',
                          email_validated=True,
                          profile=self.profile4)
        self.session.add_all([self.user2, self.user3, self.user4])

        self.session.flush()
Example #20
0
    def post(self):
        """ Create a new version of the document based upon an old one.

        Request:
            `POST` `/documents/revert`

        Request body:
            {
                'document_id': @document_id@,
                'lang': @lang@,
                'version_id': @version_id@
            }

        """
        document_id = self.request.validated['document_id']
        lang = self.request.validated['lang']
        version_id = self.request.validated['version_id']

        clazz, locale_clazz, archive_clazz, \
            archive_locale_clazz, document_type = self._get_models(document_id)

        document = self._get_current_document(document_id, lang, clazz,
                                              locale_clazz)
        document_in = self._get_archive_document(document_id, lang, version_id,
                                                 archive_clazz,
                                                 archive_locale_clazz)

        # 'before_update' callbacks as in _put() are generally not required
        # when reverting, except maybe if associated WP/routes have changed.
        before_update = None
        after_update = self._get_after_update(document_type)

        def manage_versions(document, old_versions):
            # After the target document object has been updated,
            # set the versions back to the versions of the current document
            # because we are basing our changes on the lastest version.
            document.version = old_versions['document']
            document.locales[0].version = old_versions['locales'][lang]
            if document.geometry:
                document.geometry.version = old_versions['geometry']

        self.request.validated['message'] = 'Revert to version {}'.format(
            version_id)

        update_types = DocumentRest.update_document(document, document_in,
                                                    self.request,
                                                    before_update,
                                                    after_update,
                                                    manage_versions)

        if not update_types:
            raise HTTPBadRequest(
                'No change to apply when reverting to this version')

        return {}
Example #21
0
    def _add_test_data(self):
        user_id = self.global_userids['contributor']
        self.profile1 = self.session.query(UserProfile).get(user_id)
        self.locale_en = self.profile1.get_locale('en')
        self.locale_fr = self.profile1.get_locale('fr')
        DocumentRest.create_new_version(self.profile1, user_id)

        self.profile2 = UserProfile(categories=['amateur'])
        self.session.add(self.profile2)
        self.profile3 = UserProfile(categories=['amateur'])
        self.session.add(self.profile3)
        self.profile4 = UserProfile(categories=['amateur'])
        self.profile4.locales.append(DocumentLocale(
            lang='en', description='You', title=''))
        self.profile4.locales.append(DocumentLocale(
            lang='fr', description='Toi', title=''))
        self.session.add(self.profile4)

        self.session.flush()

        # create users for the profiles
        self.user2 = User(
            name='user2', username='******', email='*****@*****.**',
            forum_username='******', password='******',
            email_validated=True, profile=self.profile2)
        self.user3 = User(
            name='user3', username='******', email='*****@*****.**',
            forum_username='******', password='******',
            email_validated=False, profile=self.profile3)
        self.user4 = User(
            name='user4', username='******', email='*****@*****.**',
            forum_username='******', password='******',
            email_validated=True, profile=self.profile4)
        self.session.add_all([self.user2, self.user3, self.user4])

        self.session.flush()
Example #22
0
    def _add_test_data(self):
        self.image = Image(activities='paragliding', height=2000)

        self.locale_en = ImageLocale(culture='en',
                                     title='Mont Blanc from the air',
                                     description='...')

        self.locale_fr = ImageLocale(culture='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()

        DocumentRest(None)._create_new_version(self.image)
Example #23
0
    def _add_test_data(self):
        self.route = Route(
            activities='paragliding', height=2000)

        self.locale_en = RouteLocale(
            culture='en', title='Mont Blanc from the air', description='...',
            gear='paraglider')

        self.locale_fr = RouteLocale(
            culture='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='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)')

        self.session.add(self.route)
        self.session.flush()

        DocumentRest(None)._create_new_version(self.route)
Example #24
0
    def _add_test_data(self):
        self.waypoint = Waypoint(
            waypoint_type='summit', elevation=2203)

        self.locale_en = WaypointLocale(
            culture='en', title='Mont Granier', description='...',
            pedestrian_access='yep')

        self.locale_fr = WaypointLocale(
            culture='fr', title='Mont Granier', description='...',
            pedestrian_access='ouai')

        self.waypoint.locales.append(self.locale_en)
        self.waypoint.locales.append(self.locale_fr)

        self.waypoint.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')

        self.session.add(self.waypoint)
        self.session.flush()

        DocumentRest(None)._create_new_version(self.waypoint)
Example #25
0
    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.session.add(Association.create(
        #     parent_document=self.book1,
        #     child_document=self.image2))
        self.session.add(
            Association.create(parent_document=self.book1,
                               child_document=self.route3))
        self.session.add(
            Association.create(parent_document=self.book2,
                               child_document=self.waypoint2))
        self.session.flush()
Example #26
0
    def _add_test_data(self):
        self.waypoint = Waypoint(
            waypoint_type='summit', elevation=2203)

        self.locale_en = WaypointLocale(
            lang='en', title='Mont Granier', description='...',
            access='yep')

        self.locale_fr = WaypointLocale(
            lang='fr', title='Mont Granier', description='...',
            access='ouai')

        self.waypoint.locales.append(self.locale_en)
        self.waypoint.locales.append(self.locale_fr)

        self.waypoint.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')
        self.session.add(self.waypoint)
        self.session.flush()
        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.waypoint, user_id)
        self.waypoint_version = self.session.query(DocumentVersion). \
            filter(DocumentVersion.document_id == self.waypoint.document_id). \
            filter(DocumentVersion.lang == 'en').first()

        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.waypoint3 = Waypoint(
            waypoint_type='summit', elevation=3,
            geometry=DocumentGeometry(
                geom='SRID=3857;POINT(635956 5723604)'))
        self.session.add(self.waypoint3)
        self.waypoint4 = Waypoint(
            waypoint_type='summit', elevation=4,
            protected=True,
            geometry=DocumentGeometry(
                geom='SRID=3857;POINT(659775 5694854)'))
        self.waypoint4.locales.append(WaypointLocale(
            lang='en', title='Mont Granier', description='...',
            access='yep'))
        self.waypoint4.locales.append(WaypointLocale(
            lang='fr', title='Mont Granier', description='...',
            access='ouai'))
        self.session.add(self.waypoint4)
        self.waypoint5 = Waypoint(
            waypoint_type='summit', elevation=3,
            redirects_to=self.waypoint.document_id,
            geometry=DocumentGeometry(
                geom='SRID=3857;POINT(635956 5723604)'))
        self.waypoint5.locales.append(WaypointLocale(
            lang='en', title='Mont Granier', description='...',
            access='yep'))
        self.session.add(self.waypoint5)
        self.session.flush()
        DocumentRest.create_new_version(
            self.waypoint4, self.global_userids['contributor'])
        DocumentRest.create_new_version(
            self.waypoint5, self.global_userids['contributor'])

        # add some associations
        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.waypoint.document_id
        )
        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()
        self.route2 = Route(
            redirects_to=self.route1.document_id,
            activities=['skitouring'], elevation_max=1500, elevation_min=700,
            height_diff_up=800, height_diff_down=800, durations='1',
            main_waypoint_id=self.waypoint.document_id
        )
        self.route3 = Route(
            activities=['skitouring'], elevation_max=1500, elevation_min=700,
            height_diff_up=800, height_diff_down=800, durations='1'
        )
        self.route3.locales.append(RouteLocale(
            lang='en', title='Mont Blanc from the air', description='...',
            title_prefix='Mont Blanc :', gear='paraglider'))
        self.session.add(self.route2)
        self.session.add(self.route3)
        self.session.flush()
        self.session.add(Association(
            parent_document_id=self.waypoint.document_id,
            child_document_id=self.waypoint4.document_id))
        self.session.add(Association(
            parent_document_id=self.waypoint.document_id,
            child_document_id=self.waypoint5.document_id))
        self.session.add(Association(
            parent_document_id=self.waypoint.document_id,
            child_document_id=self.route1.document_id))
        self.session.add(Association(
            parent_document_id=self.waypoint.document_id,
            child_document_id=self.route2.document_id))
        self.session.add(Association(
            parent_document_id=self.waypoint4.document_id,
            child_document_id=self.route3.document_id))

        self.outing1 = Outing(
            activities=['skitouring'], date_start=datetime.date(2016, 1, 1),
            date_end=datetime.date(2016, 1, 3),
            locales=[
                OutingLocale(
                    lang='en', title='...', description='...',
                    weather='sunny')
            ]
        )
        self.session.add(self.outing1)
        self.session.flush()
        self.session.add(Association(
            parent_document_id=self.route1.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.outing3 = Outing(
            activities=['skitouring'], date_start=datetime.date(2015, 12, 31),
            date_end=datetime.date(2016, 1, 1),
            locales=[
                OutingLocale(
                    lang='en', title='...', description='...',
                    weather='sunny')
            ]
        )
        self.session.add(self.outing2)
        self.session.add(self.outing3)
        self.session.flush()
        self.session.add(Association(
            parent_document_id=self.route1.document_id,
            child_document_id=self.outing2.document_id))
        self.session.add(Association(
            parent_document_id=self.route3.document_id,
            child_document_id=self.outing3.document_id))

        # add a map
        topo_map = 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(topo_map)
        self.session.flush()
        self.session.add(TopoMap(
            redirects_to=topo_map.document_id,
            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
        ))

        # add areas
        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.area2 = Area(
            area_type='range',
            locales=[
                DocumentLocale(lang='fr', title='France')
            ]
        )

        self.session.add_all([self.area1, self.area2])
        self.session.add(AreaAssociation(
            document=self.waypoint, area=self.area2))
        self.session.flush()
Example #27
0
    def _add_test_data(self):
        user_id = self.global_userids['contributor']

        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._add_association(
            Association.create(parent_document=self.article1,
                               child_document=self.image), user_id)

        self.book1 = Book(activities=['hiking'], book_types=['biography'])
        self.session.add(self.book1)
        self.session.flush()
        self._add_association(
            Association.create(parent_document=self.book1,
                               child_document=self.image), user_id)

        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._add_association(
            Association.create(parent_document=self.image,
                               child_document=self.image2), user_id)

        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._add_association(Association.create(self.area, self.image),
                              user_id)
        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._add_association(
            Association.create(parent_document=self.outing1,
                               child_document=self.image), user_id)
        self._add_association(
            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), user_id)
        update_feed_document_create(self.outing1, user_id)
        self.session.flush()
Example #28
0
    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()
Example #29
0
    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',
            document_topic=DocumentTopic(topic_id=1))

        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.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.route,
            child_document=self.article1))

        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.route))

        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',
            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.route3.geometry = DocumentGeometry(geom='SRID=3857;POINT(0 0)')
        self.session.add(self.route3)
        self.session.flush()
        DocumentRest.create_new_version(self.route3, user_id)

        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 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.create(
            parent_document=self.route,
            child_document=self.route4))
        self.session.add(Association.create(
            parent_document=self.route4,
            child_document=self.route))
        self.session.add(Association.create(
            parent_document=self.waypoint,
            child_document=self.route))

        # add a map
        topo_map = 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
        )
        self.session.add(topo_map)
        self.session.flush()
        self.session.add(TopoMapAssociation(
            document=self.route, topo_map=topo_map))

        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.route,
            child_document=self.outing1))

        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.create(
            parent_document=self.route,
            child_document=self.outing2))
        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()
Example #30
0
    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.session.add(Association.create(
        #     parent_document=self.book1,
        #     child_document=self.image2))
        self.session.add(Association.create(
            parent_document=self.book1,
            child_document=self.route3))
        self.session.add(Association.create(
            parent_document=self.book2,
            child_document=self.waypoint2))
        self.session.flush()
Example #31
0
    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(
            activities=['hiking'],
            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()
Example #32
0
    def _add_test_data(self):
        self.waypoint = Waypoint(waypoint_type='summit', elevation=2203)

        self.locale_en = WaypointLocale(lang='en',
                                        title='Mont Granier',
                                        description='...',
                                        access='yep')

        self.locale_fr = WaypointLocale(lang='fr',
                                        title='Mont Granier',
                                        description='...',
                                        access='ouai')

        self.waypoint.locales.append(self.locale_en)
        self.waypoint.locales.append(self.locale_fr)

        self.waypoint.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')
        self.session.add(self.waypoint)
        self.session.flush()
        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.waypoint, user_id)
        self.waypoint_version = self.session.query(DocumentVersion). \
            filter(DocumentVersion.document_id == self.waypoint.document_id). \
            filter(DocumentVersion.lang == 'en').first()

        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.waypoint3 = Waypoint(
            waypoint_type='summit',
            elevation=3,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'))
        self.session.add(self.waypoint3)
        self.waypoint4 = Waypoint(
            waypoint_type='summit',
            elevation=4,
            protected=True,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(659775 5694854)'))
        self.waypoint4.locales.append(
            WaypointLocale(lang='en',
                           title='Mont Granier',
                           description='...',
                           access='yep'))
        self.waypoint4.locales.append(
            WaypointLocale(lang='fr',
                           title='Mont Granier',
                           description='...',
                           access='ouai'))
        self.session.add(self.waypoint4)
        self.waypoint5 = Waypoint(
            waypoint_type='summit',
            elevation=3,
            redirects_to=self.waypoint.document_id,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'))
        self.waypoint5.locales.append(
            WaypointLocale(lang='en',
                           title='Mont Granier',
                           description='...',
                           access='yep'))
        self.session.add(self.waypoint5)
        self.session.flush()
        DocumentRest.create_new_version(self.waypoint4,
                                        self.global_userids['contributor'])
        DocumentRest.create_new_version(self.waypoint5,
                                        self.global_userids['contributor'])

        # add some associations
        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.waypoint.document_id)
        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()
        self.route2 = Route(redirects_to=self.route1.document_id,
                            activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=800,
                            height_diff_down=800,
                            durations='1',
                            main_waypoint_id=self.waypoint.document_id)
        self.route3 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=800,
                            height_diff_down=800,
                            durations='1')
        self.route3.locales.append(
            RouteLocale(lang='en',
                        title='Mont Blanc from the air',
                        description='...',
                        title_prefix='Mont Blanc :',
                        gear='paraglider'))
        self.session.add(self.route2)
        self.session.add(self.route3)
        self.session.flush()
        self.session.add(
            Association(parent_document_id=self.waypoint.document_id,
                        child_document_id=self.waypoint4.document_id))
        self.session.add(
            Association(parent_document_id=self.waypoint.document_id,
                        child_document_id=self.waypoint5.document_id))
        self.session.add(
            Association(parent_document_id=self.waypoint.document_id,
                        child_document_id=self.route1.document_id))
        self.session.add(
            Association(parent_document_id=self.waypoint.document_id,
                        child_document_id=self.route2.document_id))
        self.session.add(
            Association(parent_document_id=self.waypoint4.document_id,
                        child_document_id=self.route3.document_id))

        self.outing1 = Outing(activities=['skitouring'],
                              date_start=datetime.date(2016, 1, 1),
                              date_end=datetime.date(2016, 1, 3),
                              locales=[
                                  OutingLocale(lang='en',
                                               title='...',
                                               description='...',
                                               weather='sunny')
                              ])
        self.session.add(self.outing1)
        self.session.flush()
        self.session.add(
            Association(parent_document_id=self.route1.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.outing3 = Outing(activities=['skitouring'],
                              date_start=datetime.date(2015, 12, 31),
                              date_end=datetime.date(2016, 1, 1),
                              locales=[
                                  OutingLocale(lang='en',
                                               title='...',
                                               description='...',
                                               weather='sunny')
                              ])
        self.session.add(self.outing2)
        self.session.add(self.outing3)
        self.session.flush()
        self.session.add(
            Association(parent_document_id=self.route1.document_id,
                        child_document_id=self.outing2.document_id))
        self.session.add(
            Association(parent_document_id=self.route3.document_id,
                        child_document_id=self.outing3.document_id))

        # add a map
        topo_map = 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(topo_map)
        self.session.flush()
        self.session.add(
            TopoMap(
                redirects_to=topo_map.document_id,
                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
            ))

        # add areas
        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.area2 = Area(area_type='range',
                          locales=[DocumentLocale(lang='fr', title='France')])

        self.session.add_all([self.area1, self.area2])
        self.session.add(
            AreaAssociation(document=self.waypoint, area=self.area2))
        self.session.flush()
Example #33
0
    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._add_association(Association.create(self.area1, self.image),
                              user_id)
        self.session.flush()
Example #34
0
    def setUp(self):
        super(TestChangesDocumentRest, self).setUp()
        self._prefix = '/documents/changes'

        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.session.flush()
        DocumentRest.create_new_version(self.waypoint1, contributor_id)
        self.session.flush()

        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()
        DocumentRest.create_new_version(self.waypoint2, contributor_id)
        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.session.flush()
        DocumentRest.create_new_version(self.waypoint3, contributor_id)
        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.session.flush()
        DocumentRest.create_new_version(self.route1, contributor_id)
        self.session.flush()

        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.session.add(self.outing)
        self.session.flush()
        DocumentRest.create_new_version(self.outing, contributor_id)
        self.session.flush()

        self.profile2 = UserProfile(categories=['amateur'])
        self.session.add(self.profile2)
        self.session.flush()

        version_count = self.session.query(DocumentVersion).count()
        self.assertEqual(4, version_count)

        hist_meta_count = self.session.query(HistoryMetaData).count()
        self.assertEqual(5, hist_meta_count)
Example #35
0
    def test_put_add_geometry(self):
        """Tests adding a geometry to a waypoint without geometry.
        """
        # first create a waypoint with no geometry
        waypoint = Waypoint(waypoint_type='summit', elevation=3779)

        locale_en = WaypointLocale(lang='en', title='Mont Pourri', access='y')
        waypoint.locales.append(locale_en)

        self.session.add(waypoint)
        self.session.flush()
        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(waypoint, user_id)

        # then add a geometry to the waypoint
        body_put = {
            'message': 'Adding geom',
            'document': {
                'document_id': waypoint.document_id,
                'version': waypoint.version,
                'quality': quality_types[1],
                'geometry': {
                    'geom':
                    '{"type": "Point", "coordinates": [635956, 5723604]}'
                },
                'waypoint_type': 'summit',
                'elevation': 3779,
                'locales': []
            }
        }
        response = self.app_put_json(self._prefix + '/' +
                                     str(waypoint.document_id),
                                     body_put,
                                     status=403)

        headers = self.add_authorization_header(username='******')
        self.app_put_json(self._prefix + '/' + str(waypoint.document_id),
                          body_put,
                          headers=headers,
                          status=200)

        response = self.app.get(self._prefix + '/' + str(waypoint.document_id),
                                status=200)
        self.assertEqual(response.content_type, 'application/json')

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

        # check that no new archive_document was created
        self.session.expire_all()
        document = self.session.query(self._model).get(document_id)

        # 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, 1)

        # check that no 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, 1)

        # check that a new archive_document_geometry was created
        archive_locale_count = \
            self.session.query(ArchiveDocumentGeometry). \
            filter(document_id == ArchiveDocumentGeometry.document_id). \
            count()
        self.assertEqual(archive_locale_count, 1)

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

        # version with lang 'en'
        version_en = self.get_latest_version('en', versions)

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

        meta_data_en = version_en.history_metadata
        self.assertEqual(meta_data_en.comment, 'Adding geom')
        self.assertIsNotNone(meta_data_en.written_at)
Example #36
0
    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',
            document_topic=DocumentTopic(topic_id=1))

        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.article1 = Article(categories=['site_info'],
                                activities=['hiking'],
                                article_type='collab')
        self.session.add(self.article1)
        self.session.flush()
        self._add_association(Association.create(
            parent_document=self.route,
            child_document=self.article1), user_id)

        self.book1 = Book(activities=['hiking'],
                          book_types=['biography'])
        self.session.add(self.book1)
        self.session.flush()
        self._add_association(Association.create(
            parent_document=self.book1,
            child_document=self.route), user_id)

        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',
            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.route3.geometry = DocumentGeometry(geom='SRID=3857;POINT(0 0)')
        self.session.add(self.route3)
        self.session.flush()
        DocumentRest.create_new_version(self.route3, user_id)

        self.route4 = Route(
            activities=['rock_climbing'], elevation_max=1500,
            elevation_min=700, height_diff_up=500, height_diff_down=500,
            durations='1', climbing_outdoor_type='single')
        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 some associations
        self.waypoint = Waypoint(
            waypoint_type='climbing_outdoor', elevation=4,
            geometry=DocumentGeometry(
                geom='SRID=3857;POINT(635956 5723604)'))
        self.waypoint.locales.append(WaypointLocale(
            lang='en', title='Mont Granier 1 (en)', description='...',
            access='yep', access_period='yapa'))
        self.waypoint.locales.append(WaypointLocale(
            lang='fr', title='Mont Granier 1 (fr)', description='...',
            access='ouai', access_period='yapa'))
        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 2 (en)', description='...',
            access='yep'))
        self.session.add(self.waypoint2)
        self.session.flush()
        self._add_association(Association.create(
            parent_document=self.route,
            child_document=self.route4), user_id)
        self._add_association(Association.create(
            parent_document=self.route4,
            child_document=self.route), user_id)
        self._add_association(Association.create(
            parent_document=self.waypoint,
            child_document=self.route), user_id)

        # add a map
        topo_map = 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
        )
        self.session.add(topo_map)
        self.session.flush()
        self.session.add(TopoMapAssociation(
            document=self.route, topo_map=topo_map))

        self.outing1 = Outing(
            activities=['skitouring'], date_start=datetime.date(2016, 1, 1),
            date_end=datetime.date(2016, 1, 1),
            public_transport=True,
            locales=[
                OutingLocale(
                    lang='en', title='...', description='...',
                    weather='sunny')
            ]
        )
        self.session.add(self.outing1)
        self.session.flush()
        self._add_association(Association.create(
            parent_document=self.route,
            child_document=self.outing1), user_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._add_association(Association.create(
            parent_document=self.route,
            child_document=self.outing2), user_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()
Example #37
0
    def _add_test_data(self):
        self.xreport1 = Xreport(activities=['hiking'],
                                event_type=['stone_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()

        self.xreport2 = Xreport(activities=['hiking'],
                                event_type=['avalanche'],
                                nb_participants=5)
        self.session.add(self.xreport2)
        self.xreport3 = Xreport(activities=['hiking'],
                                event_type=['avalanche'],
                                nb_participants=5)
        self.session.add(self.xreport3)
        self.xreport4 = Xreport(activities=['hiking'],
                                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.session.add(Association.create(
            parent_document=self.outing3,
            child_document=self.xreport1))
        self.session.add(Association.create(
            parent_document=self.route3,
            child_document=self.xreport1))
        self.session.flush()
Example #38
0
    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.session.flush()

        DocumentRest.create_new_version(self.waypoint1, contributor_id)
        update_feed_document_create(self.waypoint1, 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.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()
Example #39
0
    def test_put_add_geometry(self):
        """Tests adding a geometry to a waypoint without geometry.
        """
        # first create a waypoint with no geometry
        waypoint = Waypoint(
            waypoint_type='summit', elevation=3779)

        locale_en = WaypointLocale(
            lang='en', title='Mont Pourri', access='y')
        waypoint.locales.append(locale_en)

        self.session.add(waypoint)
        self.session.flush()
        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(waypoint, user_id)

        # then add a geometry to the waypoint
        body_put = {
            'message': 'Adding geom',
            'document': {
                'document_id': waypoint.document_id,
                'version': waypoint.version,
                'quality': quality_types[1],
                'geometry': {
                    'geom':
                        '{"type": "Point", "coordinates": [635956, 5723604]}'
                },
                'waypoint_type': 'summit',
                'elevation': 3779,
                'locales': []
            }
        }
        response = self.app_put_json(
            self._prefix + '/' + str(waypoint.document_id), body_put,
            status=403)

        headers = self.add_authorization_header(username='******')
        self.app_put_json(
            self._prefix + '/' + str(waypoint.document_id), body_put,
            headers=headers, status=200)

        response = self.app.get(
            self._prefix + '/' + str(waypoint.document_id), status=200)
        self.assertEqual(response.content_type, 'application/json')

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

        # check that no new archive_document was created
        self.session.expire_all()
        document = self.session.query(self._model).get(document_id)

        # 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, 1)

        # check that no 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, 1)

        # check that a new archive_document_geometry was created
        archive_locale_count = \
            self.session.query(ArchiveDocumentGeometry). \
            filter(document_id == ArchiveDocumentGeometry.document_id). \
            count()
        self.assertEqual(archive_locale_count, 1)

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

        # version with lang 'en'
        version_en = self.get_latest_version('en', versions)

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

        meta_data_en = version_en.history_metadata
        self.assertEqual(meta_data_en.comment, 'Adding geom')
        self.assertIsNotNone(meta_data_en.written_at)
Example #40
0
    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()
Example #41
0
    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()
Example #42
0
    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.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(
            activities=['hiking'],
            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()
Example #43
0
    def _add_test_data(self):
        self.xreport1 = Xreport(activities=['hiking'],
                                event_type=['stone_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.session.add(
            Association(parent_document_id=user_id3,
                        parent_document_type=USERPROFILE_TYPE,
                        child_document_id=self.xreport1.document_id,
                        child_document_type=XREPORT_TYPE))

        self.xreport2 = Xreport(activities=['hiking'],
                                event_type=['avalanche'],
                                nb_participants=5)
        self.session.add(self.xreport2)
        self.xreport3 = Xreport(activities=['hiking'],
                                event_type=['avalanche'],
                                nb_participants=5)
        self.session.add(self.xreport3)
        self.xreport4 = Xreport(activities=['hiking'],
                                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.session.add(
            Association.create(parent_document=self.outing3,
                               child_document=self.xreport1))
        self.session.add(
            Association.create(parent_document=self.route3,
                               child_document=self.xreport1))
        self.session.flush()
Example #44
0
    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)
Example #45
0
    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.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()
Example #46
0
    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._add_tag(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(
            event_activity='alpine_climbing',
            event_type='stone_ice_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()
Example #47
0
    def _add_test_data(self):
        self.article1 = Article(categories=['site_info'],
                                activities=['hiking'],
                                article_type='collab')
        self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy')
        self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy')

        self.article1.locales.append(self.locale_en)
        self.article1.locales.append(self.locale_fr)

        self.session.add(self.article1)
        self.session.flush()

        user_id = self.global_userids['contributor']
        DocumentRest.create_new_version(self.article1, user_id)
        self.article1_version = self.session.query(DocumentVersion). \
            filter(DocumentVersion.document_id == self.article1.document_id). \
            filter(DocumentVersion.lang == 'en').first()

        self.article2 = Article(
            categories=['site_info'], activities=['hiking'],
            article_type='collab')
        self.session.add(self.article2)
        self.article3 = Article(
            categories=['site_info'], activities=['hiking'],
            article_type='collab')
        self.session.add(self.article3)
        self.article4 = Article(
            categories=['site_info'], activities=['hiking'],
            article_type='personal')
        self.article4.locales.append(DocumentLocale(
            lang='en', title='Lac d\'Annecy'))
        self.article4.locales.append(DocumentLocale(
            lang='fr', title='Lac d\'Annecy'))
        self.session.add(self.article4)
        self.session.flush()

        DocumentRest.create_new_version(self.article4, user_id)
        self.article4_version = self.session.query(DocumentVersion). \
            filter(DocumentVersion.document_id == self.article4.document_id). \
            filter(DocumentVersion.lang == 'en').first()

        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.session.add(Association.create(
            parent_document=self.article1,
            child_document=self.article4))
        self.session.add(Association.create(
            parent_document=self.article3,
            child_document=self.article1))
        self.session.flush()
Example #48
0
    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()