Skip to content

Commit

Permalink
- Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Mar 15, 2021
1 parent e16179c commit c65dfae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
18 changes: 9 additions & 9 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ def save_thumbnail(self, filename, image):
storage.path(_upload_path)
)
except Exception as e:
logger.debug(e)
logger.exception(e)

try:
# Optimize the Thumbnail size and resolution
Expand All @@ -1520,7 +1520,7 @@ def save_thumbnail(self, filename, image):
cover = ImageOps.fit(im, (_default_thumb_size['width'], _default_thumb_size['height']))
cover.save(storage.path(_upload_path), format='PNG')
except Exception as e:
logger.debug(e)
logger.exception(e)

# check whether it is an URI or not
parsed = urlsplit(url)
Expand Down Expand Up @@ -1551,10 +1551,10 @@ def save_thumbnail(self, filename, image):
thumbnail_url=url
)
except Exception as e:
logger.debug(
'Error when generating the thumbnail for resource %s. (%s)' %
(self.id, str(e)))
logger.warn('Check permissions for file %s.' % upload_path)
logger.error(
f'Error when generating the thumbnail for resource {self.id}. ({e})'
)
logger.error(f'Check permissions for file {upload_path}.')
try:
Link.objects.filter(resource=self, name='Thumbnail').delete()
_thumbnail_url = staticfiles.static(settings.MISSING_THUMBNAIL)
Expand All @@ -1575,9 +1575,9 @@ def save_thumbnail(self, filename, image):
thumbnail_url=_thumbnail_url
)
except Exception as e:
logger.debug(
'Error when generating the thumbnail for resource %s. (%s)' %
(self.id, str(e)))
logger.error(
f'Error when generating the thumbnail for resource {self.id}. ({e})'
)

def set_missing_info(self):
"""Set default permissions and point of contacts.
Expand Down
11 changes: 8 additions & 3 deletions geonode/thumbs/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
from pixelmatch.contrib.PIL import pixelmatch

from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
from django.contrib.auth import get_user_model
from django.test.utils import override_settings
from django.contrib.staticfiles.templatetags import staticfiles

from geonode import geoserver
from geonode.utils import check_ogc_backend
Expand All @@ -52,6 +53,8 @@

logger = logging.getLogger(__name__)

missing_thumbnail_url = staticfiles.static(settings.MISSING_THUMBNAIL)

LOCAL_TIMEOUT = 300
EXPECTED_RESULTS_DIR = "geonode/thumbs/tests/expected_results/"

Expand Down Expand Up @@ -413,6 +416,9 @@ def tearDownClass(cls):
super().tearDownClass()

def _fetch_thumb_and_compare(self, url, expected_image):
self.assertNotEqual(
url, missing_thumbnail_url,
f"Expected url different from '{missing_thumbnail_url}'")
_, img = http_client.request(url)
content = BytesIO(img)
Image.open(content).verify() # verify that it is, in fact an image
Expand All @@ -436,8 +442,7 @@ def _fetch_thumb_and_compare(self, url, expected_image):
def test_layer_default_thumb(self):
expected_thumb = Image.open(EXPECTED_RESULTS_DIR + "thumbnails/default_layer_coast_line_thumb.png")
create_gs_thumbnail_geonode(self.layer_coast_line, overwrite=True)
logger.error(f" --- expected_thumb: {expected_thumb}")
logger.error(f" --- thumbnail_url: {self.layer_coast_line.thumbnail_url}")
self.layer_coast_line.refresh_from_db()
self._fetch_thumb_and_compare(self.layer_coast_line.thumbnail_url, expected_thumb)

@on_ogc_backend(geoserver.BACKEND_PACKAGE)
Expand Down

0 comments on commit c65dfae

Please sign in to comment.