def application(environ, start_response): results = [] results.append(hello.hello()) helloWorld = hello.HelloWorld() results.append(helloWorld.sayHello()) output = "<br/>".join(results) # build the response body possibly using the environ dictionary response_body = output # HTTP response code and message status = '200 OK' # These are HTTP headers expected by the client. # They must be wrapped as a list of tupled pairs: # [(Header name, Header value)]. response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(response_body)))] # Send them to the server using the supplied function start_response(status, response_headers) # Return the response body. # Notice it is wrapped in a list although it could be any iterable. return [response_body]
#!/usr/bin/python3 # import my hello.py module import hello # I can now call my hello world function # from this script file hello.HelloWorld()
def test_say_hello(): app = hello.HelloWorld() assert None is app.say_hello(name='John')
def test_name(self): for name, greeting in zip(("Anton", "Антон"), ("Hello, Anton!", "Hello, Антон!")): hw = hello.HelloWorld(name) self.assertEqual(hw.greeting(), greeting)
def test_no_name(self): name = None hw = hello.HelloWorld(name) self.assertIsNone(hw.name) self.assertEqual(hw.greeting(), "")