Skip to content

Commit

Permalink
Moved the max allowed remote image size to settings; added deletion o…
Browse files Browse the repository at this point in the history
…f image files' directory to test case.
  • Loading branch information
Kai committed Feb 23, 2011
1 parent 79a9f3f commit fb6541b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/metaimage/models.py
Expand Up @@ -4,6 +4,7 @@
from urlparse import urlparse

from django.db import models
from django.conf import settings
from django.contrib.auth.models import User
from django.core.files import File
from django.template.defaultfilters import slugify
Expand All @@ -12,20 +13,27 @@

from PIL import Image

from photologue.models import ImageModel
from photologue.models import ImageModel, PHOTOLOGUE_DIR
from tagging.fields import TagField

from utils.openanything import fetch


MAX_REMOTE_IMAGE_SIZE = 1048576 # 1 MB
if settings.METAIMAGE_MAX_REMOTE_IMAGE_SIZE:
MAX_REMOTE_IMAGE_SIZE = settings.METAIMAGE_MAX_REMOTE_IMAGE_SIZE
else:
MAX_REMOTE_IMAGE_SIZE = 1048576 # 1 MB

PRIVACY_CHOICES = (
(1, _('Public')),
(2, _('Friends')),
(3, _('Private')),
)

# This parameter is needed when cleaning up after unit-tests,
# otherwise old test images litter the directory:
METAIMAGE_DIR = PHOTOLOGUE_DIR


class MetaImageException(Exception):
pass
Expand Down
16 changes: 12 additions & 4 deletions src/metaimage/tests.py
@@ -1,7 +1,9 @@
import shutil

from django.contrib.auth.models import User
from django.test import TestCase

from metaimage.models import MetaImage
from metaimage.models import MetaImage, METAIMAGE_DIR


class TestMetaImage(TestCase):
Expand All @@ -27,11 +29,17 @@ def test_metaimage_save(self):
)
test_metaimage.save()
the_metaimage = MetaImage.objects.get(slug='django-logo')
assert the_metaimage.image is not None # Image was downloaded
assert the_metaimage.image is not None # Image was downloaded OK.
assert the_metaimage.is_public
assert the_metaimage.updater == self.foo
assert the_metaimage.slug == 'django-logo'
the_metaimage.delete() # Removes image file too
print the_metaimage.image.name
# As of Django 1.2.5, the image file is NOT removed when the
# database object is deleted.
the_metaimage.delete()

def tearDown(self):
pass
# In order that image filenames are repeatable, it's necessary
# to delete the directory where they're stored between test
# runs.
shutil.rmtree(METAIMAGE_DIR)
9 changes: 5 additions & 4 deletions src/metaimage/testsettings.py
@@ -1,16 +1,17 @@
DATABASES = {
'default': {
'ENGINE': 'sqlite3',
'NAME': '/tmp/metaimage.db',
}
'NAME': '/tmp/metaimage.db'}
}

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'metaimage',
'photologue',
'tagging',
]
'tagging']

METAIMAGE_MAX_REMOTE_IMAGE_SIZE = 1048576 # 1 MB

ROOT_URLCONF = ['metaimage.urls']

0 comments on commit fb6541b

Please sign in to comment.