Skip to content

Commit

Permalink
- Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed May 28, 2019
1 parent 7efd502 commit 6c940c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion geonode/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def delete_orphaned_thumbs():
model = filename.split('-')[0]
uuid = filename.replace(model, '').replace('-thumb.png', '')[1:]
if ResourceBase.objects.filter(uuid=uuid).count() == 0:
print 'Removing orphan thumb %s' % fn
logger.debug('Removing orphan thumb %s' % fn)
try:
os.remove(fn)
except OSError:
logger.debug('Could not delete file %s' % fn)
print 'Could not delete file %s' % fn
logger.error('Could not delete file %s' % fn)
14 changes: 13 additions & 1 deletion geonode/documents/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def test_moderated_upload(self):
_d = Document.objects.get(title=dname)

self.assertTrue(_d.is_published)
uuid = _d.uuid
_d.delete()

from geonode.documents.utils import delete_orphaned_document_files
Expand All @@ -489,7 +490,18 @@ def test_moderated_upload(self):
from geonode.base.utils import delete_orphaned_thumbs
delete_orphaned_thumbs()

self.assertFalse(os.path.isfile(input_path))
from django.conf import settings
documents_path = os.path.join(settings.MEDIA_ROOT, 'documents')
fn = os.path.join(documents_path, os.path.basename(input_path))
self.assertFalse(os.path.isfile(fn))

thumbs_path = os.path.join(settings.MEDIA_ROOT, 'thumbs')
_cnt = 0
for filename in os.listdir(thumbs_path):
fn = os.path.join(thumbs_path, filename)
if uuid in filename:
_cnt += 1
self.assertTrue(_cnt == 0)

with self.settings(ADMIN_MODERATE_UPLOADS=True):
document_upload_url = reverse('document_upload')
Expand Down
5 changes: 5 additions & 0 deletions geonode/documents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@

# Standard Modules
import os
import logging

# Django functionality
from django.conf import settings

# Geonode functionality
from geonode.documents.models import Document

logger = logging.getLogger(__name__)


def delete_orphaned_document_files():
"""
Expand All @@ -40,7 +43,9 @@ def delete_orphaned_document_files():
fn = os.path.join(documents_path, filename)
if Document.objects.filter(doc_file__contains=filename).count() == 0:
print 'Removing orphan document %s' % fn
logger.debug('Removing orphan document %s' % fn)
try:
os.remove(fn)
except OSError:
print 'Could not delete file %s' % fn
logger.error('Could not delete file %s' % fn)

0 comments on commit 6c940c2

Please sign in to comment.