def test_save_empty_schema(bommen_schema_json, django_assert_num_queries): """Prove that the dataset table models are created on save.""" dataset = Dataset(name="empty", schema_data="") with django_assert_num_queries(1): dataset.save() assert dataset.tables.count() == 0
def test_save_schema_tables_add(bommen_schema_json): """Prove that the dataset table models are created on save.""" dataset = Dataset(name="testing", schema_data=bommen_schema_json) dataset.save() assert dataset.tables.count() == 1, dataset.tables.all() table = dataset.tables.get() assert table.name == "bommen" assert table.db_table == "bommen_bommen" assert table.enable_geosearch is True
def test_save_schema_tables_with_geometry_type(bommen_schema_json): """Prove that the dataset table models are created with geosearch field type set to schema.""" bommen_schema_json["tables"][0]["schema"]["properties"]["geometry"][ "$ref"] = "https://geojson.org/schema/Point.json" dataset = Dataset(name="testing", schema_data=bommen_schema_json) dataset.save() assert dataset.tables.count() == 1, dataset.tables.all() table = dataset.tables.get() assert table.name == "bommen" assert table.db_table == "bommen_bommen" assert table.geometry_field == "geometry" assert table.geometry_field_type == "Point"
def test_save_schema_tables_with_disabled_geosearch(settings, bommen_schema_json): """Prove that the dataset table models are created with geosearch disabled if dataset.name in settings.AMSTERDAM_SCHEMA['geosearch_disabled_datasets].""" settings.AMSTERDAM_SCHEMA["geosearch_disabled_datasets"] = ["bommen"] dataset = Dataset(name="bommen", schema_data=bommen_schema_json) dataset.save() assert dataset.tables.count() == 1, dataset.tables.all() table = dataset.tables.get() assert table.name == "bommen" assert table.db_table == "bommen_bommen" assert table.enable_geosearch is False
def geometry_zoom_things(geometry_zoom_schema, dynamic_models): Dataset.create_for_schema(schema=geometry_zoom_schema) model = dynamic_models["geometry_zoom"]["things"] model.objects.create( id=1, geometry=Point(10, 10), max_zoom=4, ) model.objects.create( id=2, geometry=Point(11, 11), max_zoom=6, )
def test_save_schema_tables_delete(bommen_schema_json): """Prove that the dataset table models are created on save.""" dataset = Dataset(name="bommen", schema_data=bommen_schema_json) dataset.save() assert dataset.tables.count() == 1 dataset.schema_data = { "id": "bommen", "type": "dataset", "title": "", "version": "0.0.1", "crs": "EPSG:28992", "tables": [], # removed tables } dataset.save() assert dataset.tables.count() == 0
def geometry_authdataset_dataset(geometry_authdataset_schema): return Dataset.create_for_schema(schema=geometry_authdataset_schema)
def bommen_v2_dataset(bommen_v2_schema) -> Dataset: return Dataset.create_for_schema(schema=bommen_v2_schema)
def test_save_blocks_invalid_json(): """Prove that invalid JSON won't be stored in the database.""" dataset = Dataset(name="foobar", schema_data="NOT_JSON") with pytest.raises(RuntimeError): dataset.save()