def test_handle_get(self): simple = ultramini.Resource() simple.template = 'hello' code, result, headers = self.handle_resource(loc(), simple) assert code == 200 assert result == 'hello'
def test_simple_http(self): root = ultramini.Resource() root.template = 'hello' site = ultramini.SiteMap(root) headers, result = sendreq(site, GET_TEMPLATE % ('/', )) assert result == 'hello', (site, result, headers)
def test_missing_methods(self): expected = ( "<html><body>No handler for method 'GURFLE' present.</body></html>" ) code, result, headers = self.handle_resource(loc(method='GURFLE'), ultramini.Resource()) assert code == 200 assert result == expected
def test_handle_post(self): simple = ultramini.Resource() simple.template = 'hello' ## Assert that we redirect code, result, headers = self.handle_resource( loc(method='post', headers={'content-length': '0'}), simple) assert code == 303, (code, headers, result) assert result == '' assert headers['Location'] == loc().uri()
def test_willHandle(self): child = ultramini.Resource() class Root(ultramini.Resource): def willHandle(self, req): return child def childFactory(self, req, segments): return self, segments, () assert self.find_resource('/', Root()) == child
def test_findChild(self): child = ultramini.Resource() class Foo(ultramini.Resource): def findChild(self, req, segments): return child, segments, () root = Foo() assert self.find_resource('/foobar', root) == child assert self.find_resource('/', root) == child assert self.find_resource('/asdfasdf/asdfasdf/asdfasdf', root) == child
def __init__(self, query, site, method, uri, headers, path, body, resource): self.site = site # These should be private but they aren't self._query = query self._path = path # These are private self._headers_ = headers self._method_ = method self._body_ = body self._uri_ = uri self.pushed = '' self._response_ = 200 self._outgoing_headers_ = {} if resource is None: resource = ultramini.Resource() self.resource = resource self.convert = ultramini.convert
def test_simple_not_found(self): root = ultramini.Resource() site = ultramini.SiteMap(root) headers, result = sendreq( site, GET_TEMPLATE % ('/asdfkjasdfhakshdfkhaqe/asdfhas/a.dhf', )) assert headers.startswith("HTTP/1.1 404"), ('Fail', headers, result)
def test_child(self): root = ultramini.Resource() child = root.child_foo = ultramini.Resource() result = self.find_resource('/foo', root) assert result == child
def test_root(self): root = ultramini.Resource() result = self.find_resource('/', root) assert result == root