Skip to content
Permalink
Browse files

fix height to string, remove favicon png, add tests, make app importable

  • Loading branch information
jinpark committed Mar 28, 2015
1 parent fe599da commit 0fdbfbc75c4dc04abbeb4e19eb959f65e5db7547
No changes.
6 app.py
@@ -39,6 +39,9 @@ def home():

@app.route('/favicon.ico/')
def favicon():
"""
I hate favicons. ugh
"""
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/png')

@@ -70,7 +73,6 @@ def convert(url):
try:
resize_height = int(query_string['rheight'])
except:

bad_request('rheight')
else:
resize_height = None
@@ -79,7 +81,7 @@ def convert(url):
if resize_width and not resize_height:
img.transform(resize=str(resize_width))
if resize_height and not resize_width:
img.transform(resize='x' + resize_height)
img.transform(resize='x' + str(resize_height))

temp_file = NamedTemporaryFile(mode='w+b',suffix=img.format)
img.save(file=temp_file)
BIN -4.76 KB static/favicon.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,75 @@
import os
import sys
import unittest
import requests
from StringIO import StringIO
from wand.image import Image
from mock import MagicMock

topdir = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(topdir)
import app


def get_stub(*args, **kwargs):
response = requests.get.return_value
with open('tests/images/50x200_pre.jpeg', 'r') as f:
response.content = f.read()
response.headers = {'content-type': 'image/png'}
return response

requests.get = MagicMock(side_effect=get_stub)


class TestImageResizer(unittest.TestCase):
def setUp(self):
self.app = app.app.test_client()

def test_entry(self):
expected_image = open('tests/images/50x200.jpeg').read()

rv = self.app.get('/http://placekitten.com/g/50/200/', follow_redirects=True)
rv_image_string = rv.data
self.assertEqual(rv.data, expected_image)

def test_resize_width(self):
expected_image = open('tests/images/50x200.jpeg').read()

rv = self.app.get('/http://placekitten.com/g/50/200/?rwidth=100', follow_redirects=True)
with Image(file=StringIO(rv.data)) as img:
self.assertEqual(img.width, 100)
self.assertEqual(img.height, 400)

def test_resize_height(self):
expected_image = open('tests/images/50x200.jpeg').read()

rv = self.app.get('/http://placekitten.com/g/50/200/?rheight=100', follow_redirects=True)
with Image(file=StringIO(rv.data)) as img:
self.assertEqual(img.width, 25)
self.assertEqual(img.height, 100)

def test_resize_width_and_height(self):
expected_image = open('tests/images/50x200.jpeg').read()

rv = self.app.get('/http://placekitten.com/g/50/200/?rheight=100&rwidth=100', follow_redirects=True)
with Image(file=StringIO(rv.data)) as img:
self.assertEqual(img.width, 100)
self.assertEqual(img.height, 100)

def test_resize_width_and_height(self):
expected_image = open('tests/images/50x200.jpeg').read()

rv = self.app.get('/http://placekitten.com/g/50/200/?rheight=100&rwidth=100', follow_redirects=True)
with Image(file=StringIO(rv.data)) as img:
self.assertEqual(img.width, 100)
self.assertEqual(img.height, 100)

def test_convert_type(self):
expected_image = open('tests/images/50x200.jpeg').read()

rv = self.app.get('/http://placekitten.com/g/50/200/?type=png', follow_redirects=True)
with Image(file=StringIO(rv.data)) as img:
self.assertEqual(img.mimetype, "image/png")

if __name__ == '__main__':
unittest.main()

0 comments on commit 0fdbfbc

Please sign in to comment.
You can’t perform that action at this time.