Skip to content

Commit

Permalink
Fix HTTPServer headers. Add HTTPServer tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Feb 26, 2019
1 parent 1eb5e2b commit 88eb30e
Show file tree
Hide file tree
Showing 21 changed files with 325 additions and 27 deletions.
11 changes: 6 additions & 5 deletions unrest/framework/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ def handle_request(self, method):
)
return self.send(404, 'Not Found')

def send(self, status, message):
def send(self, status, message, headers):
self.send_response(status)

for name, value in headers.items():
self.send_header(name, value)
self.end_headers()

self.wfile.write(message.encode('utf-8'))

def respond(self, url, method, function, url_parameters):
Expand All @@ -82,10 +86,7 @@ def respond(self, url, method, function, url_parameters):
log.exception('Error on ' + method + ' ' + self.path)
return self.send(500, 'Internal Server Error')

for name, value in response.headers.items():
self.headers[name] = value

self.send(response.status, response.payload)
self.send(response.status, response.payload, response.headers)

self.app.RequestHandlerClass = HTTPServerFrameworkHandlerClass

Expand Down
2 changes: 2 additions & 0 deletions unrest/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def idsorted(it, key='id'):
return sorted(it, key=lambda x: x[key])
2 changes: 0 additions & 2 deletions unrest/tests/flask/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
def idsorted(it, key='id'):
return sorted(it, key=lambda x: x[key])
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_delete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_delete_pk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_get.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_get_pk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_paginated.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_patch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import timedelta

from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_patch_pk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_post_pk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_properties.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sqlalchemy.types import DateTime, Float, Numeric

from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_put.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_put_pk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_relationships.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_unrest_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unrest.framework.flask import FlaskFramework
from unrest.rest import Rest

from . import idsorted
from .. import idsorted
from ...framework import Framework
from ...idiom import Idiom
from ...util import Response
Expand Down
2 changes: 1 addition & 1 deletion unrest/tests/flask/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sqlalchemy.inspection import inspect

from . import idsorted
from .. import idsorted
from ..model import Fruit, Tree


Expand Down

0 comments on commit 88eb30e

Please sign in to comment.