def test_post_submit(self): data = {'my_input': 'my_value'} encoded_data = to_bytes(urlencode(data)) response = urlopen(self.base_url + 'submit', encoded_data) self.assertEqual(200, response.getcode()) self.assertEqual(response.headers['Content-type'], 'text/html') self.assertIn('Submitted', str(response.read()))
def action(environ, start_response): response_headers = [ ('Location', redirect_to), ('Content-type', 'text/plain') ] start_response('302 Found', response_headers) return to_bytes('')
def test_post_submit(self): data = {"my_input": "my_value"} encoded_data = to_bytes(urlencode(data)) response = urlopen(self.base_url + "submit", encoded_data) self.assertEqual(200, response.getcode()) self.assertEqual(response.headers["Content-type"], "text/html") self.assertIn("Submitted", str(response.read()))
def add_html(self, method, path, filename): filepath = os.path.join(self.base, filename) with open(filepath, 'r') as html_file: contents = to_bytes(html_file.read()) def action(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) return contents self.add_route(method, path, action)
def add_html(self, method, path, filename): filepath = os.path.join(self.base, filename) with open(filepath, 'r') as html_file: contents = to_bytes(html_file.read()) def action(environ, start_response): start_response( '200 OK', [('Content-Type', 'text/html')]) return contents self.add_route(method, path, action)
def action(environ, start_response): response_headers = [('Location', redirect_to), ('Content-type', 'text/plain')] start_response('302 Found', response_headers) return to_bytes('')
def not_found(self): """Called if no URL matches.""" self.start_response('404 NOT FOUND', [('Content-Type', 'text/plain')]) return to_bytes('Not Found')
def not_found(self): """Called if no URL matches.""" self.start_response( '404 NOT FOUND', [('Content-Type', 'text/plain')]) return to_bytes('Not Found')