|
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 |
|
41 | 42 |
|
42 | 43 | from guardian.shortcuts import get_anonymous_user |
43 | 44 |
|
44 | | -from geonode.assets.utils import create_asset_and_link |
| 45 | +from geonode.assets.utils import create_asset_and_link, get_default_asset |
45 | 46 | from geonode.maps.models import Map |
46 | 47 | from geonode.compat import ensure_string |
47 | 48 | from geonode.base.enumerations import SOURCE_TYPE_REMOTE |
|
56 | 57 | from geonode.upload.api.exceptions import FileUploadLimitException |
57 | 58 |
|
58 | 59 | from .forms import DocumentCreateForm |
| 60 | +from geonode.security.registry import permissions_registry |
59 | 61 |
|
60 | 62 |
|
61 | 63 | TEST_GIF = os.path.join(os.path.dirname(__file__), "tests/data/img.gif") |
@@ -189,6 +191,25 @@ def test_create_document_url_view(self): |
189 | 191 | d = Document.objects.get(title="GeoNode Map") |
190 | 192 | self.assertEqual(d.doc_url, "http://www.geonode.org/map.pdf") |
191 | 193 |
|
| 194 | + def test_uploaded_csv_with_uppercase_extension(self): |
| 195 | + """ |
| 196 | + The extension of the file should always be lowercase |
| 197 | + """ |
| 198 | + |
| 199 | + self.client.login(username="admin", password="admin") |
| 200 | + try: |
| 201 | + with open(os.path.join(os.path.dirname(__file__), "tests/data/test.CSV"), "rb") as f: |
| 202 | + data = {"title": "CSV with uppercase extension", "doc_file": f, "extension": "CSV"} |
| 203 | + self.client.post(reverse("document_upload"), data=data) |
| 204 | + d = Document.objects.get(title="CSV with uppercase extension") |
| 205 | + # verify that the extension is not lowercase |
| 206 | + self.assertEqual(d.extension, "csv") |
| 207 | + # be sure that also the file extension is not lowercase |
| 208 | + asset = get_default_asset(d) |
| 209 | + self.assertEqual(Path(asset.location[0]).suffix, ".csv") |
| 210 | + finally: |
| 211 | + Document.objects.filter(title="CSV with uppercase extension").delete() |
| 212 | + |
192 | 213 | def test_upload_document_form(self): |
193 | 214 | """ |
194 | 215 | Tests the Upload form. |
@@ -397,8 +418,8 @@ def test_set_document_permissions(self): |
397 | 418 | self.assertFalse(self.anonymous_user.has_perm("view_resourcebase", document.get_self_resource())) |
398 | 419 |
|
399 | 420 | # Test that previous permissions for users other than ones specified in |
400 | | - # the perm_spec (and the document owner) were removed |
401 | | - current_perms = document.get_all_level_info() |
| 421 | + # the perm_spec (and the document owner) were |
| 422 | + current_perms = permissions_registry.get_perms(instance=document) |
402 | 423 | self.assertEqual(len(current_perms["users"]), 1) |
403 | 424 |
|
404 | 425 | # Test that the User permissions specified in the perm_spec were |
|
0 commit comments