Let’s continue
Let’s add on to webserver.py with the following endpoints
- If someone goes to
http://localhost:5000/hello/Mike
, the server returns the string-
<h1>Hello Mike</h1>
-
- If someone goes to
http://localhost:5000/hello/Sarah
, the server returns the string-
<h1>Hello Sarah</h1>
-
- If anything is typed after ‘/hello’ like
http://localhost:5000/hello/sdFKLJafdj
the server should return the string:-
<h1>Hello sdFKLJafdj</h1>
-
Please be sure to return the responses listed exactly as shown. If not then the unit tests will not function correctly.
How to test:
-
- Add the following code to test_webserver.py and run it using the command
pytest test_webserver.py
-
def test_hello_mike(): page = requests.get('http://localhost:5000/hello/mike') true_content = '<h1>Hello mike</h1>' assert str(page.text) == true_content def test_hello_sarah(): page = requests.get('http://localhost:5000/hello/sarah') true_content = '<h1>Hello sarah</h1>' assert str(page.text) == true_content def test_hello_crazy(): page = requests.get('http://localhost:5000/hello/crazy') true_content = '<h1>Hello crazy</h1>' assert str(page.text) == true_content def test_hello_asfdasdf(): page = requests.get('http://localhost:5000/hello/asfdasdf') true_content = '<h1>Hello asfdasdf</h1>' assert str(page.text) == true_content
- When it all passes your are done! The unit test is sending HTTP requests to your server and determining if it is returning the right content.
-
- Add the following code to test_webserver.py and run it using the command