Esempio n. 1
0
    def test_synchronize_associations(self):
        self.route3 = Route(activities=['hiking'])
        self.route4 = Route(activities=['hiking'])
        self.session.add_all([self.route3, self.route4])
        self.session.add_all([
            Association(parent_document=self.route1,
                        child_document=self.route2),
            Association(parent_document=self.route1,
                        child_document=self.route3)
        ])
        self.session.flush()

        new_associations = {
            'routes': [{
                'document_id': self.route2.document_id,
                'is_parent': True
            }, {
                'document_id': self.route4.document_id,
                'is_parent': True
            }],
            'waypoints': [{
                'document_id': self.waypoint1.document_id,
                'is_parent': True
            }]
        }
        synchronize_associations(self.route1, new_associations,
                                 self.global_userids['contributor'])

        self.assertIsNotNone(self._get_association(self.route1, self.route2))
        self.assertIsNotNone(self._get_association(self.route4, self.route1))
        self.assertIsNone(self._get_association(self.route2, self.route1))
        self.assertIsNone(self._get_association(self.route1, self.route3))
        self.assertIsNotNone(self._get_association(self.waypoint1,
                                                   self.route1))
Esempio n. 2
0
 def _add_test_data_routes(self):
     self.session.add_all([
         Association(parent_document=self.route1,
                     child_document=self.route2),
         Association(parent_document=self.waypoint1,
                     child_document=self.route1),
         Association(parent_document=self.waypoint2,
                     child_document=self.route1),
     ])
     self.session.flush()
Esempio n. 3
0
    def collection_delete(self):
        association_in = schema_association.objectify(self.request.validated)

        association = self._load(association_in)
        if association is None:
            # also accept {parent_document_id: y, child_document_id: x} when
            # for an association {parent_document_id: x, child_document_id: x}
            association_in = Association(
                parent_document_id=association_in.child_document_id,
                child_document_id=association_in.parent_document_id)
            association = self._load(association_in)
            if association is None:
                raise HTTPBadRequest('association does not exist')

        if is_main_waypoint_association(association):
            raise HTTPBadRequest(
                'as the main waypoint of the route, this waypoint can not '
                'be disassociated')

        log = association.get_log(self.request.authenticated_userid,
                                  is_creation=False)

        DBSession.delete(association)
        DBSession.add(log)

        return {}
Esempio n. 4
0
    def test_get_current_associations_waypoints(self):
        self.waypoint3 = Waypoint(waypoint_type='summit')
        self.session.add_all([
            Association(parent_document=self.waypoint1,
                        child_document=self.waypoint2),
            Association(parent_document=self.waypoint3,
                        child_document=self.waypoint1),
            Association(parent_document=self.waypoint1,
                        child_document=self.route1),
            Association(parent_document=self.waypoint1,
                        child_document=self.route2),
        ])
        self.session.flush()

        new_associations = {
            # routes are ignored
            'routes': [{
                'document_id': 1,
                'is_parent': True
            }, {
                'document_id': 2,
                'is_parent': True
            }],
            'waypoints': [{
                'document_id': 3,
                'is_parent': True
            }],
            'waypoint_children': [{
                'document_id': 4,
                'is_parent': False
            }]
        }

        current_associations = _get_current_associations(
            self.waypoint1, new_associations)

        expected_current_associations = {
            'waypoints': [{
                'document_id': self.waypoint3.document_id,
                'is_parent': True
            }],
            'waypoint_children': [{
                'document_id': self.waypoint2.document_id,
                'is_parent': False
            }]
        }
        self.assertEqual(current_associations, expected_current_associations)
Esempio n. 5
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.waypoint.locales.append(self.locale_en)
        self.waypoint.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')
        self.session.add(self.waypoint)

        self.waypoint_with_topic = Waypoint(waypoint_type='summit',
                                            elevation=2203)
        document_topic = DocumentTopic(topic_id=1)
        self.locale_en_with_topic = WaypointLocale(
            lang='en',
            title='Mont Granier',
            description='...',
            access='yep',
            document_topic=document_topic)
        self.waypoint_with_topic.locales.append(self.locale_en_with_topic)
        self.waypoint_with_topic.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')
        self.session.add(self.waypoint_with_topic)

        self.image = Image(filename='image.jpg',
                           activities=['paragliding'],
                           height=1500,
                           image_type='collaborative')
        self.image_locale_en = DocumentLocale(lang='en',
                                              title='',
                                              description='')
        self.image.locales.append(self.image_locale_en)
        self.image.geometry = DocumentGeometry(
            geom='SRID=3857;POINT(635956 5723604)')
        self.session.add(self.image)

        self.outing = Outing(activities=['skitouring'],
                             date_start=datetime.date(2016, 1, 1),
                             date_end=datetime.date(2016, 1, 1),
                             locales=[
                                 OutingLocale(
                                     lang='en',
                                     title='Mont Granier / skitouring')
                             ])
        self.session.add(self.outing)
        self.session.flush()

        for user_id in (self.global_userids['contributor'],
                        self.global_userids['contributor2']):
            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))

        self.session.flush()
Esempio n. 6
0
    def test_get_current_associations_waypoints_partial(self):
        self.session.add(
            Association(parent_document=self.waypoint1,
                        child_document=self.waypoint2))
        self.session.flush()

        new_associations = {}
        current_associations = _get_current_associations(
            self.waypoint1, new_associations)

        expected_current_associations = {}
        self.assertEqual(current_associations, expected_current_associations)
Esempio n. 7
0
    def collection_delete(self):
        association_in = schema_association.objectify(self.request.validated)

        association = self._load(association_in)
        if association is None:
            # also accept {parent_document_id: y, child_document_id: x} when
            # for an association {parent_document_id: x, child_document_id: x}
            association_in = Association(
                parent_document_id=association_in.child_document_id,
                child_document_id=association_in.parent_document_id)
            association = self._load(association_in)
            if association is None:
                raise HTTPBadRequest('association does not exist')

        _check_required_associations(association)
        check_permission_for_association_removal(self.request, association)

        log = association.get_log(self.request.authenticated_userid,
                                  is_creation=False)

        DBSession.delete(association)
        DBSession.add(log)

        update_cache_version_associations(
            [], [{
                'parent_id': association.parent_document_id,
                'parent_type': association.parent_document_type,
                'child_id': association.child_document_id,
                'child_type': association.child_document_type
            }])

        notify_es_syncer_if_needed(association, self.request)
        update_feed_association_update(association.parent_document_id,
                                       association.parent_document_type,
                                       association.child_document_id,
                                       association.child_document_type,
                                       self.request.authenticated_userid)

        return {}
Esempio n. 8
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()
Esempio n. 9
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()
Esempio n. 10
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()
Esempio n. 11
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()
Esempio n. 12
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()
Esempio n. 13
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')

        self.locale_fr = RouteLocale(lang='fr',
                                     title='Mont Blanc du ciel',
                                     description='...',
                                     gear='paraglider')

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

        self.route.geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')

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

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

        self.route2 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=800,
                            height_diff_down=800,
                            durations='1',
                            locales=[
                                RouteLocale(lang='en',
                                            title='Mont Blanc from the air',
                                            description='...',
                                            gear='paraglider'),
                                RouteLocale(lang='fr',
                                            title='Mont Blanc du ciel',
                                            description='...',
                                            gear='paraglider')
                            ])
        self.session.add(self.route2)
        self.session.flush()
        DocumentRest.create_new_version(self.route2, user_id)

        self.route3 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=500,
                            height_diff_down=500,
                            durations='1')
        self.session.add(self.route3)
        self.route4 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=500,
                            height_diff_down=500,
                            durations='1')
        self.route4.locales.append(
            RouteLocale(lang='en',
                        title='Mont Blanc from the air',
                        description='...',
                        gear='paraglider'))
        self.route4.locales.append(
            RouteLocale(lang='fr',
                        title='Mont Blanc du ciel',
                        description='...',
                        gear='paraglider'))
        self.session.add(self.route4)

        # add a map
        self.session.add(
            TopoMap(
                code='3232ET',
                editor='IGN',
                scale='25000',
                locales=[DocumentLocale(lang='fr', title='Belley')],
                geometry=DocumentGeometry(
                    geom_detail=
                    'SRID=3857;POLYGON((635900 5723600, 635900 5723700, 636000 5723700, 636000 5723600, 635900 5723600))'
                )  # noqa
            ))

        # add some associations
        self.waypoint = Waypoint(
            waypoint_type='summit',
            elevation=4,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'))
        self.waypoint.locales.append(
            WaypointLocale(lang='en',
                           title='Mont Granier (en)',
                           description='...',
                           access='yep'))
        self.waypoint.locales.append(
            WaypointLocale(lang='fr',
                           title='Mont Granier (fr)',
                           description='...',
                           access='ouai'))
        self.session.add(self.waypoint)
        self.waypoint2 = Waypoint(
            waypoint_type='summit',
            elevation=4,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'))
        self.waypoint2.locales.append(
            WaypointLocale(lang='en',
                           title='Mont Granier (en)',
                           description='...',
                           access='yep'))
        self.session.add(self.waypoint2)
        self.session.flush()
        self.session.add(
            Association(parent_document_id=self.route.document_id,
                        child_document_id=self.route4.document_id))
        self.session.add(
            Association(parent_document_id=self.route4.document_id,
                        child_document_id=self.route.document_id))
        self.session.add(
            Association(parent_document_id=self.waypoint.document_id,
                        child_document_id=self.route.document_id))

        self.outing1 = Outing(activities=['skitouring'],
                              date_start=datetime.date(2016, 1, 1),
                              date_end=datetime.date(2016, 1, 1),
                              locales=[
                                  OutingLocale(lang='en',
                                               title='...',
                                               description='...',
                                               weather='sunny')
                              ])
        self.session.add(self.outing1)
        self.session.flush()
        self.session.add(
            Association(parent_document_id=self.route.document_id,
                        child_document_id=self.outing1.document_id))

        self.outing2 = Outing(redirects_to=self.outing1.document_id,
                              activities=['skitouring'],
                              date_start=datetime.date(2016, 1, 1),
                              date_end=datetime.date(2016, 1, 1),
                              locales=[
                                  OutingLocale(lang='en',
                                               title='...',
                                               description='...',
                                               weather='sunny')
                              ])
        self.session.add(self.outing2)
        self.session.flush()
        self.session.add(
            Association(parent_document_id=self.route.document_id,
                        child_document_id=self.outing2.document_id))
        self.session.flush()

        # add areas
        self.area1 = Area(
            area_type='range',
            geometry=DocumentGeometry(
                geom_detail=
                'SRID=3857;POLYGON((635900 5723600, 635900 5723700, 636000 5723700, 636000 5723600, 635900 5723600))'  # noqa
            ))
        self.area2 = Area(area_type='range',
                          locales=[DocumentLocale(lang='fr', title='France')])

        self.session.add_all([self.area1, self.area2])
        self.session.flush()
Esempio n. 14
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()