|
32 | 32 |
|
33 | 33 | from unittest.mock import patch |
34 | 34 | from urllib.parse import urlparse |
| 35 | +from pathlib import Path |
35 | 36 |
|
36 | 37 | from django.urls import reverse |
37 | 38 | from django.conf import settings |
|
42 | 43 |
|
43 | 44 | from guardian.shortcuts import get_anonymous_user |
44 | 45 |
|
45 | | -from geonode.assets.utils import create_asset_and_link |
| 46 | +from geonode.assets.utils import create_asset_and_link, get_default_asset |
46 | 47 | from geonode.base.forms import LinkedResourceForm |
47 | 48 | from geonode.maps.models import Map |
48 | 49 | from geonode.layers.models import Dataset |
@@ -194,6 +195,25 @@ def test_create_document_url_view(self): |
194 | 195 | d = Document.objects.get(title="GeoNode Map") |
195 | 196 | self.assertEqual(d.doc_url, "http://www.geonode.org/map.pdf") |
196 | 197 |
|
| 198 | + def test_uploaded_csv_with_uppercase_extension(self): |
| 199 | + """ |
| 200 | + The extension of the file should always be lowercase |
| 201 | + """ |
| 202 | + |
| 203 | + self.client.login(username="admin", password="admin") |
| 204 | + try: |
| 205 | + with open(os.path.join(os.path.dirname(__file__), "tests/data/test.CSV"), "rb") as f: |
| 206 | + data = {"title": "CSV with uppercase extension", "doc_file": f, "extension": "CSV"} |
| 207 | + self.client.post(reverse("document_upload"), data=data) |
| 208 | + d = Document.objects.get(title="CSV with uppercase extension") |
| 209 | + # verify that the extension is not lowercase |
| 210 | + self.assertEqual(d.extension, "csv") |
| 211 | + # be sure that also the file extension is not lowercase |
| 212 | + asset = get_default_asset(d) |
| 213 | + self.assertEqual(Path(asset.location[0]).suffix, ".csv") |
| 214 | + finally: |
| 215 | + Document.objects.filter(title="CSV with uppercase extension").delete() |
| 216 | + |
197 | 217 | def test_upload_document_form(self): |
198 | 218 | """ |
199 | 219 | Tests the Upload form. |
|
0 commit comments