Example #1
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())
Example #2
0
    def setUpClass(cls):
        super(SyncTestPortal, cls).setUpClass()
        cls.source_a = RecordSourceFactory()
        cls.source_b = RecordSourceFactory()
        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()

        FlatPageFactory.create(published=True,
                               sources=(cls.source_a,))
        FlatPageFactory.create(portals=(cls.portal_a, cls.portal_b),
                               published=True)
        FlatPageFactory.create(published=True,
                               sources=(cls.source_b,))
        FlatPageFactory.create(portals=(cls.portal_a,),
                               published=True)
Example #3
0
 def portals(obj, create, extracted=None, **kwargs):
     if create:
         if extracted:
             for portal in extracted:
                 obj.portal.add(portal)
         else:
             obj.portal.add(TargetPortalFactory.create())
Example #4
0
 def test_tiles_with_treks_source_portal(self, mock_tileslist, mock_tiles,
                                         mock_prepare):
     output = StringIO()
     self.source = RecordSourceFactory()
     self.portal = TargetPortalFactory()
     trek = TrekFactory.create(published=True,
                               sources=(self.source, ),
                               portals=(self.portal, ))
     management.call_command('sync_rando',
                             os.path.join('var', 'tmp'),
                             url='http://localhost:8000',
                             source=self.source.name,
                             portal=self.portal.name,
                             languages='fr',
                             verbosity=2,
                             stdout=output,
                             stderr=StringIO())
     zfile = zipfile.ZipFile(
         os.path.join('var', 'tmp', 'zip', 'tiles', 'global.zip'))
     for finfo in zfile.infolist():
         ifile = zfile.open(finfo)
         self.assertEqual(ifile.read(), b'I am a png')
     self.assertIn("zip/tiles/global.zip", output.getvalue())
     zfile_trek = zipfile.ZipFile(
         os.path.join('var', 'tmp', 'zip', 'tiles',
                      '{pk}.zip'.format(pk=trek.pk)))
     for finfo in zfile_trek.infolist():
         ifile_trek = zfile_trek.open(finfo)
         self.assertEqual(ifile_trek.read(), b'I am a png')
     self.assertIn("zip/tiles/{pk}.zip".format(pk=trek.pk),
                   output.getvalue())
Example #5
0
    def setUpClass(cls):
        super(SyncMobileFlatpageTest, cls).setUpClass()
        translation.deactivate()

        cls.portals = []

        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()

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

        FlatPageFactory.create(published=True)
        FlatPageFactory.create(portals=(cls.portal_a, cls.portal_b),
                               published=True)
        FlatPageFactory.create(published=True)
        FlatPageFactory.create(portals=(cls.portal_a, ), published=True)
Example #6
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())
Example #7
0
    def setUp(self):
        self.source_a = RecordSourceFactory()
        self.source_b = RecordSourceFactory()

        self.portal_a = TargetPortalFactory()
        self.portal_b = TargetPortalFactory()

        self.trek_1 = TrekFactory.create(sources=(self.source_a, ),
                                         portals=(self.portal_b, ),
                                         published=True)
        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)
Example #8
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)
        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 = (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 = 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())
        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()
Example #9
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()
Example #10
0
 def test_command_post_migration(self, mock_stdout):
     portal = TargetPortalFactory.create(name="Test", title=None)
     self.assertEqual(portal.title_fr, "")
     self.assertEqual(portal.description_fr, "")
     call_command('update_post_migration_languages')
     changed_portal = TargetPortal.objects.get(name="Test")
     self.assertEqual(changed_portal.title_fr, "Geotrek Rando")
     self.assertEqual(
         changed_portal.description_fr,
         "Geotrek est une web app permettant de préparer à "
         "l'avance ses randonnées !")
Example #11
0
    def test_tiles_with_treks(self, mock_tiles, mock_prepare, mock_tileslist):
        output = StringIO()
        portal_a = TargetPortalFactory()
        portal_b = TargetPortalFactory()
        trek = TrekWithPublishedPOIsFactory.create(published=True)
        trek_not_same_portal = TrekWithPublishedPOIsFactory.create(
            published=True, portals=(portal_a, ))
        p = PathFactory.create(geom=LineString((0, 0), (0, 10)))
        trek_multi = TrekFactory.create(published=True,
                                        paths=[(p, 0, 0.1), (p, 0.2, 0.3)])
        management.call_command('sync_mobile',
                                'var/tmp',
                                url='http://localhost:8000',
                                verbosity=2,
                                stdout=output,
                                portal=portal_b.name)

        zfile_global = zipfile.ZipFile('var/tmp/nolang/global.zip')
        for finfo in zfile_global.infolist():
            ifile_global = zfile_global.open(finfo)
            if ifile_global.name.startswith('tiles/'):
                self.assertEqual(ifile_global.readline(), b'I am a png')
        zfile_trek = zipfile.ZipFile('var/tmp/nolang/{}.zip'.format(trek.pk))
        for finfo in zfile_trek.infolist():
            ifile_trek = zfile_trek.open(finfo)
            if ifile_trek.name.startswith('tiles/'):
                self.assertEqual(ifile_trek.readline(), b'I am a png')
        self.assertIn("nolang/global.zip", output.getvalue())
        self.assertIn("nolang/{pk}.zip".format(pk=trek.pk), output.getvalue())

        self.assertFalse(
            os.path.exists(
                os.path.join('var/tmp', 'nolang',
                             '{}.zip'.format(trek_not_same_portal.pk))))
        self.assertTrue(
            os.path.exists(
                os.path.join('var/tmp', 'nolang',
                             '{}.zip'.format(trek_multi.pk))))
Example #12
0
    def test_create_content_apidae_constant_fields(self, mocked):
        def mocked_json():
            filename = os.path.join(os.path.dirname(__file__), 'data',
                                    'apidaeContent.json')
            with open(filename, 'r') as f:
                return json.load(f)

        mocked.return_value.status_code = 200
        mocked.return_value.json = mocked_json
        mocked.return_value.content = b'Fake image'
        FileType.objects.create(type="Photographie")
        TargetPortalFactory(name='Portal 1')
        TargetPortalFactory(name='Portal 2')
        RecordSourceFactory(name='Source 1')
        RecordSourceFactory(name='Source 2')
        self.assertEqual(TouristicContent.objects.count(), 0)
        output = io.StringIO()
        call_command(
            'import',
            'geotrek.tourism.tests.test_parsers.ApidaeConstantFieldContentParser',
            verbosity=2,
            stdout=output)
        self.assertEqual(TouristicContent.objects.count(), 1)
        content = TouristicContent.objects.get()
        self.assertEqual(str(content.category), "Constant Content")
        self.assertQuerysetEqual(content.type1.all(), ["Type1 1", "Type1 2"],
                                 transform=str)
        self.assertQuerysetEqual(content.type2.all(), ["Type2 1", "Type2 2"],
                                 transform=str)
        self.assertQuerysetEqual(content.themes.all(), ["Theme 1", "Theme 2"],
                                 transform=str)
        self.assertQuerysetEqual(content.source.all(),
                                 ["Source 1", "Source 2"],
                                 transform=str)
        self.assertQuerysetEqual(content.portal.all(),
                                 ["Portal 1", "Portal 2"],
                                 transform=str)
Example #13
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,))
    def setUp(self):
        translation.deactivate()

        self.contents = []
        self.events = []
        self.portals = []

        self.portal_a = TargetPortalFactory()
        self.portal_b = TargetPortalFactory()

        self.source_a = RecordSourceFactory()
        self.source_b = RecordSourceFactory()

        self.content_1 = TouristicContentFactory.create(portals=(self.portal_a, self.portal_b),
                                                        sources=(self.source_a, self.source_b))

        self.content_2 = TouristicContentFactory.create(portals=(self.portal_a,),
                                                        sources=(self.source_a, self.source_b))

        self.event_1 = TouristicEventFactory.create(portals=(self.portal_a, self.portal_b),
                                                    sources=(self.source_b, ))

        self.event_2 = TouristicEventFactory.create(portals=(self.portal_b,),
                                                    sources=(self.source_a, self.source_b))
Example #15
0
    def test_create_event_tourinsoft(self, mocked):
        def mocked_json():
            filename = os.path.join(os.path.dirname(__file__), 'data',
                                    'tourinsoftEvent.json')
            with open(filename, 'r') as f:
                return json.load(f)

        mocked.return_value.status_code = 200
        mocked.return_value.json = mocked_json
        mocked.return_value.content = b'Fake image'
        FileType.objects.create(type="Photographie")
        type = TouristicEventTypeFactory(type="Agenda rando")
        source = RecordSourceFactory(name="CDT 28")
        portal = TargetPortalFactory(name="Itinérance")
        call_command('import',
                     'geotrek.tourism.tests.test_parsers.FMA28',
                     verbosity=0)
        self.assertEqual(TouristicEvent.objects.count(), 1)
        event = TouristicEvent.objects.get()
        self.assertEqual(event.eid, "FMACEN0280060359")
        self.assertEqual(event.name, "Moto cross de Brou")
        self.assertEqual(event.description, "")
        self.assertEqual(event.description_teaser, "")
        self.assertEqual(
            event.contact[:69],
            "<strong>Adresse :</strong><br>Circuit des Tonnes<br>28160 DAMPIERRE-S"
        )
        self.assertEqual(event.email, "*****@*****.**")
        self.assertEqual(event.website, "http://www.mxbrou.com")
        self.assertEqual(round(event.geom.x), 559796)
        self.assertEqual(round(event.geom.y), 6791765)
        self.assertEqual(
            event.practical_info[:61],
            "<strong>Langues parlées :</strong><br>Anglais<br>Allemand<br>")
        self.assertIn(
            "<strong>Équipements :</strong><br>Restauration sur place<br>Sanitaires",
            event.practical_info)
        self.assertTrue(event.published)
        self.assertEqual(event.source.get(), source)
        self.assertEqual(event.portal.get(), portal)
        self.assertEqual(event.type, type)
        self.assertEqual(Attachment.objects.count(), 9)
        self.assertEqual(Attachment.objects.first().content_object, event)
        self.assertEqual(event.begin_date, date(2100, 6, 1))
        self.assertEqual(event.end_date, date(2100, 6, 2))
Example #16
0
    def test_create_content_tourinsoft_v3(self, mocked):
        def mocked_json():
            filename = os.path.join(os.path.dirname(__file__), 'data',
                                    'tourinsoftContentV3.json')
            with open(filename, 'r') as f:
                return json.load(f)

        mocked.return_value.status_code = 200
        mocked.return_value.json = mocked_json
        mocked.return_value.content = b'Fake image'
        FileType.objects.create(type="Photographie")
        category = TouristicContentCategoryFactory(label="Où dormir")
        source = RecordSourceFactory(name="CDT 28")
        portal = TargetPortalFactory(name="Itinérance")
        call_command('import',
                     'geotrek.tourism.tests.test_parsers.HOT28v3',
                     verbosity=0)
        self.assertEqual(TouristicContent.objects.count(), 1)
        content = TouristicContent.objects.get()
        self.assertEqual(content.eid, "HOTCEN0280010001")
        self.assertEqual(content.name, "Hôtel du Perche")
        self.assertEqual(content.description[:27], "")
        self.assertEqual(content.description_teaser[:26],
                         "A deux pas du centre ville")
        self.assertEqual(
            content.contact[:73],
            "<strong>Adresse :</strong><br>Rue de la Bruyère<br>28400 NOGENT-LE-ROTROU"
        )
        self.assertEqual(content.email, "*****@*****.**")
        self.assertEqual(content.website, "http://www.hotel-du-perche.com")
        self.assertEqual(round(content.geom.x), 537329)
        self.assertEqual(round(content.geom.y), 6805504)
        self.assertEqual(content.practical_info[:49],
                         "<strong>Langues parlées :</strong><br>Anglais<br>")
        self.assertIn("du 01/01/2019 au 21/07/2019", content.practical_info)
        self.assertIn("<strong>Équipements :</strong><br>Bar<br>Parking<br>",
                      content.practical_info)
        self.assertTrue(content.published)
        self.assertEqual(content.source.get(), source)
        self.assertEqual(content.portal.get(), portal)
        self.assertEqual(content.category, category)
        self.assertEqual(content.type1.get().label, "Hôtels")
        self.assertEqual(content.type2.get().label, "****")
        self.assertEqual(Attachment.objects.count(), 3)
        self.assertEqual(Attachment.objects.first().content_object, content)
Example #17
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())
Example #18
0
    def test_api_filters(self):
        SiteFactory.create(name='site1', published=False)
        SiteFactory.create(name='site2', published=True)
        site3 = SiteFactory.create(name='site3', published=True)
        site3.source.add(RecordSourceFactory.create(name='source1'))
        site3.portal.add(TargetPortalFactory.create(name='portal1'))

        response1 = self.client.get('/api/en/sites.json')
        self.assertEqual(len(response1.json()), 2)
        self.assertEqual(set((site['name'] for site in response1.json())),
                         set(('site2', 'site3')))

        response2 = self.client.get('/api/en/sites.json?source=source1')
        self.assertEqual(len(response2.json()), 1)
        self.assertEqual(response2.json()[0]['name'], 'site3')

        response3 = self.client.get('/api/en/sites.json?portal=portal1')
        self.assertEqual(len(response3.json()), 2)
        self.assertEqual(set((site['name'] for site in response3.json())),
                         set(('site2', 'site3')))

        response4 = self.client.get('/api/en/sites.json?portal=portalX')
        self.assertEqual(len(response4.json()), 1)
        self.assertEqual(response4.json()[0]['name'], 'site2')
Example #19
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())