This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75e605a
commit 7df34bd
Showing
5 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
env | ||
*.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup(name='gip', packages=find_packages()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from cStringIO import StringIO | ||
from os.path import join | ||
from zipfile import ZipFile | ||
|
||
import pytest | ||
from aspen.testing.client import Client | ||
from gip import website | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
client = Client(www_root='www', project_root='.') | ||
client._website = website | ||
yield client | ||
|
||
@pytest.fixture | ||
def image(): | ||
yield open(join('tests', 'image.jpg')).read() | ||
|
||
|
||
def zipfile(raw): | ||
return ZipFile(StringIO(raw), mode='r') | ||
|
||
def filenames(zipfile): | ||
return [n.filename for n in zipfile.filelist] | ||
|
||
@pytest.fixture | ||
def vary_length(client, image): | ||
def vary_length(length, fail=True): | ||
method = client.PxST if fail else client.POST | ||
return method( '/v1' | ||
, body=image | ||
, content_type='image/jpeg' | ||
, HTTP_CONTENT_LENGTH=str(length) | ||
).code | ||
return vary_length | ||
|
||
|
||
def test_normal_case_is_200(client, image): | ||
response = client.POST('/v1', body=image, content_type='image/jpeg') | ||
assert response.code == 200 | ||
assert filenames(zipfile(response.body)) == ['160', '48'] | ||
|
||
def test_length_too_great_is_413(vary_length): | ||
assert vary_length(262145) == 413 | ||
|
||
def test_length_overstated_is_400(vary_length): | ||
assert vary_length(262144) == 400 | ||
assert vary_length(20888) == 400 | ||
|
||
def test_length_properly_stated_is_200(vary_length): | ||
assert vary_length(20887, False) == 200 | ||
|
||
def test_length_understated_is_400(vary_length): | ||
assert vary_length(20886) == 400 | ||
assert vary_length(1) == 400 | ||
assert vary_length(0) == 400 | ||
assert vary_length(-1) == 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters