def test_trek_child_as_parent(self): a = TrekFactory.create(name='A') b = TrekFactory.create(name='B', parent=a) c = TrekFactory.create(name='C', parent=b) self.assertRaisesMessage(ValidationError, u"Cannot use a a child trek as parent trek.", c.full_clean)
def test_gpx(self): trek = TrekFactory.create() trek = TrekFactory.create() url = reverse('trekking:trek_gpx_detail', kwargs={'pk': trek.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.content.count('<rte>'), 1) self.assertTrue(response.content.count('<rtept') >= 2)
def test_multilinestring(self): TrekFactory.create(geom=MultiLineString(LineString((0, 0), (0, 1)), LineString((100, 100), (100, 101)))) management.call_command('sync_mobile', 'tmp', url='http://localhost:8000', skip_tiles=True, skip_pdf=True, verbosity=0) for lang in settings.MODELTRANSLATION_LANGUAGES: with open(os.path.join('tmp', lang, 'treks.geojson'), 'r') as f: trek_geojson = json.load(f) self.assertEqual(len(trek_geojson['features']), Trek.objects.filter(**{'published_{}'.format(lang): True}).count())
def setUp(self): self.path = PathFactory.create( geom='SRID=2154;LINESTRING(200000 300000, 1100000 1200000)') if settings.TREKKING_TOPOLOGY_ENABLED: self.trek = TrekFactory.create(paths=[self.path], published=False) else: self.trek = TrekFactory.create( geom='SRID=2154;LINESTRING(200000 300000, 1100000 1200000)', published=False)
def setUp(self): profile = UserProfileFactory.create(user__username='******', user__password='******', language='en') self.user = profile.user self.user.groups.add(Group.objects.get(name=u"Référents communication")) self.client.login(username='******', password='******') self.content1 = TrekFactory.create() structure = StructureFactory.create() self.content2 = TrekFactory.create(structure=structure)
def test_detail_target_objects(self): self.login() if settings.TREKKING_TOPOLOGY_ENABLED: path = PathFactory.create(geom=LineString((200, 200), (300, 300))) signa = SignageFactory.create(paths=[(path, .5, .5)]) signa.save() infrastructure = InfrastructureFactory.create(paths=[(path, .5, .5)]) infrastructure.save() poi = POIFactory.create(paths=[(path, .5, .5)]) trek = TrekFactory.create(paths=[(path, .5, .5)]) service = ServiceFactory.create(paths=[(path, .5, .5)]) topo = TopologyFactory.create(paths=[(path, .5, .5)]) topo.save() path_other = PathFactory.create( geom=LineString((10000, 0), (10010, 0))) signa_other = SignageFactory.create(paths=[(path_other, .5, .5)]) signa_other.save() else: signa = SignageFactory.create(geom='SRID=2154;POINT (250 250)') infrastructure = InfrastructureFactory.create( geom='SRID=2154;POINT (250 250)') poi = POIFactory.create(geom='SRID=2154;POINT (250 250)') trek = TrekFactory.create(geom='SRID=2154;POINT (250 250)') service = ServiceFactory.create(geom='SRID=2154;POINT (250 250)') topo = TopologyFactory.create(geom='SRID=2154;POINT (250 250)') signa_other = SignageFactory.create( geom='SRID=2154;POINT (10005 0)') intervention_signa = InterventionFactory.create(target=signa) intervention_infra = InterventionFactory.create(target=infrastructure) intervention_poi = InterventionFactory.create(target=poi) intervention_trek = InterventionFactory.create(target=trek) intervention_service = InterventionFactory.create(target=service) intervention_topo = InterventionFactory.create(target=topo) blade = BladeFactory(signage=signa, number="1") intervention_blade = InterventionFactory.create(target=blade) intervention_other = InterventionFactory.create(target=signa_other) response = self.client.get(signa.get_detail_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, intervention_signa.target_display) self.assertContains(response, intervention_infra.target_display) self.assertContains(response, intervention_poi.target_display) self.assertContains(response, intervention_trek.target_display) self.assertContains(response, intervention_service.target_display) self.assertContains(response, intervention_blade.target_display) self.assertContains(response, intervention_topo.target_display) self.assertNotContains(response, intervention_other.target_display)
def setUp(self): testutil._MAX_LENGTH = 10000 creation = make_aware(datetime.datetime(2014, 1, 1), utc) self.trek = TrekFactory.create(published=True) self.trek.date_insert = creation self.trek.save() self.poi = POIFactory.create(published=True) self.poi.date_insert = creation self.poi.save() TrekFactory.create(published=False) POIFactory.create(published=False)
def get_good_data(self): path = PathFactory.create() return { 'name_fr': 'Huhu', 'name_en': 'Hehe', 'departure_fr': '', 'departure_en': '', 'arrival_fr': '', 'arrival_en': '', 'published': '', 'difficulty': '', 'route': '', 'description_teaser_fr': '', 'description_teaser_en': '', 'description_fr': '', 'description_en': '', 'ambiance_fr': '', 'ambiance_en': '', 'access_fr': '', 'access_en': '', 'disabled_infrastructure_fr': '', 'disabled_infrastructure_en': '', 'duration': '0', 'is_park_centered': '', 'advised_parking': 'Very close', 'parking_location': 'POINT (1.0 1.0)', 'public_transport': 'huhu', 'advice_fr': '', 'advice_en': '', 'themes': ThemeFactory.create().pk, 'networks': TrekNetworkFactory.create().pk, 'practice': '', 'accessibilities': AccessibilityFactory.create().pk, 'web_links': WebLinkFactory.create().pk, 'information_desks': tourism_factories.InformationDeskFactory.create().pk, 'topology': '{"paths": [%s]}' % path.pk, 'trek_relationship_a-TOTAL_FORMS': '2', 'trek_relationship_a-INITIAL_FORMS': '0', 'trek_relationship_a-MAX_NUM_FORMS': '', 'trek_relationship_a-0-id': '', 'trek_relationship_a-0-trek_b': TrekFactory.create().pk, 'trek_relationship_a-0-has_common_edge': 'on', 'trek_relationship_a-0-has_common_departure': 'on', 'trek_relationship_a-0-is_circuit_step': '', 'trek_relationship_a-1-id': '', 'trek_relationship_a-1-trek_b': TrekFactory.create().pk, 'trek_relationship_a-1-has_common_edge': '', 'trek_relationship_a-1-has_common_departure': '', 'trek_relationship_a-1-is_circuit_step': 'on', }
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())
def test_pois_is_not_ordered_by_progression(self): self.trek = TrekFactory.create(geom=LineString((0, 0), (8, 8))) self.trek_reverse = TrekFactory.create(geom=LineString((6.4, 6.4), (0.8, 0.8))) self.poi1 = POIFactory.create(geom=Point(3.2, 3.2)) self.poi2 = POIFactory.create(geom=Point(1.2, 1.2)) self.poi3 = POIFactory.create(geom=Point(4, 4)) pois = self.trek.pois self.assertCountEqual([self.poi1, self.poi2, self.poi3], pois) pois = self.trek_reverse.pois self.assertCountEqual([self.poi1, self.poi2, self.poi3], pois)
def test_treks_are_sorted_by_name(self): TrekFactory.create(name='Cb') TrekFactory.create(name='Ca') TrekFactory.create(name='A') TrekFactory.create(name='B') self.assertEqual([u'A', u'B', u'Ca', u'Cb'], list(Trek.objects.all().values_list('name', flat=True)))
def get_good_data(self): path = PathFactory.create() return { 'name_fr': 'Huhu', 'name_en': 'Hehe', 'departure_fr': '', 'departure_en': '', 'arrival_fr': '', 'arrival_en': '', 'published': '', 'difficulty': '', 'route': '', 'description_teaser_fr': '', 'description_teaser_en': '', 'description_fr': '', 'description_en': '', 'ambiance_fr': '', 'ambiance_en': '', 'access_fr': '', 'access_en': '', 'disabled_infrastructure_fr': '', 'disabled_infrastructure_en': '', 'duration': '0', 'is_park_centered': '', 'advised_parking': 'Very close', 'parking_location': 'POINT (1.0 1.0)', 'public_transport': 'huhu', 'advice_fr': '', 'advice_en': '', 'themes': ThemeFactory.create().pk, 'networks': TrekNetworkFactory.create().pk, 'usages': UsageFactory.create().pk, 'web_links': WebLinkFactory.create().pk, 'information_desks': InformationDeskFactory.create().pk, 'topology': '{"paths": [%s]}' % path.pk, 'trek_relationship_a-TOTAL_FORMS': '2', 'trek_relationship_a-INITIAL_FORMS': '0', 'trek_relationship_a-MAX_NUM_FORMS': '', 'trek_relationship_a-0-id': '', 'trek_relationship_a-0-trek_b': TrekFactory.create().pk, 'trek_relationship_a-0-has_common_edge': 'on', 'trek_relationship_a-0-has_common_departure': 'on', 'trek_relationship_a-0-is_circuit_step': '', 'trek_relationship_a-1-id': '', 'trek_relationship_a-1-trek_b': TrekFactory.create().pk, 'trek_relationship_a-1-has_common_edge': '', 'trek_relationship_a-1-has_common_departure': '', 'trek_relationship_a-1-is_circuit_step': 'on', }
def test_treks_are_sorted_by_name(self): TrekFactory.create(name='Cb') TrekFactory.create(name='Ca') TrekFactory.create(name='A') TrekFactory.create(name='B') self.assertQuerysetEqual(Trek.objects.all(), [u'<Trek: A>', u'<Trek: B>', u'<Trek: Ca>', u'<Trek: Cb>'], ordered=False)
def test_pois_should_be_ordered_by_progression(self): p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) p2 = PathFactory.create(geom=LineString((4, 4), (8, 8))) self.trek = TrekFactory.create(paths=[p1, p2]) self.trek_reverse = TrekFactory.create(paths=[(p2, 0.8, 0), (p1, 1, 0.2)]) self.poi1 = POIFactory.create(paths=[(p1, 0.8, 0.8)]) self.poi2 = POIFactory.create(paths=[(p1, 0.3, 0.3)]) self.poi3 = POIFactory.create(paths=[(p2, 0.5, 0.5)]) pois = self.trek.pois self.assertEqual([self.poi2, self.poi1, self.poi3], list(pois)) pois = self.trek_reverse.pois self.assertEqual([self.poi3, self.poi1, self.poi2], list(pois))
def test_treks_are_sorted_by_name(self): TrekFactory.create(name='Cb') TrekFactory.create(name='Ca') TrekFactory.create(name='A') TrekFactory.create(name='B') self.assertQuerysetEqual(Trek.objects.all(), ['<Trek: A>', '<Trek: B>', '<Trek: Ca>', '<Trek: Cb>'], ordered=False)
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())
def setUp(self): self.login() self.trek = TrekFactory.create() self.trek.points_reference = MultiPoint( [Point(0, 0), Point(1, 1)], srid=settings.SRID) self.trek.save()
def test_poi_geojson_translation(self): # Create a Trek with a POI trek = TrekFactory.create(no_path=True, published_fr=True, published_it=True) p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) poi = POIFactory.create(no_path=True) poi.name_fr = "Chapelle" poi.name_en = "Chapel" poi.name_it = "Capela" poi.published_fr = True poi.published_en = True poi.published_it = True poi.save() trek.add_path(p1, start=0.5) poi.add_path(p1, start=0.6, end=0.6) # Check that it applies to GeoJSON also : self.assertEqual(len(trek.pois), 1) poi = trek.pois[0] for lang, expected in [('fr', poi.name_fr), ('it', poi.name_it)]: url = '/api/{lang}/treks/{pk}/pois.geojson'.format(lang=lang, pk=trek.pk) self.login() response = self.client.get(url) self.assertEqual(response.status_code, 200) obj = json.loads(response.content) jsonpoi = obj.get('features', [])[0] self.assertEqual(jsonpoi.get('properties', {}).get('name'), expected) self.client.logout() # Django 1.6 keeps language in session
def test_helpers(self): p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) p2 = PathFactory.create(geom=LineString((4, 4), (8, 8))) trek = TrekFactory.create(paths=[(p1, 0.5, 1), (p2, 0, 1)]) poi = POIFactory.create(paths=[(p1, 0.6, 0.6)]) poi2 = POIFactory.create(paths=[(p1, 0.6, 0.6)]) service = ServiceFactory.create(paths=[(p1, 0.7, 0.7)]) service.type.practices.add(trek.practice) trek.pois_excluded.add(poi2.pk) # /!\ District are automatically linked to paths at DB level d1 = DistrictFactory.create(geom=MultiPolygon( Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2))))) # Ensure related objects are accessible self.assertCountEqual(trek.pois_excluded.all(), [poi2]) self.assertCountEqual(trek.all_pois, [poi, poi2]) self.assertCountEqual(trek.pois, [poi]) self.assertCountEqual(trek.services, [service]) self.assertCountEqual(poi.treks, [trek]) self.assertCountEqual(service.treks, [trek]) self.assertCountEqual(trek.districts, [d1]) # Ensure there is no duplicates self.assertCountEqual(trek.pois_excluded.all(), [poi2]) self.assertCountEqual(trek.all_pois, [poi, poi2]) self.assertCountEqual(trek.pois, [poi]) self.assertCountEqual(trek.services, [service]) self.assertCountEqual(poi.treks, [trek]) self.assertCountEqual(service.treks, [trek]) d2 = DistrictFactory.create(geom=MultiPolygon( Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3))))) self.assertCountEqual(trek.districts, [d1, d2])
def test_json_detail(self): trek = TrekFactory.create() self.information_desk = InformationDeskFactory.create() trek.information_desks.add(self.information_desk) url = reverse('trekking:trek_json_detail', kwargs={'pk': trek.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) detailjson = json.loads(response.content) self.assertDictEqual(detailjson['route'], {"id": trek.route.id, "pictogram": None, "label": trek.route.route}) self.assertDictEqual(detailjson['difficulty'], {"id": trek.difficulty.id, "pictogram": os.path.join(settings.MEDIA_URL, trek.difficulty.pictogram.name), "label": trek.difficulty.difficulty}) self.assertDictEqual(detailjson['information_desk'], detailjson['information_desks'][0]) self.assertDictEqual(detailjson['information_desks'][0], {u'description': u'<p>description 0</p>', u'email': u'*****@*****.**', u'latitude': -5.983593666147552, u'longitude': -1.3630761286186646, u'name': u'information desk name 0', u'phone': u'01 02 03 0', u'photo_url': self.information_desk.photo_url, u'postal_code': 28300, u'street': u'0 baker street', u'municipality': u"Bailleau L'évêque-0", u'website': u'http://makina-corpus.com/0'}) self.assertEqual(detailjson['information_desk_layer'], '/api/trek/%s/information_desks.geojson' % trek.pk) self.assertEqual(detailjson['filelist_url'], '/paperclip/get/trekking/trek/%s/' % trek.pk)
def test_deleted_pois(self): p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) trek = TrekFactory.create(paths=[p1]) poi = POIFactory.create(paths=[(p1, 0.6, 0.6)]) self.assertCountEqual(trek.pois, [poi]) poi.delete() self.assertCountEqual(trek.pois, [])
def test_deleted_services_nds(self): trek = TrekFactory.create(geom=LineString((0, 0), (4, 4))) service = ServiceFactory.create(geom=Point(2.4, 2.4)) service.type.practices.add(trek.practice) self.assertCountEqual(trek.services, [service]) service.delete() self.assertCountEqual(trek.services, [])
def test_tiles(self, mock_tileslist, mock_tiles): output = StringIO() 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_rando', os.path.join('var', 'tmp'), url='http://localhost:8000', verbosity=2, languages='en', stdout=output) zfile = zipfile.ZipFile( os.path.join('var', 'tmp', 'zip', 'tiles', 'global.zip')) for finfo in zfile.infolist(): ifile_global = zfile.open(finfo) if ifile_global.name.startswith('tiles/'): self.assertEqual(ifile_global.readline(), b'I am a png') zfile_trek = zipfile.ZipFile( os.path.join('var', 'tmp', 'zip', 'tiles', '{}.zip'.format(trek_multi.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("tiles/global.zip", output.getvalue()) self.assertIn("tiles/{pk}.zip".format(pk=trek_multi.pk), output.getvalue())
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)
def test_delete_show_topologies(self): self.login() path = PathFactory(name="PATH_AB", geom=LineString((0, 0), (4, 0))) poi = POIFactory.create(name='POI', no_path=True) poi.add_path(path, start=0.5, end=0.5) trail = TrailFactory.create(name='Trail', no_path=True) trail.add_path(path, start=0.1, end=0.2) trek = TrekFactory.create(name='Trek', no_path=True) trek.add_path(path, start=0.2, end=0.3) service = ServiceFactory.create(no_path=True, type__name='ServiceType') service.add_path(path, start=0.2, end=0.3) signage = SignageFactory.create(name='Signage', no_path=True) signage.add_path(path, start=0.2, end=0.2) infrastructure = InfrastructureFactory.create(name='Infrastructure', no_path=True) infrastructure.add_path(path, start=0.2, end=0.2) intervention1 = InterventionFactory.create(topology=signage, name='Intervention1') t = TopologyFactory.create(no_path=True) t.add_path(path, start=0.2, end=0.5) intervention2 = InterventionFactory.create(topology=t, name='Intervention2') response = self.client.get(path.get_delete_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Different topologies are linked with this path') self.assertContains(response, '<a href="/poi/%d/">POI</a>' % poi.pk) self.assertContains(response, '<a href="/trail/%d/">Trail</a>' % trail.pk) self.assertContains(response, '<a href="/trek/%d/">Trek</a>' % trek.pk) self.assertContains(response, '<a href="/service/%d/">ServiceType</a>' % service.pk) self.assertContains(response, '<a href="/signage/%d/">Signage</a>' % signage.pk) self.assertContains(response, '<a href="/infrastructure/%d/">Infrastructure</a>' % infrastructure.pk) self.assertContains(response, '<a href="/intervention/%d/">Intervention1</a>' % intervention1.pk) self.assertContains(response, '<a href="/intervention/%d/">Intervention2</a>' % intervention2.pk)
def test_profile_object_public_fail_no_profile(self): success = self.client.login(username=self.user.username, password='******') self.assertTrue(success) trek = TrekFactory.create(name='Trek', no_path=True, published=True) response = self.client.get('/media/profiles/trek-%s.png' % trek.pk) self.assertEqual(response.status_code, 200)
def setUp(self): self.trek = TrekFactory.create( no_path=True, points_reference=MultiPoint([Point(0, 0), Point(1, 1)], srid=settings.SRID), parking_location=Point(0, 0, srid=settings.SRID), )
def test_delete_cascade(self): p1 = PathFactory.create() p2 = PathFactory.create() t = TrekFactory.create(no_path=True) t.add_path(p1) t.add_path(p2) # Everything should be all right before delete self.assertTrue(t.published) self.assertFalse(t.deleted) self.assertEqual(t.aggregations.count(), 2) # When a path is deleted p1.delete() t = Trek.objects.get(pk=t.pk) self.assertFalse(t.published) self.assertFalse(t.deleted) self.assertEqual(t.aggregations.count(), 1) # Reset published status t.published = True t.save() # When all paths are deleted p2.delete() t = Trek.objects.get(pk=t.pk) self.assertFalse(t.published) self.assertTrue(t.deleted) self.assertEqual(t.aggregations.count(), 0)
def test_poi_geojson_translation(self): # Create a Trek with a POI trek = TrekFactory.create(no_path=True) p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) poi = POIFactory.create(no_path=True) poi.name_fr = "Chapelle" poi.name_en = "Chapel" poi.name_it = "Capela" poi.published_fr = True poi.published_en = True poi.published_it = True poi.save() trek.add_path(p1, start=0.5) poi.add_path(p1, start=0.6, end=0.6) # Check that it applies to GeoJSON also : self.assertEqual(len(trek.pois), 1) poi = trek.pois[0] for lang, expected in [('fr-FR', poi.name_fr), ('it-IT', poi.name_it)]: url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk}) self.login() response = self.client.get(url, HTTP_ACCEPT_LANGUAGE=lang) self.assertEqual(response.status_code, 200) obj = json.loads(response.content) jsonpoi = obj.get('features', [])[0] self.assertEqual(jsonpoi.get('properties', {}).get('name'), expected) self.client.logout() # Django 1.6 keeps language in session
def setUp(self): call_command('update_permissions') self.trek = TrekFactory.create(published=False) self.user = User.objects.create_user('omer', password='******') self.user.user_permissions.add(Permission.objects.get(codename='add_trek')) self.user.user_permissions.add(Permission.objects.get(codename='change_trek')) self.client.login(username='******', password='******')
def test_helpers(self): trek = TrekFactory.create(no_path=True) p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) p2 = PathFactory.create(geom=LineString((4, 4), (8, 8))) poi = POIFactory.create(no_path=True) PathAggregationFactory.create(topo_object=trek, path=p1, start_position=0.5) PathAggregationFactory.create(topo_object=trek, path=p2) PathAggregationFactory.create(topo_object=poi, path=p1, start_position=0.6, end_position=0.6) # /!\ District are automatically linked to paths at DB level d1 = DistrictFactory.create(geom=MultiPolygon( Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2))))) # Ensure related objects are accessible self.assertItemsEqual(trek.pois, [poi]) self.assertItemsEqual(poi.treks, [trek]) self.assertItemsEqual(trek.districts, [d1]) # Ensure there is no duplicates PathAggregationFactory.create(topo_object=trek, path=p1, end_position=0.5) self.assertItemsEqual(trek.pois, [poi]) self.assertItemsEqual(poi.treks, [trek]) d2 = DistrictFactory.create(geom=MultiPolygon( Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3))))) self.assertItemsEqual(trek.districts, [d1, d2])
def test_helpers(self): trek = TrekFactory.create(no_path=True) p1 = PathFactory.create(geom=LineString((0, 0, 0), (4, 4, 2))) p2 = PathFactory.create(geom=LineString((4, 4, 2), (8, 8, 4))) poi = POIFactory.create(no_path=True) PathAggregationFactory.create(topo_object=trek, path=p1, start_position=0.5) PathAggregationFactory.create(topo_object=trek, path=p2) PathAggregationFactory.create(topo_object=poi, path=p1, start_position=0.6, end_position=0.6) # /!\ District are automatically linked to paths at DB level d1 = DistrictFactory.create(geom=MultiPolygon( Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2))))) # Ensure related objects are accessible self.assertItemsEqual(trek.pois, [poi]) self.assertItemsEqual(poi.treks, [trek]) self.assertItemsEqual(trek.districts, [d1]) # Ensure there is no duplicates PathAggregationFactory.create(topo_object=trek, path=p1, end_position=0.5) self.assertItemsEqual(trek.pois, [poi]) self.assertItemsEqual(poi.treks, [trek]) d2 = DistrictFactory.create(geom=MultiPolygon( Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3))))) self.assertItemsEqual(trek.districts, [d1, d2])
def test_deleted_services(self): p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) trek = TrekFactory.create(paths=[p1]) service = ServiceFactory.create(paths=[(p1, 0.6, 0.6)]) service.type.practices.add(trek.practice) self.assertCountEqual(trek.services, [service]) service.delete() self.assertCountEqual(trek.services, [])
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)
def setUp(self): self.trek = TrekFactory.create() self.information_desk1 = tourism_factories.InformationDeskFactory.create() self.information_desk2 = tourism_factories.InformationDeskFactory.create(photo=None) self.information_desk3 = tourism_factories.InformationDeskFactory.create() self.trek.information_desks.add(self.information_desk1) self.trek.information_desks.add(self.information_desk2) self.url = reverse('trekking:trek_information_desk_geojson', kwargs={'pk': self.trek.pk})
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())
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()
def test_any_published_property(self): t = TrekFactory.create(published=False) t.published_fr = False t.published_it = False t.save() self.assertFalse(t.any_published) t.published_it = True t.save() self.assertTrue(t.any_published)
def test_deleted_pois(self): p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) trek = TrekFactory.create(no_path=True) trek.add_path(p1) poi = POIFactory.create(no_path=True) poi.add_path(p1, start=0.6, end=0.6) self.assertItemsEqual(trek.pois, [poi]) poi.delete() self.assertItemsEqual(trek.pois, [])
def test_trek_itself_as_parent(self): """ Test if a trek it is its own parent """ trek1 = TrekFactory.create(name='trek1') OrderedTrekChild.objects.create(parent=trek1, child=trek1) self.assertRaisesMessage(ValidationError, u"Cannot use itself as child trek.", trek1.full_clean)
def test_geojson_translation(self): trek = TrekFactory.create(name='Voie lactee') trek.name_it = 'Via Lattea' trek.save() url = reverse('trekking:trek_layer') # Test with another language response = self.client.get(url, HTTP_ACCEPT_LANGUAGE='it-IT') obj = json.loads(response.content) self.assertEqual(obj['features'][0]['properties']['name'], trek.name_it)
def test_no_template_odt(self, mock_get_template): self.login_as_superuser() request = RequestFactory().get('/fake-path') request.user = self.superuser request.session = {} trek = TrekFactory.create() view = TrekDocument.as_view() with self.assertRaises(TemplateDoesNotExist): view(request, pk=trek.pk, slug=trek.slug)
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)
def test_published_status(self): t = TrekFactory.create(published=False) t.published_fr = False t.published_it = True t.save() self.assertEqual(t.published_status, [ {'lang': 'en', 'language': 'English', 'status': False}, {'lang': 'es', 'language': 'Spanish', 'status': False}, {'lang': 'fr', 'language': 'French', 'status': False}, {'lang': 'it', 'language': 'Italian', 'status': True}])
def test_get_elevation_chart_none(self): trek = TrekFactory.create(no_path=True, published=True) response = self.client.get('/media/profiles/trek-%s.png' % trek.pk) self.assertEqual(response.status_code, 200) # In PDF trek.get_elevation_chart_path() basefolder = os.path.join(settings.MEDIA_ROOT, 'profiles') self.assertTrue(os.listdir(basefolder)) directory = os.listdir(basefolder) self.assertIn('%s-%s-%s.png' % (Trek._meta.model_name, str(trek.pk), get_language()), directory)
def test_deleted_services(self): p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) trek = TrekFactory.create(no_path=True) trek.add_path(p1) service = ServiceFactory.create(no_path=True) service.type.practices.add(trek.practice) service.add_path(p1, start=0.6, end=0.6) self.assertItemsEqual(trek.services, [service]) service.delete() self.assertItemsEqual(trek.services, [])
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())
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)
def test_city_departure(self): trek = TrekFactory.create(no_path=True) p1 = PathFactory.create(geom=LineString((0, 0), (5, 5))) trek.add_path(p1) self.assertEqual(trek.city_departure, '') city1 = CityFactory.create(geom=MultiPolygon(Polygon(((-1, -1), (3, -1), (3, 3), (-1, 3), (-1, -1))))) city2 = CityFactory.create(geom=MultiPolygon(Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3))))) self.assertEqual(trek.cities, [city1, city2]) self.assertEqual(trek.city_departure, unicode(city1))
def test_elevation(self): trek = TrekFactory.create(no_path=True) p1 = PathFactory.create(geom=LineString((1, 0, 1), (0, 0, 1), (0, 1, 1))) p2 = PathFactory.create(geom=LineString((0, 1, 1), (1, 1, 1), (1, 2, 2))) PathAggregationFactory.create(topo_object=trek, path=p1, start_position=0.5) PathAggregationFactory.create(topo_object=trek, path=p2) trek = Trek.objects.get(pk=trek.pk) # reload to get computed fields actual_profile = trek.elevation_profile expected_profile = ((0, 1), (1, 1), (2, 1), (2 + 2 ** 0.5, 2)) self.assertItemsEqual(actual_profile, expected_profile)
def test_pois_should_be_ordered_by_progression(self): p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) p2 = PathFactory.create(geom=LineString((4, 4), (8, 8))) self.trek = TrekFactory.create(no_path=True) self.trek.add_path(p1) self.trek.add_path(p2, order=1) self.trek_reverse = TrekFactory.create(no_path=True) self.trek_reverse.add_path(p2, start=0.8, end=0, order=0) self.trek_reverse.add_path(p1, start=1, end=0.2, order=1) self.poi1 = POIFactory.create(no_path=True) self.poi1.add_path(p1, start=0.8, end=0.8) self.poi2 = POIFactory.create(no_path=True) self.poi2.add_path(p1, start=0.3, end=0.3) self.poi3 = POIFactory.create(no_path=True) self.poi3.add_path(p2, start=0.5, end=0.5) pois = self.trek.pois self.assertEqual([self.poi2, self.poi1, self.poi3], list(pois)) pois = self.trek_reverse.pois self.assertEqual([self.poi3, self.poi1, self.poi2], list(pois))
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)
def test_tiles_with_treks(self, mock_tileslist, mock_tiles, mock_prepare): output = BytesIO() trek = TrekFactory.create(published=True) management.call_command('sync_rando', 'tmp', url='http://localhost:8000', verbosity=2, stdout=output) zfile = zipfile.ZipFile(os.path.join('tmp', 'zip', 'tiles', 'global.zip')) for finfo in zfile.infolist(): ifile = zfile.open(finfo) self.assertEqual(ifile.readline(), 'I am a png') self.assertIn("zip/tiles/global.zip", output.getvalue()) zfile_trek = zipfile.ZipFile(os.path.join('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.readline(), 'I am a png') self.assertIn("zip/tiles/{pk}.zip".format(pk=trek.pk), output.getvalue())