def replace_legend(): # Probably enough to just clear the rainapp template, since django's delete # Will be cascading. sts = ShapeTemplate.objects.filter(name='Rainapp') for st in sts: st.delete() st = ShapeTemplate(name='Rainapp', id_field='Id field (unused)', name_field='Name field (unused)',) st.save() slc = ShapeLegendClass(descriptor='Rainapp', shape_template=st, value_field='Value field (unused)',) slc.save() legend_props = [ {'color': '8e36ed', 'index': 1, 'label': u'>=25', 'max_value': u'', 'min_value': u'25'}, {'color': 'ac25a5', 'index': 2, 'label': u'>=10', 'max_value': u'25', 'min_value': u'10'}, {'color': 'd21450', 'index': 3, 'label': u'>=5', 'max_value': u'10', 'min_value': u'5'}, {'color': 'fe0002', 'index': 4, 'label': u'>=2', 'max_value': u'5', 'min_value': u'2'}, {'color': '0001fe', 'index': 5, 'label': u'>=1', 'max_value': u'2', 'min_value': u'1'}, {'color': '374cff', 'index': 6, 'label': u'>=0,1', 'max_value': u'1', 'min_value': u'0.1'}, {'color': '7294ff', 'index': 7, 'label': u'>=0,05', 'max_value': u'0.1', 'min_value': u'0.05'}, {'color': 'abdfff', 'index': 8, 'label': u'>=0,01', 'max_value': u'0.05', 'min_value': u'0.01'}, {'color': 'ffffff', 'index': 9, 'label': u'>=0', 'max_value': u'0.01', 'min_value': u'0'}, {'color': '000000', 'index': 10, 'label': u'Geen data', 'max_value': u'-0.5', 'min_value': u'-1.5'}, ] slsc_kwargs = {'shape_legend_class': slc} for p in legend_props: p['color_inside'] = p['color'] slsc_kwargs.update(p) ShapeLegendSingleClass(**slsc_kwargs).save()
def setUp(self): """ One can make a shape template. The shape template contains fields for id, name and legend info. """ self.shape = Shape.objects.all()[0] self.shape_template = ShapeTemplate( name='test_template', id_field='mock_id_field', name_field='mock_name_field') self.shape_template.save()
class ModelShapeTest(TestCase): fixtures = ['lizard_shape_test'] def setUp(self): """ One can make a shape template. The shape template contains fields for id, name and legend info. """ self.shape = Shape.objects.all()[0] self.shape_template = ShapeTemplate( name='test_template', id_field='mock_id_field', name_field='mock_name_field') self.shape_template.save() def test_shape(self): """ The fixture has a correctly defined Shape object. """ self.shape.save() def test_shape2(self): """ Check if wrong extension would allow you to save. """ self.shape.shp_file.name = 'oeloebloe.txt' self.assertRaises(ShapeNameError, self.shape.save) def test_shape3(self): """ Check if wrong extension would allow you to save. """ self.shape.dbf_file.name = 'oeloebloe.txt' self.assertRaises(ShapeNameError, self.shape.save) def test_shape4(self): """ Check if wrong extension would allow you to save. """ self.shape.shx_file.name = 'oeloebloe.txt' self.assertRaises(ShapeNameError, self.shape.save) def test_shape5(self): """ Check if wrong extension would allow you to save. """ self.shape.prj_file.name = 'oeloebloe.txt' self.assertRaises(ShapeNameError, self.shape.save) def test_shape6(self): """ Check if inconsistent filenames would allow you to save. """ self.shape.shp_file.name = 'oeloebloe.shp' self.assertRaises(ShapeNameError, self.shape.save) def test_timeseries(self): """ There is not his-file associated with the shape. """ self.assertEquals(self.shape.timeseries('asdf'), []) def test_shapelegend(self): """ Make a shape legend. """ shape_legend = ShapeLegend( shape_template=self.shape_template, value_field='mock_value_field') shape_legend.save() # MUST use a saved shape_legend. shape_legend.adapter_layer_json(self.shape) def test_shapelegendpoint(self): """ Make a shape legend. """ shape_legend_point = ShapeLegendPoint( shape_template=self.shape_template, value_field='mock_value_field') shape_legend_point.save() # MUST use a saved shape_legend. shape_legend_point.adapter_layer_json(self.shape) def test_shapelegendclass_mapnik(self): """ Test mapnik output of shapelegendclass """ slc = ShapeLegendClass.objects.all()[0] slc.mapnik_style()