def test_property_enum_are_casted(self): prop_1 = CrudViewProperty.objects.create(view=self.view_1, key="age2", json_schema={ 'type': "integer", "title": "Age" }) prop_2 = CrudViewProperty.objects.create(view=self.view_1, key="height2", json_schema={ 'type': "number", "title": "Height" }) PropertyEnum.objects.create(value="1", property=prop_1) PropertyEnum.objects.create(value="2", property=prop_1) PropertyEnum.objects.create(value="1.1", property=prop_2) PropertyEnum.objects.create(value="2", property=prop_2) sync_ui_schema(self.view_1) sync_layer_schema(self.view_1) response = self.client.get( reverse('crudview-detail', args=(self.view_1.pk, ))) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() self.assertListEqual( sorted(data['form_schema']['properties']['age2']['enum']), sorted([1, 2])) self.assertListEqual( sorted(data['form_schema']['properties']['height2']['enum']), sorted([1.1, 2]))
def setUp(self) -> None: self.view = CrudViewFactory() self.prop_name = CrudViewProperty.objects.create(view=self.view, key="name", required=True, json_schema={ 'type': "string", "title": "Name" }) self.prop_age = CrudViewProperty.objects.create(view=self.view, key="age", json_schema={ 'type': "integer", "title": "Age" }) self.prop_country = CrudViewProperty.objects.create(view=self.view, key="country", json_schema={ 'type': "string", "title": "Country" }) sync_layer_schema(self.view) sync_ui_schema(self.view) self.feature = Feature.objects.create(layer=self.view.layer, geom='POINT(0 0)', properties={ "name": None, "age": 15, "country": "Country" })
def setUp(self) -> None: self.crud_view = factories.CrudViewFactory() models.CrudViewProperty.objects.create(view=self.crud_view, key="date_start", required=True, json_schema={ 'type': "string", "title": "Date start", "format": "date" }) models.CrudViewProperty.objects.create(view=self.crud_view, key="date_end", required=True, json_schema={ 'type': "string", "title": "Date end", "format": "date" }) self.feature = Feature.objects.create(geom='POINT(0 0)', properties={ "date_start": "test", "date_end": "2020-12-10" }, layer=self.crud_view.layer) sync_layer_schema(self.crud_view) sync_ui_schema(self.crud_view) self.serializer = CrudFeatureDetailSerializer(self.feature)
def setUp(self) -> None: self.view = CrudViewFactory() self.prop_name = CrudViewProperty.objects.create(view=self.view, key="name", required=True, json_schema={ 'type': "string", "title": "Name" }, include_in_tile=True) self.prop_age = CrudViewProperty.objects.create(view=self.view, key="age", json_schema={ 'type': "integer", "title": "Age" }) self.prop_country = CrudViewProperty.objects.create(view=self.view, key="country", json_schema={ 'type': "string", "title": "Country" }) sync_layer_schema(self.view) sync_ui_schema(self.view) sync_properties_in_tiles(self.view)
def test_value_is_removed_if_property_deleted(self): self.prop_age.delete() sync_layer_schema(self.view) sync_ui_schema(self.view) self.feature.refresh_from_db() self.assertIn('age', self.feature.properties) clean_properties_not_in_schema_or_null(self.view) self.feature.refresh_from_db() self.assertNotIn('age', self.feature.properties)
def test_json_schema(self): prop_country = CrudViewProperty.objects.create(view=self.view_1, key="country", json_schema={ 'type': "string", "title": "Country" }) prop_themes = CrudViewProperty.objects.create(view=self.view_1, key="themes", json_schema={ 'type': "array", "items": { "type": "string" } }) PropertyEnum.objects.create(value="France", property=prop_country) PropertyEnum.objects.create(value="Spain", property=prop_country) PropertyEnum.objects.create(value="Theme 1", property=prop_themes) PropertyEnum.objects.create(value="Theme 2", property=prop_themes) sync_ui_schema(self.view_1) sync_layer_schema(self.view_1) response = self.client.get( reverse('crudview-detail', args=(self.view_1.pk, ))) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() self.assertDictEqual( data['form_schema'], { 'properties': { 'country': { 'enum': ['Spain', 'France'], 'title': 'Country', 'type': 'string' }, "themes": { "type": "array", "items": { "type": "string", "enum": ["Theme 2", "Theme 1"] } } }, 'required': [] })
def setUp(self) -> None: self.crud_view = factories.CrudViewFactory() models.CrudViewProperty.objects.create(view=self.crud_view, key="date_start", required=True, json_schema={ 'type': "string", "title": "Date start", "format": "date" }) models.CrudViewProperty.objects.create(view=self.crud_view, key="date_end", required=True, json_schema={ 'type': "string", "title": "Date end", "format": "date" }) models.CrudViewProperty.objects.create( view=self.crud_view, key="not_editable", required=False, editable=False, json_schema={ 'type': "string", "title": "Not editable", }, ) prop_with_values = models.CrudViewProperty.objects.create( view=self.crud_view, key="type", required=False, editable=False, json_schema={ 'type': "string", "title": "Type", }, ) prop_with_array_values = models.CrudViewProperty.objects.create( view=self.crud_view, key="types", required=False, editable=False, json_schema={ "type": "array", "items": { "type": "string", "enum": ['multi_type_3', 'multi_type_4'] }, "title": "Types" }) PropertyEnum.objects.create(value='type_1', pictogram=ContentFile(SMALL_PICTURE, name='test.png'), property=prop_with_values) PropertyEnum.objects.create(value='multi_type_1', pictogram=ContentFile(SMALL_PICTURE, name='test.png'), property=prop_with_array_values) PropertyEnum.objects.create(value='multi_type_2', pictogram=ContentFile(SMALL_PICTURE, name='test.png'), property=prop_with_array_values) PropertyEnum.objects.create(value='multi_type_5', property=prop_with_array_values) self.feature = Feature.objects.create(geom='POINT(0 0)', properties={ "date_start": "test", "date_end": "2020-12-10", "type": "type_1", "types": [ 'multi_type_1', 'multi_type_2', 'multi_type_3', 'multi_type_4', 'multi_type_5' ] }, layer=self.crud_view.layer) sync_layer_schema(self.crud_view) sync_ui_schema(self.crud_view) self.serializer = CrudFeatureDetailSerializer(self.feature)
def setUpTestData(cls): cls.crud_view = factories.CrudViewFactory() sync_layer_schema(cls.crud_view) sync_ui_schema(cls.crud_view)