Exemplo n.º 1
0
class DenormalizedTrailTest(AuthentFixturesTest):
    def setUp(self):
        self.trail1 = TrailFactory(no_path=True)
        self.trail2 = TrailFactory(no_path=True)
        self.path = PathFactory()
        self.trail1.add_path(self.path)
        self.trail2.add_path(self.path)

    def test_path_and_trails_are_linked(self):
        self.assertIn(self.trail1, self.path.trails.all())
        self.assertIn(self.trail2, self.path.trails.all())

    def login(self):
        user = PathManagerFactory(password='******')
        success = self.client.login(username=user.username, password='******')
        self.assertTrue(success)

    def test_denormalized_path_trails(self):
        PathFactory.create_batch(size=50)
        TrailFactory.create_batch(size=50)
        self.login()
        with self.assertNumQueries(LTE(15)):
            self.client.get(reverse('core:path_json_list'))

    def test_trails_are_shown_as_links_in_list(self):
        self.login()
        response = self.client.get(reverse('core:path_json_list'))
        self.assertEqual(response.status_code, 200)
        paths_json = json.loads(response.content)
        trails_column = paths_json['aaData'][0][4]
        self.assertTrue(trails_column == u'%s, %s' % (self.trail1.name_display, self.trail2.name_display) or
                        trails_column == u'%s, %s' % (self.trail2.name_display, self.trail1.name_display))
Exemplo n.º 2
0
class DenormalizedTrailTest(AuthentFixturesTest):
    def setUp(self):
        self.trail1 = TrailFactory(no_path=True)
        self.trail2 = TrailFactory(no_path=True)
        self.path = PathFactory()
        self.trail1.add_path(self.path)
        self.trail2.add_path(self.path)

    def test_path_and_trails_are_linked(self):
        self.assertIn(self.trail1, self.path.trails.all())
        self.assertIn(self.trail2, self.path.trails.all())

    def login(self):
        user = PathManagerFactory(password='******')
        success = self.client.login(username=user.username, password='******')
        self.assertTrue(success)

    def test_denormalized_path_trails(self):
        PathFactory.create_batch(size=50)
        TrailFactory.create_batch(size=50)
        self.login()
        with self.assertNumQueries(LTE(15)):
            self.client.get(reverse('core:path_json_list'))

    def test_trails_are_shown_as_links_in_list(self):
        self.login()
        response = self.client.get(reverse('core:path_json_list'))
        self.assertEqual(response.status_code, 200)
        paths_json = json.loads(response.content)
        trails_column = paths_json['aaData'][0][4]
        self.assertTrue(trails_column == u'%s, %s' % (self.trail1.name_display, self.trail2.name_display) or
                        trails_column == u'%s, %s' % (self.trail2.name_display, self.trail1.name_display))
Exemplo n.º 3
0
 def test_document_export(self, get_attributes_html):
     get_attributes_html.return_value = '<p>mock</p>'
     self.login()
     trail = TrailFactory()
     with open(trail.get_map_image_path(), 'w') as f:
         f.write('***' * 1000)
     response = self.client.get(trail.get_document_url())
     self.assertEqual(response.status_code, 200)
Exemplo n.º 4
0
 def test_document_export(self, get_attributes_html):
     get_attributes_html.return_value = '<p>mock</p>'
     trail = TrailFactory()
     self.login()
     with open(trail.get_map_image_path(), 'w') as f:
         f.write('***' * 1000)
     response = self.client.get(trail.get_document_url())
     self.assertEqual(response.status_code, 200)
Exemplo n.º 5
0
 def test_add_trail_from_existing_topology(self):
     self.login()
     trail = TrailFactory()
     form_data = self.get_good_data()
     form_data['topology'] = trail.serialize(with_pk=False)
     response = self.client.post(Trail.get_add_url(), form_data)
     self.assertEqual(response.status_code, 302)  # success, redirects to detail view
     p = re.compile(r"http://testserver/trail/(\d+)/")
     m = p.match(response['Location'])
     new_pk = int(m.group(1))
     new_trail = Trail.objects.get(pk=new_pk)
     self.assertIn(trail, new_trail.trails.all())
Exemplo n.º 6
0
 def test_add_trail_from_existing_topology(self):
     self.login()
     trail = TrailFactory()
     form_data = self.get_good_data()
     form_data['topology'] = trail.serialize(with_pk=False)
     response = self.client.post(Trail.get_add_url(), form_data)
     self.assertEqual(response.status_code, 302)  # success, redirects to detail view
     p = re.compile(r"/trail/(\d+)/")
     m = p.match(response['Location'])
     new_pk = int(m.group(1))
     new_trail = Trail.objects.get(pk=new_pk)
     self.assertIn(trail, new_trail.trails.all())
Exemplo n.º 7
0
 def test_delete_multiple_path(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     poi = POIFactory.create(no_path=True, name="POI_1")
     poi.add_path(path_1, start=0, end=0)
     infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1")
     infrastructure.add_path(path_1, start=0, end=1)
     signage = SignageFactory.create(no_path=True, name="SIGNA_1")
     signage.add_path(path_1, start=0, end=1)
     trail = TrailFactory.create(no_path=True, name="TRAIL_1")
     trail.add_path(path_2, start=0, end=1)
     service = ServiceFactory.create(no_path=True)
     service.add_path(path_2, start=0, end=1)
     InterventionFactory.create(topology=signage, name="INTER_1")
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertIn("POI_1", response.content)
     self.assertIn("INFRA_1", response.content)
     self.assertIn("SIGNA_1", response.content)
     self.assertIn("TRAIL_1", response.content)
     self.assertIn("ServiceType", response.content)
     self.assertIn("INTER_1", response.content)
     response = self.client.post(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(Path.objects.count(), 2)
     self.assertEqual(Path.objects.filter(pk__in=[path_1.pk, path_2.pk]).count(), 0)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 def test_delete_multiple_path(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     poi = POIFactory.create(no_path=True, name="POI_1")
     poi.add_path(path_1, start=0, end=0)
     infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1")
     infrastructure.add_path(path_1, start=0, end=1)
     signage = SignageFactory.create(no_path=True, name="SIGNA_1")
     signage.add_path(path_1, start=0, end=1)
     trail = TrailFactory.create(no_path=True, name="TRAIL_1")
     trail.add_path(path_2, start=0, end=1)
     service = ServiceFactory.create(no_path=True)
     service.add_path(path_2, start=0, end=1)
     InterventionFactory.create(topology=signage, name="INTER_1")
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertIn("POI_1", response.content)
     self.assertIn("INFRA_1", response.content)
     self.assertIn("SIGNA_1", response.content)
     self.assertIn("TRAIL_1", response.content)
     self.assertIn("ServiceType", response.content)
     self.assertIn("INTER_1", response.content)
     response = self.client.post(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(Path.objects.count(), 2)
     self.assertEqual(Path.objects.filter(pk__in=[path_1.pk, path_2.pk]).count(), 0)
Exemplo n.º 11
0
 def test_save_form_when_topology_has_not_changed(self):
     topo = TrailFactory()
     form = TrailForm(instance=topo)
     self.assertEqual(topo, form.instance)
     form.cleaned_data = {'topology': topo}
     form.save()
     self.assertEqual(topo, form.instance)
Exemplo n.º 12
0
    def test_trail_helpers(self):
        if not self.factory:
            return   # ignore abstract test
        t = TrailFactory.create()
        t2 = TrailFactory.create()

        self.assertEquals(len(getattr(t, self.helper_name)), 0)
        self.assertEquals(len(getattr(t2, self.helper_name)), 0)

        p = PathFactory.create(trail=t)
        l = self.factory.create(no_path=True)
        l.add_path(p)

        self.assertEquals(len(getattr(t, self.helper_name)), 1)
        self.assertEquals(len(getattr(t2, self.helper_name)), 0)

        self.assertEqual([o.pk for o in getattr(t, self.helper_name).all()],
                         [l.pk])
Exemplo n.º 13
0
    def setUp(self):
        super(TrailKmlGPXTest, self).setUp()
        self.user = UserFactory.create(is_staff=True, is_superuser=True)
        self.client.force_login(self.user)

        self.trail = TrailFactory.create(comments='exportable trail')

        self.gpx_response = self.client.get(reverse('core:trail_gpx_detail', args=('en', self.trail.pk, 'slug')))
        self.gpx_parsed = BeautifulSoup(self.gpx_response.content, 'lxml')

        self.kml_response = self.client.get(reverse('core:trail_kml_detail', args=('en', self.trail.pk, 'slug')))
Exemplo n.º 14
0
 def test_delete_multiple_path(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     POIFactory.create(paths=[(path_1, 0, 0)], name="POI_1")
     InfrastructureFactory.create(paths=[(path_1, 0, 1)], name="INFRA_1")
     signage = SignageFactory.create(paths=[(path_1, 0, 1)], name="SIGNA_1")
     TrailFactory.create(paths=[(path_2, 0, 1)], name="TRAIL_1")
     ServiceFactory.create(paths=[(path_2, 0, 1)])
     InterventionFactory.create(target=signage, name="INTER_1")
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertContains(response, "POI_1")
     self.assertContains(response, "INFRA_1")
     self.assertContains(response, "SIGNA_1")
     self.assertContains(response, "TRAIL_1")
     self.assertContains(response, "Service type")
     self.assertContains(response, "INTER_1")
     response = self.client.post(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(Path.objects.count(), 2)
     self.assertEqual(Path.objects.filter(pk__in=[path_1.pk, path_2.pk]).count(), 0)
Exemplo n.º 15
0
    def setUp(self):
        super(TrailKmlGPXTest, self).setUp()
        self.user = UserFactory.create(is_staff=True, is_superuser=True)
        self.client.force_login(self.user)

        self.trail = TrailFactory.create(comments='exportable trail')

        self.gpx_response = self.client.get(reverse('core:trail_gpx_detail', args=('en', self.trail.pk, 'slug')))
        self.gpx_parsed = BeautifulSoup(self.gpx_response.content, 'lxml')

        self.kml_response = self.client.get(reverse('core:trail_kml_detail', args=('en', self.trail.pk, 'slug')))
Exemplo n.º 16
0
    def test_add_trail_from_existing_topology_does_not_use_pk(self):
        import bs4

        self.login()
        trail = TrailFactory(offset=3.14)
        response = self.client.get(Trail.get_add_url() + '?topology=%s' % trail.pk)
        soup = bs4.BeautifulSoup(response.content)
        textarea_field = soup.find(id="id_topology")
        self.assertIn('"kind": "TOPOLOGY"', textarea_field.text)
        self.assertIn('"offset": 3.14', textarea_field.text)
        self.assertNotIn('"pk": %s' % trail.pk, textarea_field.text)
Exemplo n.º 17
0
 def test_trail_helpers(self):
     t = TrailFactory.create()
     self.assertEqual(0, len(t.interventions))
     
     p = PathFactory.create()
     t.paths.add(p)
     
     topo = TopologyFactory.create(no_path=True)
     topo.add_path(p)
     i = InterventionFactory(topology=topo)
     self.assertEqual(1, len(t.interventions))
     self.assertItemsEqual([i], t.interventions)
Exemplo n.º 18
0
    def test_trail_helpers(self):
        t = TrailFactory.create()
        self.assertEqual(0, len(t.interventions))

        p = PathFactory.create()
        t.paths.add(p)

        topo = TopologyFactory.create(no_path=True)
        topo.add_path(p)
        i = InterventionFactory(topology=topo)
        self.assertEqual(1, len(t.interventions))
        self.assertItemsEqual([i], t.interventions)
Exemplo n.º 19
0
class DenormalizedTrailTest(AuthentFixturesTest):
    def setUp(self):
        self.trail1 = TrailFactory(no_path=True)
        self.trail2 = TrailFactory(no_path=True)
        self.path = PathFactory()
        self.trail1.add_path(self.path)
        self.trail2.add_path(self.path)

    def test_path_and_trails_are_linked(self):
        self.assertIn(self.trail1, self.path.trails.all())
        self.assertIn(self.trail2, self.path.trails.all())

    def login(self):
        user = PathManagerFactory(password='******')
        success = self.client.login(username=user.username, password='******')
        self.assertTrue(success)

    def test_denormalized_path_trails(self):
        PathFactory.create_batch(size=50)
        TrailFactory.create_batch(size=50)
        self.login()
        with self.assertNumQueries(LTE(15)):
            self.client.get(reverse('core:path_json_list'))
Exemplo n.º 20
0
class DenormalizedTrailTest(AuthentFixturesTest):
    def setUp(self):
        self.trail1 = TrailFactory(no_path=True)
        self.trail2 = TrailFactory(no_path=True)
        self.path = PathFactory()
        self.trail1.add_path(self.path)
        self.trail2.add_path(self.path)

    def test_path_and_trails_are_linked(self):
        self.assertIn(self.trail1, self.path.trails.all())
        self.assertIn(self.trail2, self.path.trails.all())

    def login(self):
        user = PathManagerFactory(password='******')
        success = self.client.login(username=user.username, password='******')
        self.assertTrue(success)

    def test_denormalized_path_trails(self):
        PathFactory.create_batch(size=50)
        TrailFactory.create_batch(size=50)
        self.login()
        with self.assertNumQueries(LTE(15)):
            self.client.get(reverse('core:path_json_list'))
Exemplo n.º 21
0
 def setUp(self):
     self.trail1 = TrailFactory(no_path=True)
     self.trail2 = TrailFactory(no_path=True)
     self.path = PathFactory()
     self.trail1.add_path(self.path)
     self.trail2.add_path(self.path)
Exemplo n.º 22
0
 def setUp(self):
     self.path = PathFactory()
     self.trail1 = TrailFactory(paths=[self.path])
     self.trail2 = TrailFactory(paths=[self.path])
Exemplo n.º 23
0
 def test_detail_page(self):
     self.login()
     trail = TrailFactory()
     response = self.client.get(trail.get_detail_url())
     self.assertEqual(response.status_code, 200)
Exemplo n.º 24
0
 def test_denormalized_path_trails(self):
     PathFactory.create_batch(size=50)
     TrailFactory.create_batch(size=50)
     self.login()
     with self.assertNumQueries(LTE(15)):
         self.client.get(reverse('core:path_json_list'))
Exemplo n.º 25
0
 def setUp(self):
     self.trail1 = TrailFactory(no_path=True)
     self.trail2 = TrailFactory(no_path=True)
     self.path = PathFactory()
     self.trail1.add_path(self.path)
     self.trail2.add_path(self.path)
Exemplo n.º 26
0
 def setUp(self):
     self.path = PathFactory()
     self.trail = TrailFactory(paths=[(self.path, 0, 1)])
Exemplo n.º 27
0
 def test_trail_csv(self):
     p1 = PathFactory.create()
     t1 = TrailFactory.create(no_path=True)
     t1.add_path(p1)
     self.assertEqual(p1.trails_csv_display, t1.name)
Exemplo n.º 28
0
 def test_geom(self):
     t = TrailFactory.create()
     self.assertTrue(t.geom is None)
     p = PathFactory.create()
     t.paths.add(p)
     self.assertFalse(t.geom is None)
Exemplo n.º 29
0
 def test_trail_csv(self):
     p1 = PathFactory.create()
     t1 = TrailFactory.create(paths=[p1])
     self.assertEqual(p1.trails_csv_display, t1.name)
Exemplo n.º 30
0
 def test_detail_page(self):
     self.login()
     trail = TrailFactory()
     response = self.client.get(trail.get_detail_url())
     self.assertEqual(response.status_code, 200)
Exemplo n.º 31
0
 def test_geom(self):
     t = TrailFactory.create()
     self.assertTrue(t.geom is None)
     p = PathFactory.create()
     t.paths.add(p)
     self.assertFalse(t.geom is None)
Exemplo n.º 32
0
 def test_denormalized_path_trails(self):
     PathFactory.create_batch(size=50)
     TrailFactory.create_batch(size=50)
     self.login()
     with self.assertNumQueries(LTE(15)):
         self.client.get(reverse('core:path_json_list'))
Exemplo n.º 33
0
 def test_trail_csv(self):
     p1 = PathFactory.create()
     t1 = TrailFactory.create(no_path=True)
     t1.add_path(p1)
     self.assertEqual(p1.trails_csv_display, t1.name)