diff --git a/Listing_1.11.py b/Listing_1.11.py index 6da89e0..289f9ff 100644 --- a/Listing_1.11.py +++ b/Listing_1.11.py @@ -1,5 +1,6 @@ from flask import Flask + app = Flask(__name__) @app.route("/") diff --git a/Listing_10.10.txt b/Listing_10.10.txt new file mode 100644 index 0000000..f562008 --- /dev/null +++ b/Listing_10.10.txt @@ -0,0 +1,7 @@ +(venv) $ deactivate +$ rm -rf venv/ +$ python3 -m venv venv +$ source venv/bin/activate +(venv) $ pip install -r requirements.txt +(venv) $ flask --app palindrome_detector --debug run + * Running on http://127.0.0.1:5000/ diff --git a/Listing_10.11.py b/Listing_10.11.py new file mode 100644 index 0000000..5099793 --- /dev/null +++ b/Listing_10.11.py @@ -0,0 +1,26 @@ +import os + +from flask import Flask, render_template + + +def create_app(test_config=None): + """Create and configure the app.""" + app = Flask(__name__, instance_relative_config=True) + . + . + . + @app.route("/") + def index(): + return render_template("index.html") + + @app.route("/about") + def about(): + return render_template("about.html") + + @app.route("/palindrome") + def palindrome(): + return render_template("palindrome.html") + + return app + +app = create_app() diff --git a/Listing_10.12.html b/Listing_10.12.html index 052eb08..449b64c 100644 --- a/Listing_10.12.html +++ b/Listing_10.12.html @@ -14,18 +14,23 @@
-

About

+

Sample Flask App

- This site is the final application in + This is the sample Flask app for Learn Enough Python - to Be Dangerous - by Michael Hartl, - a tutorial introduction to the - Python programming language that - is part of - LearnEnough.com. + to Be Dangerous. Learn more on the About page.

+ +

+ Click the Sator + Square below to run the custom Palindrome + Detector. +

+ + + Sator Square +
diff --git a/Listing_10.13.html b/Listing_10.13.html index 4eede9f..052eb08 100644 --- a/Listing_10.13.html +++ b/Listing_10.13.html @@ -14,10 +14,18 @@
-

Palindrome Detector

- -

This will be the palindrome detector.

+

About

+

+ This site is the final application in + Learn Enough Python + to Be Dangerous + by Michael Hartl, + a tutorial introduction to the + Python programming language that + is part of + LearnEnough.com. +

diff --git a/Listing_10.14.html b/Listing_10.14.html new file mode 100644 index 0000000..4eede9f --- /dev/null +++ b/Listing_10.14.html @@ -0,0 +1,24 @@ + + + + + Learn Enough Python Sample App + + + + + +
+
+ +

Palindrome Detector

+ +

This will be the palindrome detector.

+ +
+
+ + diff --git a/Listing_10.15.py b/Listing_10.15.py new file mode 100644 index 0000000..e808d40 --- /dev/null +++ b/Listing_10.15.py @@ -0,0 +1,10 @@ +% import os +% from flask import Flask + +% def create_app(test_config=None): +% """Create and configure the app.""" +% app = Flask(__name__, instance_relative_config=True, +% static_url_path="/static") +% . +% . +% . diff --git a/Listing_10.16.html b/Listing_10.16.html new file mode 100644 index 0000000..26c826e --- /dev/null +++ b/Listing_10.16.html @@ -0,0 +1,20 @@ + + + + + Learn Enough Python Sample App + + + + + +
+
+ +
+
+ + diff --git a/Listing_10.17.txt b/Listing_10.17.txt new file mode 100644 index 0000000..922fb8f --- /dev/null +++ b/Listing_10.17.txt @@ -0,0 +1 @@ +$ pip install -e . diff --git a/Listing_10.18.py b/Listing_10.18.py new file mode 100644 index 0000000..39165a4 --- /dev/null +++ b/Listing_10.18.py @@ -0,0 +1,12 @@ +import pytest + +from palindrome_detector import create_app + + +@pytest.fixture +def app(): + return create_app() + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/Listing_10.19.py b/Listing_10.19.py index 2a665a8..32e7b02 100644 --- a/Listing_10.19.py +++ b/Listing_10.19.py @@ -1,17 +1,11 @@ def test_index(client): response = client.get("/") assert response.status_code == 200 - assert "" in response.text - assert "<h1>" in response.text def test_about(client): response = client.get("/about") assert response.status_code == 200 - assert "<title>" in response.text - assert "<h1>" in response.text def test_palindrome(client): response = client.get("/palindrome") assert response.status_code == 200 - assert "<title>" in response.text - assert "<h1>" in response.text diff --git a/Listing_10.21.py b/Listing_10.21.py new file mode 100644 index 0000000..2a665a8 --- /dev/null +++ b/Listing_10.21.py @@ -0,0 +1,17 @@ +def test_index(client): + response = client.get("/") + assert response.status_code == 200 + assert "<title>" in response.text + assert "<h1>" in response.text + +def test_about(client): + response = client.get("/about") + assert response.status_code == 200 + assert "<title>" in response.text + assert "<h1>" in response.text + +def test_palindrome(client): + response = client.get("/palindrome") + assert response.status_code == 200 + assert "<title>" in response.text + assert "<h1>" in response.text diff --git a/Listing_10.22.txt b/Listing_10.22.txt new file mode 100644 index 0000000..c8a9871 --- /dev/null +++ b/Listing_10.22.txt @@ -0,0 +1,7 @@ +(venv) $ pytest +============================= test session starts ============================== +collected 3 items + +tests/test_site_pages.py ... [100%] + +============================== 3 passed in 0.01s =============================== diff --git a/Listing_10.23.html b/Listing_10.23.html index 1966020..3e73ccd 100644 --- a/Listing_10.23.html +++ b/Listing_10.23.html @@ -1,16 +1,20 @@ -{% extends "layout.html" %} - -{% block content %} - <h1>About</h1> - - <p> - This site is the final application in - <a href="https://www.learnenough.com/python-tutorial"><em>Learn Enough Python - to Be Dangerous</em></a> - by <a href="https://www.michaelhartl.com/">Michael Hartl</a>, - a tutorial introduction to the - <a href="https://www.python.org/">Python programming language</a> that - is part of - <a href="https://www.learnenough.com/">LearnEnough.com</a>. - </p> -{% endblock %} +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title>Learn Enough Python Sample App + + + + + +
+
+ {% block content %}{% endblock %} +
+
+ + diff --git a/Listing_10.24.html b/Listing_10.24.html index ce855ea..c7039e8 100644 --- a/Listing_10.24.html +++ b/Listing_10.24.html @@ -1,7 +1,21 @@ {% extends "layout.html" %} {% block content %} -

Palindrome Detector

+

Sample Flask App

-

This will be the palindrome detector.

+

+ This is the sample Flask app for + Learn Enough Python + to Be Dangerous. Learn more on the About page. +

+ +

+ Click the Sator + Square below to run the custom Palindrome + Detector. +

+ + + Sator Square + {% endblock %} diff --git a/Listing_10.25.html b/Listing_10.25.html new file mode 100644 index 0000000..1966020 --- /dev/null +++ b/Listing_10.25.html @@ -0,0 +1,16 @@ +{% extends "layout.html" %} + +{% block content %} +

About

+ +

+ This site is the final application in + Learn Enough Python + to Be Dangerous + by Michael Hartl, + a tutorial introduction to the + Python programming language that + is part of + LearnEnough.com. +

+{% endblock %} diff --git a/Listing_10.26.html b/Listing_10.26.html new file mode 100644 index 0000000..ce855ea --- /dev/null +++ b/Listing_10.26.html @@ -0,0 +1,7 @@ +{% extends "layout.html" %} + +{% block content %} +

Palindrome Detector

+ +

This will be the palindrome detector.

+{% endblock %} diff --git a/Listing_10.28.py b/Listing_10.28.py index aaf26fa..6a720a5 100644 --- a/Listing_10.28.py +++ b/Listing_10.28.py @@ -2,7 +2,7 @@ def test_index(client): response = client.get("/") assert response.status_code == 200 base_title = "Learn Enough Python Sample App" - title = f"{base_title} | Home" + title = f"{base_title}" assert title in response.text assert "

" in response.text @@ -10,7 +10,7 @@ def test_about(client): response = client.get("/about") assert response.status_code == 200 base_title = "Learn Enough Python Sample App" - title = f"{base_title} | About" + title = f"{base_title}" assert title in response.text assert "

" in response.text @@ -18,6 +18,6 @@ def test_palindrome(client): response = client.get("/palindrome") assert response.status_code == 200 base_title = "Learn Enough Python Sample App" - title = f"{base_title} | Palindrome Detector" + title = f"{base_title}" assert title in response.text assert "

" in response.text diff --git a/Listing_10.29.txt b/Listing_10.29.txt index 5c79f54..c8a9871 100644 --- a/Listing_10.29.txt +++ b/Listing_10.29.txt @@ -2,15 +2,6 @@ ============================= test session starts ============================== collected 3 items -tests/test_site_pages.py FFF [100%] +tests/test_site_pages.py ... [100%] -=================================== FAILURES =================================== -__________________________________ test_index __________________________________ -. -. -. -=========================== short test summary info ============================ -FAILED tests/test_site_pages.py::test_index - assert 'Learn Enough Pyt... -FAILED tests/test_site_pages.py::test_about - assert '<title>Learn Enough Pyt... -FAILED tests/test_site_pages.py::test_palindrome - assert '<title>Learn Enoug... -============================== 3 failed in 0.03s =============================== +============================== 3 passed in 0.01s =============================== diff --git a/Listing_10.3.py b/Listing_10.3.py index d6107f4..386c2f5 100644 --- a/Listing_10.3.py +++ b/Listing_10.3.py @@ -1,6 +1,8 @@ import os + from flask import Flask + def create_app(test_config=None): """Create and configure the app.""" app = Flask(__name__, instance_relative_config=True) diff --git a/Listing_10.30.py b/Listing_10.30.py index 0fa858f..aaf26fa 100644 --- a/Listing_10.30.py +++ b/Listing_10.30.py @@ -1,36 +1,23 @@ -import os -from flask import Flask, render_template +def test_index(client): + response = client.get("/") + assert response.status_code == 200 + base_title = "Learn Enough Python Sample App" + title = f"<title>{base_title} | Home" + assert title in response.text + assert "

" in response.text -def create_app(test_config=None): - """Create and configure the app.""" - app = Flask(__name__, instance_relative_config=True) +def test_about(client): + response = client.get("/about") + assert response.status_code == 200 + base_title = "Learn Enough Python Sample App" + title = f"{base_title} | About" + assert title in response.text + assert "

" in response.text - if test_config is None: - # Load the instance config, if it exists, when not testing. - app.config.from_pyfile("config.py", silent=True) - else: - # Load the test config if passed in. - app.config.from_mapping(test_config) - - # Ensure the instance folder exists. - try: - os.makedirs(app.instance_path) - except OSError: - pass - - @app.route("/") - def index(): - return render_template("index.html", page_title="Home") - - @app.route("/about") - def about(): - return render_template("about.html", page_title="About") - - @app.route("/palindrome") - def palindrome(): - return render_template("palindrome.html", - page_title="Palindrome Detector") - - return app - -app = create_app() +def test_palindrome(client): + response = client.get("/palindrome") + assert response.status_code == 200 + base_title = "Learn Enough Python Sample App" + title = f"{base_title} | Palindrome Detector" + assert title in response.text + assert "

" in response.text diff --git a/Listing_10.31.txt b/Listing_10.31.txt new file mode 100644 index 0000000..5c79f54 --- /dev/null +++ b/Listing_10.31.txt @@ -0,0 +1,16 @@ +(venv) $ pytest +============================= test session starts ============================== +collected 3 items + +tests/test_site_pages.py FFF [100%] + +=================================== FAILURES =================================== +__________________________________ test_index __________________________________ +. +. +. +=========================== short test summary info ============================ +FAILED tests/test_site_pages.py::test_index - assert 'Learn Enough Pyt... +FAILED tests/test_site_pages.py::test_about - assert '<title>Learn Enough Pyt... +FAILED tests/test_site_pages.py::test_palindrome - assert '<title>Learn Enoug... +============================== 3 failed in 0.03s =============================== diff --git a/Listing_10.32.py b/Listing_10.32.py new file mode 100644 index 0000000..c816a9f --- /dev/null +++ b/Listing_10.32.py @@ -0,0 +1,38 @@ +import os + +from flask import Flask, render_template + + +def create_app(test_config=None): + """Create and configure the app.""" + app = Flask(__name__, instance_relative_config=True) + + if test_config is None: + # Load the instance config, if it exists, when not testing. + app.config.from_pyfile("config.py", silent=True) + else: + # Load the test config if passed in. + app.config.from_mapping(test_config) + + # Ensure the instance folder exists. + try: + os.makedirs(app.instance_path) + except OSError: + pass + + @app.route("/") + def index(): + return render_template("index.html", page_title="Home") + + @app.route("/about") + def about(): + return render_template("about.html", page_title="About") + + @app.route("/palindrome") + def palindrome(): + return render_template("palindrome.html", + page_title="Palindrome Detector") + + return app + +app = create_app() diff --git a/Listing_10.33.html b/Listing_10.33.html index 809c2ec..87e1e77 100644 --- a/Listing_10.33.html +++ b/Listing_10.33.html @@ -3,27 +3,6 @@ <head> <meta charset="utf-8"> <title>Learn Enough Python Sample App | {{ page_title }} - - - - - -
-
- -
-
- {% block content %}{% endblock %} -
-
- - + . + . + . diff --git a/Listing_10.34.txt b/Listing_10.34.txt new file mode 100644 index 0000000..c8a9871 --- /dev/null +++ b/Listing_10.34.txt @@ -0,0 +1,7 @@ +(venv) $ pytest +============================= test session starts ============================== +collected 3 items + +tests/test_site_pages.py ... [100%] + +============================== 3 passed in 0.01s =============================== diff --git a/Listing_10.35.html b/Listing_10.35.html new file mode 100644 index 0000000..809c2ec --- /dev/null +++ b/Listing_10.35.html @@ -0,0 +1,29 @@ + + + + + Learn Enough Python Sample App | {{ page_title }} + + + + + +
+
+ +
+
+ {% block content %}{% endblock %} +
+
+ + diff --git a/Listing_10.36.py b/Listing_10.36.py new file mode 100644 index 0000000..58b21c5 --- /dev/null +++ b/Listing_10.36.py @@ -0,0 +1,24 @@ +def test_index(client): + response = client.get("/") + assert response.status_code == 200 + base_title = "Learn Enough Python Sample App" + title = f"{base_title} | Home" + assert title in response.text + assert "

" in response.text + assert "