Skip to content

Commit

Permalink
Fix proxy tag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed May 31, 2021
1 parent 594c320 commit f39a70c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
45 changes: 26 additions & 19 deletions geonode/proxy/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from geonode.proxy.templatetags.proxy_lib_tags import original_link_available
from django.test.client import RequestFactory
from mock import patch
from geonode.upload.models import Upload, UploadFile
from geonode.upload.models import Upload
import json
from django.core.files.uploadedfile import SimpleUploadedFile

Expand Down Expand Up @@ -154,20 +154,25 @@ def test_download_url_with_not_existing_file(self):
@on_ogc_backend(geoserver.BACKEND_PACKAGE)
def test_download_url_with_existing_files(self, fopen, fexists):
fexists.return_value = True
fopen.return_value = SimpleUploadedFile('file.shp', b'scc')
fopen.return_value = SimpleUploadedFile('foo_file.shp', b'scc')
layer = Layer.objects.all().first()

layer.files = {
".dbf": "/tmpe1exb9e9/foo_file.dbf",
".prj": "/tmpe1exb9e9/foo_file.prj",
".shp": "/tmpe1exb9e9/foo_file.shp",
".shx": "/tmpe1exb9e9/foo_file.shx"
}

layer.save()

layer.refresh_from_db()

upload = Upload.objects.create(
state='RUNNING',
layer=layer
resource=layer
)

_ = UploadFile.objects.create(
upload=upload,
file='/file.shp',
slug='foo_slug',
name="foo_name"
)
self.client.login(username='admin', password='admin')
# ... all should be good
response = self.client.get(reverse('download', args=(layer.id,)))
Expand Down Expand Up @@ -218,25 +223,27 @@ def test_tag_original_link_available_with_different_netlock_should_return_true(s
def test_should_return_false_if_no_files_are_available(self):
_ = Upload.objects.create(
state='RUNNING',
layer=self.resource
resource=self.resource
)

actual = original_link_available(self.context, self.resource.resourcebase_ptr_id, self.url)
self.assertFalse(actual)

@patch('geonode.storage.manager.storage_manager.exists', return_value=True)
def test_should_return_true_if_no_files_are_available(self, fexists):
def test_should_return_true_if_files_are_available(self, fexists):
upload = Upload.objects.create(
state='RUNNING',
layer=self.resource
)

_ = UploadFile.objects.create(
upload=upload,
file='/file.shp',
slug='foo_slug',
name="foo_name"
resource=self.resource
)
self.resource.files = {
".dbf": "/tmpe1exb9e9/foo_file.dbf",
".prj": "/tmpe1exb9e9/foo_file.prj",
".shp": "/tmpe1exb9e9/foo_file.shp",
".shx": "/tmpe1exb9e9/foo_file.shx"
}
self.resource.save()

self.resource.refresh_from_db()

actual = original_link_available(self.context, self.resource.resourcebase_ptr_id, self.url)
self.assertTrue(actual)
3 changes: 2 additions & 1 deletion geonode/proxy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#
#########################################################################

from geonode.base.models import ResourceBase
import io
import os
import re
Expand Down Expand Up @@ -266,7 +267,7 @@ def download(request, resourceid, sender=Layer):
permission='base.download_resourcebase',
permission_msg=_not_permitted)

if isinstance(instance, Layer):
if isinstance(instance, ResourceBase):
# Create Target Folder
dirpath = tempfile.mkdtemp(dir=settings.STATIC_ROOT)
dir_time_suffix = get_dir_time_suffix()
Expand Down

0 comments on commit f39a70c

Please sign in to comment.