def test_thumb_utils_methods(self, image): """ Bunch of tests on thumb_utils helpers. """ filename = 'test-thumb' upload_path = thumb_utils.thumb_path(filename) self.assertEqual(upload_path, os.path.join(settings.THUMBNAIL_LOCATION, filename)) thumb_utils.remove_thumbs(filename) self.assertFalse(thumb_utils.thumb_exists(filename)) f = BytesIO(test_image.tobytes()) f.name = filename storage.save(upload_path, File(f)) self.assertTrue(thumb_utils.thumb_exists(filename)) self.assertEqual(thumb_utils.thumb_size(upload_path), 10000)
def test_thumbnail_links(self): """Test that thumbnail links were created after upload.""" filename = os.path.join(gisdata.GOOD_DATA, 'raster/test_grid.tif') layer = file_upload(filename) """:type: geonode.layers.models.Layer""" # check that we have remote thumbnail remote_thumbnail_link = layer.link_set.get( name__icontains='remote thumbnail') self.assertTrue(remote_thumbnail_link.url) # thumbnail won't generate because remote thumbnail uses public # address remote_thumbnail_url = remote_thumbnail_link.url # Replace url's basename, we want to access it using django client parse_result = urlsplit(remote_thumbnail_url) remote_thumbnail_url = urlunsplit( ('', '', parse_result.path, parse_result.query, '')) response = self.client.get(remote_thumbnail_url) thumbnail_path = thumb_path("layer-thumb.png") layer.save_thumbnail(thumbnail_path, ensure_string(response.content)) # Check thumbnail created self.assertTrue(storage.exists(thumbnail_path)) self.assertEqual(what(thumbnail_path), 'png') # Check that now we have thumbnail self.assertTrue(layer.has_thumbnail()) missing_thumbnail_url = staticfiles.static(settings.MISSING_THUMBNAIL) self.assertTrue(layer.get_thumbnail_url() != missing_thumbnail_url) thumbnail_links = layer.link_set.filter(name__icontains='thumbnail') self.assertTrue(len(thumbnail_links) > 0) link_names = ['remote thumbnail', 'thumbnail'] for link in thumbnail_links: self.assertIn(link.name.lower(), link_names) # cleanup layer.delete()
def test_map_thumbnail(self): """Creating map will create thumbnail.""" filename = os.path.join( gisdata.GOOD_DATA, 'raster/relief_san_andres.tif') layer1 = file_upload(filename) filename = os.path.join( gisdata.GOOD_DATA, 'vector/san_andres_y_providencia_administrative.shp') layer2 = file_upload(filename) """:type: geonode.layers.models.Layer""" # construct json request for new map json_payload = InitialSetup.generate_initial_map(layer1, layer2) self.client.login(username='******', password='******') response = self.client.post( reverse('new_map_json'), json.dumps(json_payload), content_type='application/json') self.assertEqual(response.status_code, 200) content = ensure_string(response.content) if isinstance(content, bytes): content = content.decode('UTF-8') map_id = json.loads(content).get('id') map = Map.objects.get(id=map_id) # check that we have remote thumbnail remote_thumbnail_link = map.link_set.filter( name__icontains='remote thumbnail').first() self.assertTrue(remote_thumbnail_link.url) # thumbnail won't generate because remote thumbnail uses public # address remote_thumbnail_url = remote_thumbnail_link.url # Replace url's basename, we want to access it using django client parse_result = urlsplit(remote_thumbnail_url) remote_thumbnail_url = urlunsplit( ('', '', parse_result.path, parse_result.query, '')) response = self.client.get(remote_thumbnail_url) thumbnail_path = thumb_path("map-thumb.png") map.save_thumbnail(thumbnail_path, ensure_string(response.content)) # Check thumbnail created self.assertTrue(storage.exists(thumbnail_path)) self.assertEqual(what(thumbnail_path), 'png') # Check that now we have thumbnail self.assertTrue(map.has_thumbnail()) missing_thumbnail_url = staticfiles.static(settings.MISSING_THUMBNAIL) self.assertTrue(map.get_thumbnail_url() != missing_thumbnail_url) thumbnail_links = map.link_set.filter(name__icontains='thumbnail') self.assertTrue(len(thumbnail_links) > 0) link_names = ['remote thumbnail', 'thumbnail'] for link in thumbnail_links: self.assertIn(link.name.lower(), link_names) # cleanup map.delete() layer1.delete() layer2.delete()