Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Taekyoon committed Aug 15, 2016
2 parents f3738f2 + 492a471 commit af929b2
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 83 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Daniel Nelson
David Michael Brown
Dima Veselov
Dimitar Dimitrov
Dmitry Trofimov
Dmytro Kuznetsov
Dustin J. Mitchell
Elizabeth Leddy
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
ipdb
pytest-sugar
ipython
pyenchant
sphinxcontrib-spelling
sphinxcontrib-asyncio
isort
aiodns
169 changes: 88 additions & 81 deletions tests/test_web_sendfile_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,94 @@ def handler(request):
resp.close()


@asyncio.coroutine
def test_static_file_if_modified_since(loop, test_client, sender):
filename = 'data.unknown_mime_type'
filepath = pathlib.Path(__file__).parent / filename

@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
lastmod = resp.headers.get('Last-Modified')
assert lastmod is not None
resp.close()

resp = yield from client.get('/', headers={'If-Modified-Since': lastmod})
assert 304 == resp.status
resp.close()


@asyncio.coroutine
def test_static_file_if_modified_since_past_date(loop, test_client, sender):
filename = 'data.unknown_mime_type'
filepath = pathlib.Path(__file__).parent / filename

@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)

lastmod = 'Mon, 1 Jan 1990 01:01:01 GMT'

resp = yield from client.get('/', headers={'If-Modified-Since': lastmod})
assert 200 == resp.status
resp.close()


@asyncio.coroutine
def test_static_file_if_modified_since_invalid_date(loop, test_client, sender):
filename = 'data.unknown_mime_type'
filepath = pathlib.Path(__file__).parent / filename

@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)

lastmod = 'not a valid HTTP-date'

resp = yield from client.get('/', headers={'If-Modified-Since': lastmod})
assert 200 == resp.status
resp.close()


@asyncio.coroutine
def test_static_file_if_modified_since_future_date(loop, test_client, sender):
filename = 'data.unknown_mime_type'
filepath = pathlib.Path(__file__).parent / filename

@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)

lastmod = 'Fri, 31 Dec 9999 23:59:59 GMT'

resp = yield from client.get('/', headers={'If-Modified-Since': lastmod})
assert 304 == resp.status
resp.close()


class StaticFileMixin(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -237,87 +325,6 @@ def go(dirname, relpath):
filename = '../README.rst'
self.loop.run_until_complete(go(here, filename))

def test_static_file_if_modified_since(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)
lastmod = resp.headers.get('Last-Modified')
self.assertIsNotNone(lastmod)
resp.close()

resp = yield from request('GET', url, loop=self.loop,
headers={'If-Modified-Since': lastmod})
self.assertEqual(304, resp.status)
resp.close()

here = os.path.dirname(__file__)
filename = 'data.unknown_mime_type'
self.loop.run_until_complete(go(here, filename))

def test_static_file_if_modified_since_past_date(self):

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

lastmod = 'Mon, 1 Jan 1990 01:01:01 GMT'
resp = yield from request('GET', url, loop=self.loop,
headers={'If-Modified-Since': lastmod})
self.assertEqual(200, resp.status)
resp.close()

here = os.path.dirname(__file__)
filename = 'data.unknown_mime_type'
self.loop.run_until_complete(go(here, filename))

def test_static_file_if_modified_since_future_date(self):

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

lastmod = 'Fri, 31 Dec 9999 23:59:59 GMT'
resp = yield from request('GET', url, loop=self.loop,
headers={'If-Modified-Since': lastmod})
self.assertEqual(304, resp.status)
resp.close()

here = os.path.dirname(__file__)
filename = 'data.unknown_mime_type'
self.loop.run_until_complete(go(here, filename))

def test_static_file_if_modified_since_invalid_date(self):

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

lastmod = 'not a valid HTTP-date'
resp = yield from request('GET', url, loop=self.loop,
headers={'If-Modified-Since': lastmod})
self.assertEqual(200, resp.status)
resp.close()

here = os.path.dirname(__file__)
filename = 'data.unknown_mime_type'
self.loop.run_until_complete(go(here, filename))

def test_static_route_path_existence_check(self):
directory = os.path.dirname(__file__)
web.StaticRoute(None, "/", directory)
Expand Down

0 comments on commit af929b2

Please sign in to comment.