Skip to content

Commit

Permalink
Merge pull request #19 from jonathanj/13-renderable-resource-methods
Browse files Browse the repository at this point in the history
Allow any HTTP method for `IRenderable` resources.
  • Loading branch information
jonathanj committed Sep 29, 2015
2 parents d2e0aa7 + 5b5d33c commit 6fba498
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion txspinneret/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, renderable, doctype=b'<!DOCTYPE html>'):
self._doctype = doctype


def render_GET(self, request):
def render(self, request):
request.setResponseCode(http.OK)
return renderElement(request, self._renderable, self._doctype)

Expand Down
28 changes: 28 additions & 0 deletions txspinneret/test/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,34 @@ def locateChild(zelf, request, segments):
Equals([]))


def test_renderableResourceMethods(self):
"""
`IRenderable` results allow any HTTP method.
"""
class _TestElement(Element):
loader = TagLoader(tags.span(u'Hello ', tags.em(u'World')))

@implementer(ISpinneretResource)
class _TestResource(object):
def locateChild(zelf, request, segments):
return _TestElement(), []

resource = SpinneretResource(_TestResource())
request = InMemoryRequest([''])
request.method = 'POST'
result = getChildForRequest(resource, request)
request.render(result)
self.assertThat(
b''.join(request.written),
Equals(b'<!DOCTYPE html>\n<span>Hello <em>World</em></span>'))
self.assertThat(
http.OK,
Equals(request.responseCode))
self.assertThat(
request.postpath,
Equals([]))


def test_locateChildResource(self):
"""
If ``locateChild`` returns something adaptable to `IResource` it is
Expand Down

0 comments on commit 6fba498

Please sign in to comment.