Commit 65689030 authored by Jacek Furmankiewicz's avatar Jacek Furmankiewicz

Code is broken now: working on separating router from actual Http Resource, in...

Code is broken now: working on separating router from actual Http Resource, in preparation for ZeroMQ multicore support...
parent d2897764
'''
Common classes
'''
class Response:
"""
Custom response object, can be returned instead of raw string response
"""
def __init__(self,code=200,entity=None,headers={}):
self.code = code
self.entity=entity
self.headers=headers
\ No newline at end of file
This diff is collapsed.
......@@ -186,7 +186,7 @@ total: 4443.52
| Unable to convert String response to XML automatically | application/xml | 500 | # not supported yet
| - {test1: Test1}\n- {test2: Test2} | text/yaml | 200 |
@json @yaml @xml @return_accept_deferred
@json @yaml @xml @return_accept_deferred @tmp
Scenario Outline: Return content type based on caller's Accept from Deferred methods
When I prepare HTTP header 'Accept' = '<accept>'
When as user 'None:None' I GET 'http://127.0.0.1:8080/return/by/accept/deferred'
......@@ -196,8 +196,8 @@ total: 4443.52
Examples:
| content | accept | code |
| [{"test1": "Test1"}, {"test2": "Test2"}] | application/json | 200 |
| Unable to convert String response to XML automatically | application/xml | 500 | # not supported yet
| - {test1: Test1}\n- {test2: Test2} | text/yaml | 200 |
#| Unable to convert String response to XML automatically | application/xml | 500 | # not supported yet
#| - {test1: Test1}\n- {test2: Test2} | text/yaml | 200 |
@json @yaml @xml @return_accept
Scenario Outline: Return class content type based on caller's Accept
......@@ -208,6 +208,6 @@ total: 4443.52
Examples:
| content | accept | code |
| is not JSON serializable | application/json | 500 | # not supported yet
| [{}, {}] | application/json | 200 | # not supported yet
| Unable to convert String response to XML automatically | application/xml | 500 | # not supported yet
\ No newline at end of file
......@@ -7,6 +7,7 @@ from corepost.web import CorePost, route
from corepost.enums import Http, MediaType, HttpHeader
from twisted.internet import defer
from xml.etree import ElementTree
from UserDict import UserDict
import json, yaml
class HomeApp(CorePost):
......@@ -91,13 +92,15 @@ class HomeApp(CorePost):
@route("/return/by/accept/class")
def test_return_class_content_by_accepts(self,request,**kwargs):
"""Uses Python class instead of dict/list"""
class Test: pass
class Test(UserDict,dict):
pass
t1 = Test()
t1.test1 = "Test1"
t1.test1="Test1"
t2 = Test()
t2.test2 = "Test2"
t2.test2="Test2"
val = [t1,t2]
return val
return (t1,t2)
......
......@@ -3,6 +3,7 @@ Various CorePost utilities
'''
from inspect import getargspec
import json
from corepost.enums import MediaType
def getMandatoryArgumentNames(f):
'''Returns a tuple of the mandatory arguments required in a function'''
......@@ -22,3 +23,10 @@ def convertToJson(obj):
return json.dumps(obj)
except Exception as ex:
raise RuntimeError(str(ex))
def applyResponse(self,request,code,headers={"content-type":MediaType.TEXT_PLAIN}):
"""Applies response to current request"""
request.setResponseCode(code)
if headers != None:
for header,value in headers.iteritems():
request.setHeader(header, value)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment