first tests and general code layout

pull/16/head
posativ 12 years ago
parent 7d905ed4ea
commit 0333f7efb0

@ -21,6 +21,54 @@
__version__ = '0.1'
from werkzeug.routing import Map, Rule
from werkzeug.serving import run_simple
from werkzeug.wrappers import Request, Response
from werkzeug.exceptions import HTTPException, NotFound, NotImplemented, InternalServerError
from isso import admin, comments
url_map = Map([
# moderation panel
Rule('/', endpoint='admin.index', methods=['GET', 'POST']),
# comments API
Rule('/comment/<string:path>/', endpoint='comments.comment', methods=['POST']),
Rule('/comment/<string:path>/<int:id>', endpoint='comments.comment',
methods=['GET', 'PUT', 'DELETE']),
])
class Isso:
def __init__(self, conf):
self.conf = conf
def dispatch(self, request, start_response):
adapter = url_map.bind_to_environ(request.environ)
try:
endpoint, values = adapter.match()
module, function = endpoint.split('.', 1)
handler = getattr(globals()[module], function)
return handler(self, request.environ, request, **values)
except NotFound, e:
return Response('Not Found', 404)
except HTTPException, e:
return e
except InternalServerError, e:
return Response(e, 500)
def wsgi_app(self, environ, start_response):
request = Request(environ)
response = self.dispatch(request, start_response)
return response(environ, start_response)
def __call__(self, environ, start_response):
return self.wsgi_app(environ, start_response)
def main():
print "Hallo Welt!"
app = Isso(123)
run_simple('127.0.0.1', 8080, app)

@ -0,0 +1,6 @@
from werkzeug.wrappers import Response
def index(app, environ, request):
return Response('', 200)

@ -0,0 +1,6 @@
from werkzeug.wrappers import Response
def comment(app, environ, request, path, id=None):
return Response('', 200)

@ -28,7 +28,7 @@ setup(
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7"
],
install_requires=['flask'],
install_requires=['werkzeug'],
entry_points={
'console_scripts':
['isso = isso:main'],

@ -0,0 +1,13 @@
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
import isso
client = Client(isso.Isso(123), BaseResponse)
def test_200ok():
assert client.get('/').status_code == 200
assert client.get('/comment/asdf/123').status_code == 200
Loading…
Cancel
Save