Beispiel #1
0
    def setUpClass(cls):
        super(SyncMobileTreksTest, cls).setUpClass()
        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()

        cls.trek_1 = TrekWithPublishedPOIsFactory.create()
        cls.trek_2 = TrekWithPublishedPOIsFactory.create(
            portals=(cls.portal_a, ))
        cls.trek_3 = TrekWithPublishedPOIsFactory.create(
            portals=(cls.portal_b, ))

        cls.attachment_1 = AttachmentFactory.create(
            content_object=cls.trek_1,
            attachment_file=get_dummy_uploaded_image())
        cls.poi_1 = POI.objects.first()
        cls.attachment_poi_image_1 = AttachmentFactory.create(
            content_object=cls.poi_1,
            attachment_file=get_dummy_uploaded_image())
        cls.attachment_poi_image_2 = AttachmentFactory.create(
            content_object=cls.poi_1,
            attachment_file=get_dummy_uploaded_image())
        cls.attachment_poi_file = AttachmentFactory.create(
            content_object=cls.poi_1,
            attachment_file=get_dummy_uploaded_file())
        translation.deactivate()
Beispiel #2
0
 def setUp(self):
     super(SyncTestPdf, self).setUp()
     self.trek_5 = TrekFactory.create(practice=self.practice_trek, portals=(self.portal_a,),
                                      published=True)
     filetype_topoguide = FileTypeFactory.create(type='Topoguide')
     AttachmentFactory.create(content_object=self.trek_5, attachment_file=get_dummy_uploaded_image(),
                              filetype=filetype_topoguide)
Beispiel #3
0
    def test_picture(self):
        trek = TrekFactory.create()
        AttachmentFactory.create(obj=trek)
        self.assertEqual(len(trek.attachments), 1)
        self.assertEqual(trek.thumbnail, None)
        self.assertEqual(trek.pictures, [])

        AttachmentFactory.create(obj=trek, attachment_file=get_dummy_uploaded_image())
        self.assertEqual(len(trek.attachments), 2)
        self.assertEqual(len(trek.pictures), 1)
        self.assertNotEqual(trek.thumbnail, None)
Beispiel #4
0
    def test_picture(self):
        trek = TrekFactory.create()
        AttachmentFactory.create(obj=trek)
        self.assertEqual(len(trek.attachments), 1)
        self.assertEqual(trek.thumbnail, None)
        self.assertEqual(trek.pictures, [])

        AttachmentFactory.create(obj=trek, attachment_file=get_dummy_uploaded_image())
        self.assertEqual(len(trek.attachments), 2)
        self.assertEqual(len(trek.pictures), 1)
        self.assertNotEqual(trek.thumbnail, None)
Beispiel #5
0
    def setUpClass(cls):
        super(SyncMobileTreksTest, cls).setUpClass()
        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()
        picto_desk = get_dummy_uploaded_image()
        information_desk_type = InformationDeskTypeFactory.create(
            pictogram=picto_desk)
        cls.info_desk = InformationDeskFactory.create(
            type=information_desk_type)
        info_desk_no_picture = InformationDeskFactory.create(photo=None)

        cls.trek_1 = TrekWithPublishedPOIsFactory.create()
        cls.trek_1.information_desks.set((cls.info_desk, info_desk_no_picture))
        cls.trek_2 = TrekWithPublishedPOIsFactory.create(
            portals=(cls.portal_a, ))
        cls.trek_3 = TrekWithPublishedPOIsFactory.create(
            portals=(cls.portal_b, ))
        cls.trek_4 = TrekFactory.create()
        OrderedTrekChild.objects.create(parent=cls.trek_1,
                                        child=cls.trek_4,
                                        order=1)
        cls.desk = InformationDeskFactory.create()

        cls.trek_4.information_desks.add(cls.desk)

        cls.attachment_1 = AttachmentFactory.create(
            content_object=cls.trek_1,
            attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.trek_1,
                                 attachment_file=get_dummy_uploaded_image())

        cls.poi_1 = cls.trek_1.published_pois.first()
        cls.attachment_poi_image_1 = AttachmentFactory.create(
            content_object=cls.poi_1,
            attachment_file=get_dummy_uploaded_image())
        cls.attachment_poi_image_2 = AttachmentFactory.create(
            content_object=cls.poi_1,
            attachment_file=get_dummy_uploaded_image())
        cls.attachment_poi_file = AttachmentFactory.create(
            content_object=cls.poi_1,
            attachment_file=get_dummy_uploaded_file())
        cls.attachment_trek_image = AttachmentFactory.create(
            content_object=cls.trek_4,
            attachment_file=get_dummy_uploaded_image())

        cls.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
            published=True)
        cls.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
            published=True)
        cls.attachment_content_1 = AttachmentFactory.create(
            content_object=cls.touristic_content,
            attachment_file=get_dummy_uploaded_image())
        cls.attachment_event_1 = AttachmentFactory.create(
            content_object=cls.touristic_event,
            attachment_file=get_dummy_uploaded_image())
        translation.deactivate()
Beispiel #6
0
    def test_pois_geojson(self):
        trek = TrekWithPOIsFactory.create()
        self.assertEqual(len(trek.pois), 2)
        poi = trek.pois[0]
        AttachmentFactory.create(obj=poi, attachment_file=get_dummy_uploaded_image())
        self.assertNotEqual(poi.thumbnail, None)

        url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        poislayer = json.loads(response.content)
        poifeature = poislayer['features'][0]
        self.assertTrue('serializable_thumbnail' in poifeature['properties'])
Beispiel #7
0
    def test_overriden_document(self):
        trek = TrekFactory.create()
        # Will have to mock screenshot, though.
        with open(trek.get_map_image_path(), 'w') as f:
            f.write('***' * 1000)
        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) > 1000)

        AttachmentFactory.create(obj=trek, title="docprint", attachment_file=get_dummy_uploaded_document(size=100))
        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) < 1000)
Beispiel #8
0
    def test_overriden_document(self):
        trek = TrekFactory.create()
        # Will have to mock screenshot, though.
        with open(trek.get_map_image_path(), 'w') as f:
            f.write('***' * 1000)
        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) > 1000)

        AttachmentFactory.create(obj=trek, title="docprint", attachment_file=get_dummy_uploaded_document(size=100))
        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) < 1000)
Beispiel #9
0
    def test_pois_geojson(self):
        trek = TrekWithPOIsFactory.create()
        self.assertEqual(len(trek.pois), 2)
        poi = trek.pois[0]
        AttachmentFactory.create(obj=poi,
                                 attachment_file=get_dummy_uploaded_image())
        self.assertNotEqual(poi.thumbnail, None)
        self.assertEqual(len(trek.pois), 2)

        url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        poislayer = json.loads(response.content)
        poifeature = poislayer['features'][0]
        self.assertTrue('thumbnail' in poifeature['properties'])
Beispiel #10
0
    def setUp(self):
        self.user = SuperUserFactory.create(password='******')
        self.content = POIFactory.create(geom='SRID=%s;POINT(1 1)' %
                                         settings.SRID)

        self.picture = AttachmentFactory(
            content_object=self.content,
            attachment_file=get_dummy_uploaded_image(),
        )
        self.trek = TrekFactory.create(
            geom='SRID=%s;LINESTRING(0 0, 1 0, 2 0)' % settings.SRID)
        self.picture_2 = AttachmentFactory(
            content_object=self.trek,
            attachment_file=get_dummy_uploaded_image(),
        )
Beispiel #11
0
    def test_pois_geojson(self):
        trek = TrekFactory.create(no_path=True)
        p1 = PathFactory.create(geom=LineString((0, 0, 0), (4, 4, 2)))
        poi = POIFactory(no_path=True)
        trek.add_path(p1, start=0.5, end=1.0)
        poi.add_path(p1, start=0.6, end=0.6)
        AttachmentFactory.create(obj=poi, attachment_file=get_dummy_uploaded_image())
        self.assertNotEqual(poi.thumbnail, None)
        self.assertEqual(len(trek.pois), 1)

        url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        poislayer = json.loads(response.content)
        poifeature = poislayer['features'][0]
        self.assertTrue('serializable_thumbnail' in poifeature['properties'])
Beispiel #12
0
    def test_overriden_document(self):
        event = TouristicEventFactory.create(published=True)

        with open(event.get_map_image_path(), 'w') as f:
            f.write('***' * 1000)

        url = '/api/en/touristicevents/{pk}/slug.odt'.format(pk=event.pk)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) > 1000)

        AttachmentFactory.create(obj=event, title="docprint", attachment_file=get_dummy_uploaded_document(size=100))
        url = '/api/en/touristicevents/{pk}/slug.odt'.format(pk=event.pk)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) < 1000)
Beispiel #13
0
    def test_pois_geojson(self):
        trek = TrekWithPOIsFactory.create(published=True)
        self.assertEqual(len(trek.pois), 2)
        poi = trek.pois[0]
        poi.published = True
        poi.save()
        AttachmentFactory.create(obj=poi, attachment_file=get_dummy_uploaded_image())
        self.assertNotEqual(poi.thumbnail, None)
        self.assertEqual(len(trek.pois), 2)

        url = '/api/en/treks/{pk}/pois.geojson'.format(pk=trek.pk)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        poislayer = json.loads(response.content)
        poifeature = poislayer['features'][0]
        self.assertTrue('thumbnail' in poifeature['properties'])
Beispiel #14
0
    def setUp(self):
        self.login()

        polygon = 'SRID=%s;MULTIPOLYGON(((700000 6600000, 700000 6600003, 700003 6600003, 700003 6600000, 700000 6600000)))' % settings.SRID
        self.city = CityFactory(geom=polygon)
        self.district = DistrictFactory(geom=polygon)

        self.poi = POIFactory.create(published=True)

        self.attachment = AttachmentFactory.create(obj=self.poi,
                                                   attachment_file=get_dummy_uploaded_image())

        self.touristic_content = tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=False)  # not published
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True).delete()  # deleted
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(701000 6601000)' % settings.SRID, published=True)  # too far
        self.touristic_event = tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(700002 6600002)' % settings.SRID, published=True)
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(700002 6600002)' % settings.SRID, published=False)  # not published
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(700002 6600002)' % settings.SRID, published=True).delete()  # deleted
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(702000 6602000)' % settings.SRID, published=True)  # too far

        self.pk = self.poi.pk
        url = '/api/pois/%s/' % self.pk
        self.response = self.client.get(url)
        self.result = json.loads(self.response.content)
Beispiel #15
0
 def test_attachments_missing_from_disk(self):
     trek_1 = TrekWithPublishedPOIsFactory.create(published_fr=True)
     attachment = AttachmentFactory(content_object=trek_1, attachment_file=get_dummy_uploaded_image())
     os.remove(attachment.attachment_file.path)
     management.call_command('sync_mobile', 'tmp', url='http://localhost:8000',
                             skip_tiles=True, languages='fr', verbosity=2, stdout=StringIO())
     self.assertFalse(os.path.exists(os.path.join('tmp', 'nolang', 'media', 'trekking_trek')))
Beispiel #16
0
class CommandAttachmentsTests(TestCase):
    def setUp(self):
        self.content = POIFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
        self.picture = AttachmentFactory(
            content_object=self.content,
            attachment_file=get_dummy_uploaded_image())

    def test_remove_thumbnails(self):
        output = StringIO()
        self.assertIsNotNone(self.content.thumbnail)
        self.assertTrue(os.path.exists(self.picture.attachment_file.path))
        self.assertTrue(
            os.path.exists("{path}.120x120_q85_crop.png".format(
                path=self.picture.attachment_file.path)))
        self.assertEqual(
            Thumbnail.objects.first().name,
            "{name}.120x120_q85_crop.png".format(
                name=self.picture.attachment_file.name))
        call_command('remove_thumbnails', stdout=output)
        self.assertTrue(os.path.exists(self.picture.attachment_file.path))
        self.assertFalse(
            os.path.exists("{name}.120x120_q85_crop.png".format(
                name=self.picture.attachment_file.path)))
        self.assertEqual(Thumbnail.objects.count(), 0)

    def test_clean_attachments_deleted(self):
        output = StringIO()
        self.picture.delete()
        call_command('clean_attachments', stdout=output, verbosity=2)
        self.assertIn('%s... DELETED' % self.picture.attachment_file.name,
                      output.getvalue())
        self.assertFalse(os.path.exists(self.picture.attachment_file.path))

    def test_clean_attachments_found(self):
        output = StringIO()
        call_command('clean_attachments', stdout=output, verbosity=2)
        self.assertIn('%s... Found' % self.picture.attachment_file.name,
                      output.getvalue())
        self.assertTrue(os.path.exists(self.picture.attachment_file.path))

    def test_clean_attachments_thumbnails(self):
        output = StringIO()
        self.assertIsNotNone(self.content.thumbnail)
        call_command('clean_attachments', stdout=output, verbosity=2)
        self.assertIn('%s... Thumbnail' % self.content.thumbnail.name,
                      output.getvalue())
        self.assertTrue(os.path.exists(self.content.thumbnail.path))
Beispiel #17
0
    def test_overriden_document(self, get_attributes_html):
        trek = TrekFactory.create()

        get_attributes_html.return_value = '<p>mock</p>'
        with open(trek.get_map_image_path(), 'w') as f:
            f.write('***' * 1000)
        with open(trek.get_elevation_chart_path('fr'), 'w') as f:
            f.write('***' * 1000)

        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) > 1000)

        AttachmentFactory.create(obj=trek, title="docprint", attachment_file=get_dummy_uploaded_document(size=100))
        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) < 1000)
Beispiel #18
0
    def setUp(self):
        self.user = SuperUserFactory.create(password='******')
        self.content = POIFactory.create(geom='SRID=%s;POINT(1 1)' %
                                         settings.SRID)

        self.picture = AttachmentFactory(
            content_object=self.content,
            title='img1',
            attachment_file=get_dummy_uploaded_image())
        self.trek = TrekFactory.create(
            geom='SRID=%s;LINESTRING(0 0, 1 0, 2 0)' % settings.SRID)
        self.picture_2 = AttachmentFactory(
            content_object=self.trek,
            title='img2',
            attachment_file=get_dummy_uploaded_image())
        if os.path.exists(settings.MEDIA_ROOT):
            shutil.rmtree(settings.MEDIA_ROOT)
        os.makedirs(settings.MEDIA_ROOT)
    def setUpClass(cls):
        super(SyncMobileTreksTest, cls).setUpClass()
        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()

        cls.trek_1 = TrekWithPublishedPOIsFactory.create()
        cls.trek_2 = TrekWithPublishedPOIsFactory.create(portals=(cls.portal_a,))
        cls.trek_3 = TrekWithPublishedPOIsFactory.create(portals=(cls.portal_b,))

        cls.attachment_1 = AttachmentFactory.create(content_object=cls.trek_1,
                                                    attachment_file=get_dummy_uploaded_image())
        cls.poi_1 = POI.objects.first()
        cls.attachment_poi_image_1 = AttachmentFactory.create(content_object=cls.poi_1,
                                                              attachment_file=get_dummy_uploaded_image())
        cls.attachment_poi_image_2 = AttachmentFactory.create(content_object=cls.poi_1,
                                                              attachment_file=get_dummy_uploaded_image())
        cls.attachment_poi_file = AttachmentFactory.create(content_object=cls.poi_1,
                                                           attachment_file=get_dummy_uploaded_file())
        translation.deactivate()
Beispiel #20
0
    def test_overriden_document(self):
        event = TouristicEventFactory.create(published=True)

        with open(event.get_map_image_path(), 'w') as f:
            f.write('***' * 1000)

        url = '/api/en/touristicevents/{pk}/slug.odt'.format(pk=event.pk)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) > 1000)

        AttachmentFactory.create(
            obj=event,
            title="docprint",
            attachment_file=get_dummy_uploaded_document(size=100))
        url = '/api/en/touristicevents/{pk}/slug.odt'.format(pk=event.pk)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) < 1000)
Beispiel #21
0
    def test_overriden_document(self, get_attributes_html):
        trek = TrekFactory.create()

        get_attributes_html.return_value = '<p>mock</p>'
        with open(trek.get_map_image_path(), 'w') as f:
            f.write('***' * 1000)
        with open(trek.get_elevation_chart_path(), 'w') as f:
            f.write('***' * 1000)

        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) > 1000)

        AttachmentFactory.create(
            obj=trek,
            title="docprint",
            attachment_file=get_dummy_uploaded_document(size=100))
        response = self.client.get(trek.get_document_public_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(len(response.content) < 1000)
Beispiel #22
0
 def test_only_external_public_pdf(self, trek):
     output = StringIO()
     trek = TrekFactory.create(published=True, )
     filetype_topoguide = FileTypeFactory.create(type='Topoguide')
     AttachmentFactory.create(content_object=trek,
                              attachment_file=get_dummy_uploaded_image(),
                              filetype=filetype_topoguide)
     management.call_command('sync_rando',
                             os.path.join('var', 'tmp'),
                             url='http://localhost:8000',
                             verbosity=2,
                             skip_pdf=False,
                             skip_tiles=True,
                             stdout=output)
     self.assertFalse(
         os.path.exists(
             os.path.join('var', 'tmp', 'api', 'en', 'treks',
                          str(self.trek.pk), '%s.pdf' % self.trek.slug)))
     self.assertTrue(
         os.path.exists(
             os.path.join('var', 'tmp', 'api', 'en', 'treks', str(trek.pk),
                          '%s.pdf' % trek.slug)))
Beispiel #23
0
    def test_list_attachments_in_details(self):
        """Test that the list is correctly displayed on the detail page of path"""

        path = PathFactory(length=1)
        AttachmentFactory(obj=path, creator=self.user)

        response = self.client.get(path.get_detail_url())

        self.assertTemplateUsed(response,
                                template_name='paperclip/details.html')
        self.assertItemsEqual(
            Attachment.objects.attachments_for_object(path),
            response.context['attachments_list'],
        )
Beispiel #24
0
 def setUp(self):
     super().setUp()
     self.information_desks = InformationDeskFactory.create()
     self.trek = TrekWithPublishedPOIsFactory.create(published=True)
     if settings.TREKKING_TOPOLOGY_ENABLED:
         InfrastructureFactory.create(paths=[(self.trek.paths.first(), 0, 0)
                                             ],
                                      name="INFRA_1")
         SignageFactory.create(paths=[(self.trek.paths.first(), 0, 0)],
                               name="SIGNA_1")
     else:
         InfrastructureFactory.create(
             geom='SRID=2154;POINT(700000 6600000)', name="INFRA_1")
         SignageFactory.create(geom='SRID=2154;POINT(700000 6600000)',
                               name="SIGNA_1")
     area = SensitiveAreaFactory.create(published=True)
     area.species.practices.add(
         SportPracticeFactory.create(name='Terrestre'))
     area.save()
     self.touristic_content = TouristicContentFactory(
         geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
         published=True)
     self.touristic_event = TouristicEventFactory(
         geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
         published=True)
     self.attachment_touristic_content = AttachmentFactory.create(
         content_object=self.touristic_content,
         attachment_file=get_dummy_uploaded_image())
     self.attachment_touristic_event = AttachmentFactory.create(
         content_object=self.touristic_event,
         attachment_file=get_dummy_uploaded_image())
     self.touristic_content_without_attachment = TouristicContentFactory(
         geom='SRID=%s;POINT(700002 6600002)' % settings.SRID,
         published=True)
     self.touristic_event_without_attachment = TouristicEventFactory(
         geom='SRID=%s;POINT(700002 6600002)' % settings.SRID,
         published=True)
Beispiel #25
0
 def test_document_export_with_attachment(self, mock_requests):
     obj = self.modelfactory.create()
     attachment = AttachmentFactory.create(content_object=obj,
                                           attachment_file=get_dummy_uploaded_image(),
                                           title='mapimage')
     obj.attachment = attachment
     obj.save()
     self.login()
     mock_requests.get.return_value.status_code = 200
     mock_requests.get.return_value.content = '<p id="properties">Mock</p>'
     response = self.client.get(obj.get_document_url())
     self.assertEqual(response.status_code, 200)
     element_in_dir = os.listdir(os.path.join(settings.MEDIA_ROOT, 'maps'))
     first_path = os.path.join(settings.MEDIA_ROOT, 'maps', element_in_dir[0])
     second_path = os.path.join(settings.MEDIA_ROOT, attachment.attachment_file.name)
     self.assertTrue(filecmp.cmp(first_path, second_path))
Beispiel #26
0
 def test_document_export_with_attachment(self, mock_requests):
     obj = self.modelfactory.create()
     attachment = AttachmentFactory.create(content_object=obj,
                                           attachment_file=get_dummy_uploaded_image(),
                                           title='mapimage')
     obj.attachment = attachment
     obj.save()
     self.login()
     mock_requests.get.return_value.status_code = 200
     mock_requests.get.return_value.content = '<p id="properties">Mock</p>'
     response = self.client.get(obj.get_document_url())
     self.assertEqual(response.status_code, 200)
     element_in_dir = os.listdir(os.path.join(settings.MEDIA_ROOT, 'maps'))
     first_path = os.path.join(settings.MEDIA_ROOT, 'maps', element_in_dir[0])
     second_path = os.path.join(settings.MEDIA_ROOT, attachment.attachment_file.name)
     self.assertTrue(filecmp.cmp(first_path, second_path))
Beispiel #27
0
    def setUp(self):
        self.source_a = RecordSourceFactory()
        self.source_b = RecordSourceFactory()

        self.portal_a = TargetPortalFactory()
        self.portal_b = TargetPortalFactory()
        information_desks = InformationDeskFactory.create()
        self.trek_1 = TrekWithPublishedPOIsFactory.create(
            sources=(self.source_a, ),
            portals=(self.portal_b, ),
            published=True)
        self.trek_1.information_desks.add(information_desks)
        self.attachment_1 = AttachmentFactory.create(
            content_object=self.trek_1,
            attachment_file=get_dummy_uploaded_image())
        self.trek_2 = TrekFactory.create(sources=(self.source_b, ),
                                         published=True)
        self.trek_3 = TrekFactory.create(portals=(self.portal_b,
                                                  self.portal_a),
                                         published=True)
        self.trek_4 = TrekFactory.create(portals=(self.portal_a, ),
                                         published=True)

        self.poi_1 = trek_models.POI.objects.first()
        self.attachment_poi_image_1 = AttachmentFactory.create(
            content_object=self.poi_1,
            attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_image_2 = AttachmentFactory.create(
            content_object=self.poi_1,
            attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_file = AttachmentFactory.create(
            content_object=self.poi_1,
            attachment_file=get_dummy_uploaded_file())

        infrastructure = InfrastructureFactory.create(no_path=True,
                                                      name="INFRA_1")
        infrastructure.add_path(self.trek_1.paths.first(), start=0, end=0)
        signage = SignageFactory.create(no_path=True, name="SIGNA_1")
        signage.add_path(self.trek_1.paths.first(), start=0, end=0)
        SensitiveAreaFactory.create(published=True)
        self.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
            published=True)
        self.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
            published=True)
        self.attachment_touristic_content = AttachmentFactory.create(
            content_object=self.touristic_content,
            attachment_file=get_dummy_uploaded_image())
        self.attachment_touristic_event = AttachmentFactory.create(
            content_object=self.touristic_event,
            attachment_file=get_dummy_uploaded_image())
Beispiel #28
0
    def setUp(self):
        self.login()

        polygon = 'SRID=%s;MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0)))' % settings.SRID
        self.city = CityFactory(geom=polygon)
        self.district = DistrictFactory(geom=polygon)

        self.trek = TrekFactory.create(
            points_reference=MultiPoint([Point(0, 0), Point(1, 1)], srid=settings.SRID),
            parking_location=Point(0, 0, srid=settings.SRID)
        )

        self.attachment = AttachmentFactory.create(obj=self.trek,
                                                   attachment_file=get_dummy_uploaded_image())

        self.information_desk = tourism_factories.InformationDeskFactory.create()
        self.trek.information_desks.add(self.information_desk)

        self.usage = UsageFactory.create()
        self.trek.usages.add(self.usage)

        self.theme = ThemeFactory.create()
        self.trek.themes.add(self.theme)

        self.network = TrekNetworkFactory.create()
        self.trek.networks.add(self.network)

        self.weblink = WebLinkFactory.create()
        self.trek.web_links.add(self.weblink)

        self.trek_b = TrekFactory.create()
        TrekRelationshipFactory.create(has_common_departure=True,
                                       has_common_edge=False,
                                       is_circuit_step=True,
                                       trek_a=self.trek,
                                       trek_b=self.trek_b)

        self.touristic_content = tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
        self.touristic_event = tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(2 2)' % settings.SRID)

        self.pk = self.trek.pk
        url = '/api/treks/%s/' % self.pk
        self.response = self.client.get(url)
        self.result = json.loads(self.response.content)
Beispiel #29
0
 def test_attachments_missing_from_disk(self):
     trek_1 = TrekWithPublishedPOIsFactory.create(published_fr=True)
     attachment = AttachmentFactory(
         content_object=trek_1, attachment_file=get_dummy_uploaded_image())
     os.remove(attachment.attachment_file.path)
     with self.assertRaises(CommandError) as e:
         management.call_command('sync_rando',
                                 'tmp',
                                 url='http://localhost:8000',
                                 skip_tiles=True,
                                 languages='fr',
                                 verbosity=2,
                                 stdout=BytesIO())
     self.assertEqual(e.exception.message,
                      'Some errors raised during synchronization.')
     self.assertFalse(
         os.path.exists(
             os.path.join('tmp', 'mobile', 'nolang', 'media',
                          'trekking_trek')))
Beispiel #30
0
    def setUp(self):
        self.login()

        polygon = 'SRID=%s;MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0)))' % settings.SRID
        self.city = CityFactory(geom=polygon)
        self.district = DistrictFactory(geom=polygon)

        self.poi = POIFactory.create(geom=Point(0, 0, srid=settings.SRID))

        self.attachment = AttachmentFactory.create(obj=self.poi,
                                                   attachment_file=get_dummy_uploaded_image())

        self.touristic_content = tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
        self.touristic_event = tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(2 2)' % settings.SRID)

        self.pk = self.poi.pk
        url = '/api/pois/%s/' % self.pk
        self.response = self.client.get(url)
        self.result = json.loads(self.response.content)
 def test_remove_thumbnails(self):
     output = StringIO()
     self.content = POIFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
     self.picture = AttachmentFactory(
         content_object=self.content,
         attachment_file=get_dummy_uploaded_image())
     self.assertIsNotNone(self.content.thumbnail)
     self.assertTrue(os.path.exists(self.picture.attachment_file.path))
     self.assertTrue(
         os.path.exists("{path}.120x120_q85_crop.png".format(
             path=self.picture.attachment_file.path)))
     self.assertEqual(
         Thumbnail.objects.first().name,
         "{name}.120x120_q85_crop.png".format(
             name=self.picture.attachment_file.name))
     call_command('remove_thumbnails', stdout=output)
     self.assertTrue(os.path.exists(self.picture.attachment_file.path))
     self.assertFalse(
         os.path.exists("{name}.120x120_q85_crop.png".format(
             name=self.picture.attachment_file.path)))
     self.assertEqual(Thumbnail.objects.count(), 0)
Beispiel #32
0
    def setUp(self):
        self.source_a = RecordSourceFactory()
        self.source_b = RecordSourceFactory()

        self.portal_a = TargetPortalFactory()
        self.portal_b = TargetPortalFactory()
        information_desks = InformationDeskFactory.create()
        self.trek_1 = TrekWithPublishedPOIsFactory.create(sources=(self.source_a, ),
                                                          portals=(self.portal_b,),
                                                          published=True)
        self.trek_1.information_desks.add(information_desks)
        self.attachment_1 = AttachmentFactory.create(content_object=self.trek_1,
                                                     attachment_file=get_dummy_uploaded_image())
        self.trek_2 = TrekFactory.create(sources=(self.source_b,),
                                         published=True)
        self.trek_3 = TrekFactory.create(portals=(self.portal_b,
                                                  self.portal_a),
                                         published=True)
        self.trek_4 = TrekFactory.create(portals=(self.portal_a,),
                                         published=True)

        self.poi_1 = trek_models.POI.objects.first()
        self.attachment_poi_image_1 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_image_2 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_file = AttachmentFactory.create(content_object=self.poi_1,
                                                            attachment_file=get_dummy_uploaded_file())

        infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1")
        infrastructure.add_path(self.trek_1.paths.first(), start=0, end=0)
        signage = SignageFactory.create(no_path=True, name="SIGNA_1")
        signage.add_path(self.trek_1.paths.first(), start=0, end=0)
        SensitiveAreaFactory.create(published=True)
        self.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        self.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        self.attachment_touristic_content = AttachmentFactory.create(content_object=self.touristic_content,
                                                                     attachment_file=get_dummy_uploaded_image())
        self.attachment_touristic_event = AttachmentFactory.create(content_object=self.touristic_event,
                                                                   attachment_file=get_dummy_uploaded_image())
Beispiel #33
0
    def setUpClass(cls):
        super(SyncRandoTestCase, cls).setUpClass()
        cls.source = RecordSourceFactory()
        cls.portal = TargetPortalFactory()

        cls.information_desks = InformationDeskFactory.create()

        cls.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        cls.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        cls.attachment_touristic_content = AttachmentFactory.create(content_object=cls.touristic_content,
                                                                    attachment_file=get_dummy_uploaded_image())
        cls.attachment_touristic_event = AttachmentFactory.create(content_object=cls.touristic_event,
                                                                  attachment_file=get_dummy_uploaded_image())

        AttachmentFactory.create(content_object=cls.touristic_content,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.touristic_event,
                                 attachment_file=get_dummy_uploaded_image())
Beispiel #34
0
    def setUpClass(cls):
        super(SyncRandoTestCase, cls).setUpClass()
        cls.trek = TrekWithPublishedPOIsFactory.create(published=True)
        cls.information_desks = InformationDeskFactory.create()
        cls.trek.information_desks.add(cls.information_desks)
        cls.attachment = AttachmentFactory.create(
            content_object=cls.trek,
            attachment_file=get_dummy_uploaded_image())

        cls.source_a = RecordSourceFactory()
        cls.source_b = RecordSourceFactory()

        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()
        cls.trek_fr = TrekFactory.create(published_fr=True,
                                         sources=(cls.source_b, ))
        cls.trek_sb = TrekFactory.create(sources=(cls.source_b, ),
                                         published=True)

        cls.trek_sb_pa = TrekFactory.create(sources=(cls.source_b, ),
                                            portals=(cls.portal_a, ),
                                            published=True)

        cls.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
            published=True)
        cls.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID,
            published=True)
        cls.attachment_touristic_content = AttachmentFactory.create(
            content_object=cls.touristic_content,
            attachment_file=get_dummy_uploaded_image())
        cls.attachment_touristic_event = AttachmentFactory.create(
            content_object=cls.touristic_event,
            attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.touristic_content,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.touristic_event,
                                 attachment_file=get_dummy_uploaded_image())
        cls.poi = trek_models.POI.objects.first()
        cls.attachment_poi_image = AttachmentFactory.create(
            content_object=cls.poi, attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.poi,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.poi,
                                 attachment_file=get_dummy_uploaded_file())
Beispiel #35
0
    def setUpClass(cls):
        super(SyncRandoTestCase, cls).setUpClass()
        cls.practice_dive = PracticeFactory.create(order=0)
        cls.dive = DiveFactory.create(practice=cls.practice_dive, published=True,
                                      geom='SRID=2154;POINT(700001 6600001)')
        cls.attachment_dive = AttachmentFactory.create(content_object=cls.dive,
                                                       attachment_file=get_dummy_uploaded_image())
        cls.poi_dive = POIFactory.create(name="dive_poi", published=True)
        AttachmentFactory.create(content_object=cls.poi_dive,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.poi_dive,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.poi_dive,
                                 attachment_file=get_dummy_uploaded_file())
        cls.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        cls.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        cls.attachment_touristic_content = AttachmentFactory.create(content_object=cls.touristic_content,
                                                                    attachment_file=get_dummy_uploaded_image())
        cls.attachment_touristic_event = AttachmentFactory.create(content_object=cls.touristic_event,
                                                                  attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.touristic_content,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.touristic_event,
                                 attachment_file=get_dummy_uploaded_image())
        cls.source_a = RecordSourceFactory()
        cls.source_b = RecordSourceFactory()

        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()
        cls.dive_portal_source = DiveFactory.create(practice=cls.practice_dive, published=True,
                                                    geom='SRID=2154;POINT(700002 6600002)',
                                                    portals=(cls.portal_a,), sources=(cls.source_a,))
        cls.dive_other_portal_source = DiveFactory.create(practice=cls.practice_dive, published=True,
                                                          geom='SRID=2154;POINT(700002 6600002)',
                                                          portals=(cls.portal_b,), sources=(cls.source_b,))
Beispiel #36
0
 def setUp(self):
     self.content = POIFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
     self.picture = AttachmentFactory(
         content_object=self.content,
         attachment_file=get_dummy_uploaded_image())
Beispiel #37
0
 def add_attachment(self, attachment=None):
     from geotrek.common.factories import AttachmentFactory
     return AttachmentFactory.create(obj=self.trek, attachment_file=attachment)
Beispiel #38
0
    def setUp(self):
        self.source_a = RecordSourceFactory()
        self.source_b = RecordSourceFactory()

        self.portal_a = TargetPortalFactory()
        self.portal_b = TargetPortalFactory()
        information_desks = InformationDeskFactory.create()

        self.practice_trek = PracticeTrekFactory.create(order=1)
        self.practice_trek_first = PracticeTrekFactory.create(order=0)
        self.trek_1 = TrekWithPublishedPOIsFactory.create(practice=self.practice_trek, sources=(self.source_a, ),
                                                          portals=(self.portal_b,),
                                                          published=True)
        self.trek_1.information_desks.add(information_desks)
        self.attachment_1 = AttachmentFactory.create(content_object=self.trek_1,
                                                     attachment_file=get_dummy_uploaded_image())
        self.trek_2 = TrekFactory.create(sources=(self.source_b,),
                                         published=True)
        self.trek_3 = TrekFactory.create(portals=(self.portal_b,
                                                  self.portal_a),
                                         published=True)
        self.trek_4 = TrekFactory.create(practice=self.practice_trek, portals=(self.portal_a,),
                                         published=True)
        self.trek_5 = TrekFactory.create(practice=self.practice_trek_first, portals=(self.portal_a,),
                                         published=True, name="other")

        self.practice_dive = PracticeDiveFactory.create(order=0)

        self.dive_1 = DiveFactory.create(practice=self.practice_dive, sources=(self.source_a,),
                                         portals=(self.portal_b,),
                                         published=True, geom='SRID=2154;POINT(700001 6600001)')
        self.attachment_dive = AttachmentFactory.create(content_object=self.dive_1,
                                                        attachment_file=get_dummy_uploaded_image())
        self.dive_2 = DiveFactory.create(sources=(self.source_b,),
                                         published=True, geom='SRID=2154;LINESTRING (700000 6600000, 700100 6600100)')
        self.dive_3 = DiveFactory.create(portals=(self.portal_b,
                                                  self.portal_a),
                                         published=True, geom='POLYGON((700000 6600000, 700000 6600100, '
                                                              '700100 6600100, 700100 6600000, 700000 6600000))')
        self.dive_4 = DiveFactory.create(practice=self.practice_dive, portals=(self.portal_a,),
                                         published=True)
        self.poi_1 = trek_models.POI.objects.first()
        self.poi_dive = POIFactory.create(name="dive_poi", published=True)
        self.attachment_poi_image_1 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=self.poi_dive,
                                 attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_image_2 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=self.poi_dive,
                                 attachment_file=get_dummy_uploaded_file())
        self.attachment_poi_file = AttachmentFactory.create(content_object=self.poi_1,
                                                            attachment_file=get_dummy_uploaded_file())
        if settings.TREKKING_TOPOLOGY_ENABLED:
            infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1")
            infrastructure.add_path(self.trek_1.paths.first(), start=0, end=0)
            signage = SignageFactory.create(no_path=True, name="SIGNA_1")
            signage.add_path(self.trek_1.paths.first(), start=0, end=0)
        else:
            InfrastructureFactory.create(geom='SRID=2154;POINT(700000 6600000)', name="INFRA_1")
            SignageFactory.create(geom='SRID=2154;POINT(700000 6600000)', name="SIGNA_1")
        area = SensitiveAreaFactory.create(published=True)
        area.species.practices.add(SportPracticeFactory.create(name='Terrestre'))
        area.save()
        self.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        self.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        self.attachment_touristic_content = AttachmentFactory.create(content_object=self.touristic_content,
                                                                     attachment_file=get_dummy_uploaded_image())
        self.attachment_touristic_event = AttachmentFactory.create(content_object=self.touristic_event,
                                                                   attachment_file=get_dummy_uploaded_image())
Beispiel #39
0
    def setUp(self):
        self.login()

        polygon = 'SRID=%s;MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0)))' % settings.SRID
        self.city = CityFactory(geom=polygon)
        self.district = DistrictFactory(geom=polygon)

        self.parent = TrekFactory.create(published=True)

        self.trek = TrekFactory.create(
            parent=self.parent,
            no_path=True,
            points_reference=MultiPoint([Point(0, 0), Point(1, 1)], srid=settings.SRID),
            parking_location=Point(0, 0, srid=settings.SRID)
        )
        path1 = PathFactory.create(geom='SRID=%s;LINESTRING(0 0, 1 0)' % settings.SRID)
        self.trek.add_path(path1)

        self.attachment = AttachmentFactory.create(obj=self.trek,
                                                   attachment_file=get_dummy_uploaded_image())

        self.information_desk = tourism_factories.InformationDeskFactory.create()
        self.trek.information_desks.add(self.information_desk)

        self.theme = ThemeFactory.create()
        self.trek.themes.add(self.theme)

        self.accessibility = AccessibilityFactory.create()
        self.trek.accessibilities.add(self.accessibility)

        self.network = TrekNetworkFactory.create()
        self.trek.networks.add(self.network)

        self.weblink = WebLinkFactory.create()
        self.trek.web_links.add(self.weblink)

        self.source = RecordSourceFactory.create()
        self.trek.source.add(self.source)

        self.trek_b = TrekFactory.create(no_path=True,
                                         geom='SRID=%s;POINT(2 2)' % settings.SRID,
                                         published=True)
        path2 = PathFactory.create(geom='SRID=%s;LINESTRING(0 1, 1 1)' % settings.SRID)
        self.trek_b.add_path(path2)
        TrekRelationshipFactory.create(has_common_departure=True,
                                       has_common_edge=False,
                                       is_circuit_step=True,
                                       trek_a=self.trek,
                                       trek_b=self.trek_b)

        self.touristic_content = tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID, published=True)
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID, published=False)  # not published
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID, published=True).delete()  # deleted
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(1000 1000)' % settings.SRID, published=True)  # too far
        self.touristic_event = tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(2 2)' % settings.SRID, published=True)
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(2 2)' % settings.SRID, published=False)  # not published
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(2 2)' % settings.SRID, published=True).delete()  # deleted
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(2000 2000)' % settings.SRID, published=True)  # too far
        trek2 = TrekFactory(no_path=True, published=False)  # not published
        trek2.add_path(path2)
        trek3 = TrekFactory(no_path=True, published=True)  # deleted
        trek3.add_path(path2)
        trek3.delete()
        trek4 = TrekFactory(no_path=True, published=True)  # too far
        trek4.add_path(PathFactory.create(geom='SRID=%s;LINESTRING(0 2000, 1 2000)' % settings.SRID))

        self.child1 = TrekFactory.create(published=False, parent=self.trek)
        self.child2 = TrekFactory.create(published=True, parent=self.trek)

        self.pk = self.trek.pk
        url = '/api/treks/%s/' % self.pk
        self.response = self.client.get(url)
        self.result = json.loads(self.response.content)