示例#1
0
    def _build_object(self):
        polygon = 'SRID=%s;MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0)))' % settings.SRID
        self.city = zoning_factories.CityFactory(geom=polygon)
        self.district = zoning_factories.DistrictFactory(geom=polygon)

        self.content = self.factory(geom='SRID=%s;POINT(1 1)' % settings.SRID)

        self.picture = common_factories.AttachmentFactory(
            content_object=self.content,
            attachment_file=get_dummy_uploaded_image())
        self.document = common_factories.AttachmentFactory(
            content_object=self.content,
            attachment_file=get_dummy_uploaded_document())
        self.video = common_factories.AttachmentFactory(
            content_object=self.content,
            attachment_file='',
            attachment_video=
            'http://www.youtube.com/embed/Jm3anSjly0Y?wmode=opaque')
        self.video_detected = detect_backend(self.video.attachment_video)

        self.theme = common_factories.ThemeFactory()
        self.content.themes.add(self.theme)
        self.source = common_factories.RecordSourceFactory()
        self.content.source.add(self.source)

        self.portal = common_factories.TargetPortalFactory()
        self.content.portal.add(self.portal)

        path = core_factories.PathFactory(
            geom='SRID=%s;LINESTRING(0 10, 10 10)' % settings.SRID)
        self.trek = trekking_factories.TrekFactory(no_path=True)
        self.trek.add_path(path)
        self.poi = trekking_factories.POIFactory(no_path=True)
        self.poi.add_path(path, start=0.5, end=0.5)
示例#2
0
    def _build_object(self):
        polygon = 'SRID=%s;MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0)))' % settings.SRID
        self.city = zoning_factories.CityFactory(geom=polygon)
        self.district = zoning_factories.DistrictFactory(geom=polygon)
        self.portal = common_factories.TargetPortalFactory()
        self.theme = common_factories.ThemeFactory()

        self.content = self.factory(geom='SRID=%s;POINT(1 1)' % settings.SRID,
                                    portals=[self.portal],
                                    themes=[self.theme])

        self.picture = common_factories.AttachmentFactory(
            content_object=self.content,
            attachment_file=get_dummy_uploaded_image())
        self.document = common_factories.AttachmentFactory(
            content_object=self.content,
            attachment_file=get_dummy_uploaded_document())

        self.content.themes.add(self.theme)
        self.source = common_factories.RecordSourceFactory()
        self.content.source.add(self.source)

        self.content.portal.add(self.portal)
        if settings.TREKKING_TOPOLOGY_ENABLED:
            path = core_factories.PathFactory(
                geom='SRID=%s;LINESTRING(0 10, 10 10)' % settings.SRID)
            self.trek = trekking_factories.TrekFactory(paths=[path])
            self.poi = trekking_factories.POIFactory(paths=[(path, 0.5, 0.5)])
        else:
            self.trek = trekking_factories.TrekFactory(
                geom='SRID=%s;LINESTRING(0 10, 10 10)' % settings.SRID)
            self.poi = trekking_factories.POIFactory(
                geom='SRID=%s;POINT(0 5)' % settings.SRID)
示例#3
0
    def test_videos(self):
        self.assertDictEqual(
            self.result['videos'][0], {
                u'backend': 'Youtube',
                u'url':
                'http://www.youtube.com/embed/Jm3anSjly0Y?wmode=opaque',
                u'title': self.video.title,
                u'legend': self.video.legend,
                u'author': self.video.author,
                u'code': self.video_detected.code
            })
        self.video = common_factories.AttachmentFactory(
            content_object=self.content,
            attachment_file='',
            attachment_video='http://www.dailymotion.com/video/x6e0q24')
        self.video_detected = detect_backend(self.video.attachment_video)
        self.pk = self.content.pk
        url = '/api/en/{model}s/{pk}.json'.format(
            model=self.content._meta.model_name, pk=self.pk)
        self.response = self.client.get(url)
        self.result = json.loads(self.response.content)

        self.assertDictEqual(
            self.result['videos'][0], {
                u'backend': 'Dailymotion',
                u'url': 'http://www.dailymotion.com/embed/video/x6e0q24',
                u'title': self.video.title,
                u'legend': self.video.legend,
                u'author': self.video.author,
                u'code': self.video_detected.code
            })
示例#4
0
    def test_video_dailymotion_wrong_id(self):
        common_factories.AttachmentFactory(
            content_object=self.content,
            attachment_file='',
            attachment_video='https://www.dailymotion.com/video/noid')

        pk = self.content.pk
        url = '/api/en/{model}s/{pk}.json'.format(
            model=self.content._meta.model_name, pk=pk)
        response = self.client.get(url)
        result = json.loads(response.content.decode())
        self.assertFalse(result['videos'])
示例#5
0
 def test_video_youtube(self):
     video_youtube = common_factories.AttachmentFactory(content_object=self.content, attachment_file='',
                                                        attachment_video='http://www.youtube.com/embed/Jm3anSjly0Y?wmode=opaque')
     video_detected_youtube = detect_backend(video_youtube.attachment_video)
     pk = self.content.pk
     url = '/api/en/{model}s/{pk}.json'.format(model=self.content._meta.model_name, pk=pk)
     response = self.client.get(url)
     result = json.loads(response.content)
     self.assertDictEqual(result['videos'][0],
                          {u'backend': 'Youtube',
                           u'url': 'http://www.youtube.com/embed/Jm3anSjly0Y?wmode=opaque',
                           u'title': video_youtube.title,
                           u'legend': video_youtube.legend,
                           u'author': video_youtube.author,
                           u'code': video_detected_youtube.code})
示例#6
0
    def test_video_dailymotion(self):
        video_dailymotion = common_factories.AttachmentFactory(
            content_object=self.content, attachment_file='',
            attachment_video='http://www.dailymotion.com/video/x6e0q24')
        video_detected_dailymotion = detect_backend(video_dailymotion.attachment_video)
        pk = self.content.pk
        url = '/api/en/{model}s/{pk}.json'.format(model=self.content._meta.model_name, pk=pk)
        response = self.client.get(url)
        result = json.loads(response.content)

        self.assertDictEqual(result['videos'][0],
                             {u'backend': 'Dailymotion',
                              u'url': 'http://www.dailymotion.com/embed/video/x6e0q24',
                              u'title': video_dailymotion.title,
                              u'legend': video_dailymotion.legend,
                              u'author': video_dailymotion.author,
                              u'code': video_detected_dailymotion.code})
示例#7
0
 def setUpTestData(cls):
     cls.client = Client()
     cls.nb_treks = 15
     cls.theme = common_factory.ThemeFactory.create()
     cls.network = trek_factory.TrekNetworkFactory.create()
     cls.label = common_factory.LabelFactory(id=23)
     cls.treks = trek_factory.TrekWithPOIsFactory.create_batch(cls.nb_treks)
     cls.treks[0].themes.add(cls.theme)
     cls.treks[0].networks.add(cls.network)
     cls.treks[0].labels.add(cls.label)
     trek_models.TrekRelationship(trek_a=cls.treks[0],
                                  trek_b=cls.treks[1]).save()
     information_desk_type = tourism_factory.InformationDeskTypeFactory()
     cls.info_desk = tourism_factory.InformationDeskFactory(
         type=information_desk_type)
     cls.treks[0].information_desks.add(cls.info_desk)
     common_factory.AttachmentFactory.create(
         content_object=cls.treks[0],
         attachment_file=get_dummy_uploaded_image())
     common_factory.AttachmentFactory.create(
         content_object=cls.treks[0],
         attachment_file=get_dummy_uploaded_file())
     common_factory.AttachmentFactory.create(
         content_object=cls.treks[0],
         attachment_file=get_dummy_uploaded_document())
     common_factory.AttachmentFactory(
         content_object=cls.treks[0],
         attachment_file='',
         attachment_video=
         'https://www.youtube.com/embed/Jm3anSjly0Y?wmode=opaque')
     common_factory.AttachmentFactory(
         content_object=cls.treks[0],
         attachment_file='',
         attachment_video='',
         attachment_link='https://geotrek.fr/assets/img/logo.svg')
     common_factory.AttachmentFactory(content_object=cls.treks[0],
                                      attachment_file='',
                                      attachment_video='',
                                      attachment_link='')
     cls.treks[3].parking_location = None
     cls.treks[3].points_reference = MultiPoint(
         [Point(0, 0), Point(1, 1)], srid=settings.SRID)
     cls.treks[3].save()
     cls.path = core_factory.PathFactory.create()
     cls.parent = trek_factory.TrekFactory.create(published=True,
                                                  name='Parent')
     cls.child1 = trek_factory.TrekFactory.create(published=False,
                                                  name='Child 1')
     cls.child2 = trek_factory.TrekFactory.create(published=True,
                                                  name='Child 2')
     trek_models.TrekRelationship(trek_a=cls.parent,
                                  trek_b=cls.treks[0]).save()
     trek_models.OrderedTrekChild(parent=cls.parent,
                                  child=cls.child1,
                                  order=2).save()
     trek_models.OrderedTrekChild(parent=cls.parent,
                                  child=cls.child2,
                                  order=1).save()
     trek_models.OrderedTrekChild(parent=cls.treks[0],
                                  child=cls.child2,
                                  order=3).save()
     cls.content = tourism_factory.TouristicContentFactory.create(
         published=True)
     cls.city = zoning_factory.CityFactory(code=31000)
     cls.district = zoning_factory.DistrictFactory(id=420)
     cls.accessibility = trek_factory.AccessibilityFactory(id=4)
     cls.route = trek_factory.RouteFactory(id=680)
     cls.theme = common_factory.ThemeFactory(id=15)
     cls.portal = common_factory.TargetPortalFactory(id=16)
     cls.structure = authent_factory.StructureFactory(id=8)
     cls.nb_treks += 2  # add parent and 1 child published
     cls.poi_type = trek_factory.POITypeFactory()
     cls.poi = trek_factory.POIFactory()
     cls.source = common_factory.RecordSourceFactory()
     cls.reservation_system = common_factory.ReservationSystemFactory()
     cls.site = outdoor_factory.SiteFactory()