Skip to content

Commit

Permalink
100 percent coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Sep 18, 2019
1 parent 65aa418 commit 7ba1641
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 2 additions & 4 deletions nanohttp/response.py
Expand Up @@ -36,10 +36,8 @@ def conclude(self):
if self.charset:
body = [i.encode(self.charset) for i in body]

if self.length is not None:
contentlength = self.length
else:
contentlength = sum(len(i) for i in body)
contentlength = self.length if self.length is not None \
else sum(len(i) for i in body)

self.headers.add('content-length', str(contentlength))

Expand Down
4 changes: 3 additions & 1 deletion nanohttp/static.py
@@ -1,6 +1,8 @@
from os import path
from mimetypes import guess_type

from . import statuses


CHUNKSIZE = 1024 * 10

Expand All @@ -27,7 +29,7 @@ def get(location):
filename = path.join(rootpath, location)

if not path.exists(filename):
raise notfound()
raise statuses.notfound()

app.response.length = path.getsize(filename)
app.response.type = guess_type(path.split(filename)[1])[0]
Expand Down
10 changes: 9 additions & 1 deletion tests/test_static.py
@@ -1,6 +1,6 @@
from os import path

from bddrest import status, response
from bddrest import status, response, when

from nanohttp import static

Expand Down Expand Up @@ -32,3 +32,11 @@ def test_staticdirectory(app, session, when, tmpdir):
assert response.headers['content-length'] == '3'
assert response == 'foo'

when('/invalidfile')
assert status == 404

when('/invalid/file')
assert status == 404

when('/invalid/file.html')
assert status == 404

0 comments on commit 7ba1641

Please sign in to comment.