def test_length_auto(self): # Line intervention has auto length from topology interv = InfrastructureInterventionFactory.create() interv.length = 3.14 interv.save() self.assertNotEqual(interv.length, 3.14) # Point intervention has manual length interv = InfrastructurePointInterventionFactory.create() interv.length = 3.14 interv.save() self.assertEqual(interv.length, 3.14)
def test_infrastructure_display_shows_infrastructure_name(self): interv = InfrastructureInterventionFactory.create() self.assertIn('Infrastructure', interv.infrastructure_display) self.assertIn('infrastructure-16.png', interv.infrastructure_display) name = interv.infrastructure.name self.assertIn(name, interv.infrastructure_display) interv = SignageInterventionFactory.create() self.assertIn('Signage', interv.infrastructure_display) self.assertIn('signage-16.png', interv.infrastructure_display) name = interv.infrastructure.name self.assertIn(name, interv.infrastructure_display)
def test_update_infrastructure(self): self.login() target_year = 2017 if settings.TREKKING_TOPOLOGY_ENABLED: intervention = InfrastructureInterventionFactory.create() else: intervention = InfrastructureInterventionFactory.create(geom='SRID=2154;POINT (700000 6600000)') infra = intervention.target # Save infrastructure form response = self.client.get(infra.get_update_url()) form = response.context['form'] data = form.initial data['name'] = 'modified' data['implantation_year'] = target_year if settings.TREKKING_TOPOLOGY_ENABLED: data['topology'] = '{"paths": [%s]}' % PathFactory.create().pk else: data['geom'] = 'SRID=4326;POINT (2.0 6.6)' response = self.client.post(infra.get_update_url(), data) self.assertEqual(response.status_code, 302) intervention = Intervention.objects.first() self.assertFalse(intervention.deleted) self.assertEqual(intervention.target.name, 'modified') self.assertEqual(intervention.target.implantation_year, target_year)
def test_update_infrastruture(self): self.login() intervention = InfrastructureInterventionFactory.create() infra = intervention.infrastructure # Save infrastructure form response = self.client.get(infra.get_update_url()) form = response.context['form'] data = form.initial data['name'] = 'modified' data['topology'] = '{"paths": [%s]}' % PathFactory.create().pk response = self.client.post(infra.get_update_url(), data) self.assertEqual(response.status_code, 302) # Check that intervention was not deleted (bug #783) intervention.reload() self.assertFalse(intervention.deleted) self.assertEqual(intervention.infrastructure.name, 'modified')
def test_area_auto(self): # Line interv = InfrastructureInterventionFactory.create(width=10.0) interv.reload() self.assertAlmostEqual(interv.area, interv.length * 10.0) # Points interv = InfrastructurePointInterventionFactory.create() interv.reload() self.assertEqual(interv.length, 0.0) self.assertEqual(interv.area, 0.0) interv = InfrastructurePointInterventionFactory.create(length=50, width=10.0) interv.reload() self.assertEqual(interv.area, 500) interv = InfrastructurePointInterventionFactory.create(width=0.5, length=0.5) interv.reload() self.assertEqual(interv.area, 0.25) interv = InfrastructurePointInterventionFactory.create(width=0.5) interv.reload() self.assertEqual(interv.area, 0.0)
def test_area_auto(self): # Line interv = InfrastructureInterventionFactory.create(width=10.0) interv.reload() self.assertEqual(interv.area, interv.length * 10.0) # Points interv = InfrastructurePointInterventionFactory.create() interv.reload() self.assertEqual(interv.length, 0.0) self.assertEqual(interv.area, 0.0) interv = InfrastructurePointInterventionFactory.create(length=50, width=10.0) interv.reload() self.assertEqual(interv.area, 500) interv = InfrastructurePointInterventionFactory.create(width=0.5, length=0.5) interv.reload() self.assertEqual(interv.area, 0.25) interv = InfrastructurePointInterventionFactory.create(width=0.5) interv.reload() self.assertEqual(interv.area, 0.0)
def test_no_html_in_csv(self): InfrastructureInterventionFactory.create() super(InterventionViewsTest, self).test_no_html_in_csv()
def setUp(self): InfrastructureInterventionFactory.create(date=datetime(2012, 11, 10)) InfrastructureInterventionFactory.create(date=datetime(1932, 11, 10)) self.filter = InterventionFilterSet() self.widget = self.filter.filters['year'].field.widget
def test_new_interventions_appear_dynamically(self): InfrastructureInterventionFactory.create(date=datetime(2024, 11, 10)) output = self.widget.render(name='year', value=None) self.assertEqual(output.count('<option'), 4) self.assertIn('>2024<', output)
def test_no_html_in_csv_infrastructure(self): if settings.TREKKING_TOPOLOGY_ENABLED: InfrastructureInterventionFactory.create() else: InfrastructureInterventionFactory.create(geom='SRID=2154;POINT (700000 6600000)') super(InterventionViewsTest, self).test_no_html_in_csv()