Skip to content

Commit

Permalink
Convert another test
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Aug 14, 2016
1 parent 9cc94f7 commit 3759c40
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions tests/test_web_sendfile_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ def handler(request):
resp.close()


@asyncio.coroutine
def test_static_file_with_content_encoding(loop, test_client, sender):
filepath = pathlib.Path(__file__).parent / 'hello.txt.gz'

@asyncio.coroutine
def handler(request):
resp = yield from sender().send(request, filepath)
return resp

app = web.Application(loop=loop)
app.router.add_get('/', handler)
client = yield from test_client(lambda loop: app)

resp = yield from client.get('/')
assert 200 == resp.status
body = yield from resp.read()
assert b'hello aiohttp\n' == body
ct = resp.headers['CONTENT-TYPE']
assert 'text/plain' == ct
encoding = resp.headers['CONTENT-ENCODING']
assert 'gzip' == encoding
resp.close()


class StaticFileMixin(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -184,29 +208,6 @@ def go(dirname, filename):
filename = 'data.unknown_mime_type'
self.loop.run_until_complete(go(here, filename))

def test_static_file_with_content_encoding(self):

@asyncio.coroutine
def go(dirname, filename):
app, _, url = yield from self.create_server(
'GET', '/static/' + filename
)
app.router.add_static('/static', dirname)

resp = yield from request('GET', url, loop=self.loop)
self.assertEqual(200, resp.status)
body = yield from resp.read()
self.assertEqual(b'hello aiohttp\n', body)
ct = resp.headers['CONTENT-TYPE']
self.assertEqual('text/plain', ct)
encoding = resp.headers['CONTENT-ENCODING']
self.assertEqual('gzip', encoding)
resp.close()

here = os.path.dirname(__file__)
filename = 'hello.txt.gz'
self.loop.run_until_complete(go(here, filename))

def test_static_file_directory_traversal_attack(self):

@asyncio.coroutine
Expand Down

0 comments on commit 3759c40

Please sign in to comment.