def test_id(self): from edwin.models.photo import Photo p = Photo(self.fname) self.assertEqual(p.id, None) p.id = '1234567890' p = Photo(self.fname) self.assertEqual(p.id, '1234567890')
def test_scale_by_height(self): from edwin.models.photo import Photo photo = Photo(self.photo_file) photo.id = '123456' from edwin.views.image import ImageApplication app = ImageApplication(self.tmpdir) version = app.version(photo, (3000, 300)) self.assertEqual(version['size'], (400, 300))
def test_unauthorized(self): from edwin.models.photo import Photo photo = Photo(self.photo_file) photo.id = '123456' from happy.acl import Allow from happy.acl import Everyone from edwin.views.image import ImageApplication app = ImageApplication(self.tmpdir) import os import webob request = webob.Request.blank('/image/123456.300x300.jpg') request.app_context = DummyAppContextCatalog(photo) response = app(request, '123456.300x300.jpg') self.assertEqual(response.status_int, 401)
def test_clear_cache(self): from edwin.models.photo import Photo photo = Photo(self.photo_file) photo.id = '123456' from edwin.views.image import ImageApplication app = ImageApplication(self.tmpdir) version = app.version(photo, (300, 300)) import os import webob cache_file = os.path.join(self.tmpdir, '123456.300x300.jpg') request = webob.Request.blank('/image/123456.300x300.jpg') request.app_context = DummyAppContextCatalog(photo) request.authenticated_principals = ['group.Administrators'] app(request, version['fname']) self.failUnless(os.path.exists(cache_file)) app.clear_cache() self.failIf(os.path.exists(cache_file))
def test_it(self): from edwin.models.photo import Photo photo = Photo(self.photo_file) photo.id = '123456' from edwin.views.image import ImageApplication app = ImageApplication(self.tmpdir) version = app.version(photo, (300, 300)) self.assertEqual(version['fname'], '123456.300x300.jpg') self.assertEqual(version['size'], (300, 225)) import os import webob cache_file = os.path.join(self.tmpdir, '123456.300x300.jpg') request = webob.Request.blank('/image/123456.300x300.jpg') request.app_context = DummyAppContextCatalog(photo) request.authenticated_principals = ['group.Administrators'] response = app(request, version['fname']) self.assertEqual(response.content_type, 'image/jpeg') import Image image = Image.open(cache_file) self.assertEqual(image.size, (300, 225))