From 7b3e63ae38cdb4084ef5423d0f8a7166ca2b0563 Mon Sep 17 00:00:00 2001 From: ayush bora Date: Sat, 10 May 2025 12:32:47 +0530 Subject: [PATCH] Added pytest for /posts route and updated template --- ...dd_url_field_in_posts_model.cpython-36.pyc | Bin 838 -> 838 bytes ...590e2e6e_create_posts_table.cpython-36.pyc | Bin 1103 -> 1103 bytes blogexample/templates/posts.html | 56 +++++++++++------- lib/__pycache__/util_datetime.cpython-36.pyc | Bin 1205 -> 1205 bytes .../util_sqlalchemy.cpython-36.pyc | Bin 4237 -> 4237 bytes pytest.ini | 3 + tests/conftest.py | 11 ++++ tests/test_routes.py | 4 ++ 8 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 pytest.ini create mode 100644 tests/conftest.py create mode 100644 tests/test_routes.py diff --git a/blogexample/migrations/versions/__pycache__/29d9055c6a28_create_add_url_field_in_posts_model.cpython-36.pyc b/blogexample/migrations/versions/__pycache__/29d9055c6a28_create_add_url_field_in_posts_model.cpython-36.pyc index 4fecab943c3b6d40a984e32f85d17c3d69f68ed1..963923c1fec29a8dd5b4a6c98e66eebf8f843334 100644 GIT binary patch delta 18 ZcmX@cc8rbFn3tDJuv8*r&PGmKW&kaN1eE{) delta 18 ZcmX@cc8rbFn3tD}{drGf#YRqBW&kq>1x5e> diff --git a/blogexample/migrations/versions/__pycache__/5deb590e2e6e_create_posts_table.cpython-36.pyc b/blogexample/migrations/versions/__pycache__/5deb590e2e6e_create_posts_table.cpython-36.pyc index 46ad92907d20e59e771cd66cac6644b54c4f849c..b5cc132c994b24237fb52b7cb9f74fbfeb7bbd62 100644 GIT binary patch delta 19 acmX@lah`+An3tDJuv8*Lj&&oKD+>TG?gTvm delta 19 acmX@lah`+An3tD}{drH~Czg#|t}FmM?gixl diff --git a/blogexample/templates/posts.html b/blogexample/templates/posts.html index 5e3b162..e02ec66 100644 --- a/blogexample/templates/posts.html +++ b/blogexample/templates/posts.html @@ -7,35 +7,40 @@ Posts - - + + + - - @@ -47,9 +52,11 @@ {% with messages = get_flashed_messages() %} {% if messages %} +
{% for message in messages %} -

{{ message }}

+

{{ message }}

{% endfor %} +
{% endif %} {% endwith %}
@@ -57,10 +64,13 @@

{{ message }}

{{each_post.title}}

-
-     -     - +
+ + +
+ +
+

{{ each_post.body|safe }}

diff --git a/lib/__pycache__/util_datetime.cpython-36.pyc b/lib/__pycache__/util_datetime.cpython-36.pyc index a0f68043ce1aa63b5cbf03393dcb80c2622b6876..22dcc7caff106c793c56ee502c8800ed4842fb4e 100644 GIT binary patch delta 18 ZcmdnWxs{XCn3tDJuv8-B$41UIEC4P{1w{Y= delta 18 ZcmdnWxs{XCn3tD}{drH~sg0a#SO7Dg1?&I- diff --git a/lib/__pycache__/util_sqlalchemy.cpython-36.pyc b/lib/__pycache__/util_sqlalchemy.cpython-36.pyc index f9874a68d257af7fc47e8259375f455b97bcdadf..b91fd96d9fe939737dc3974dd291066c8ffbba4f 100644 GIT binary patch delta 19 acmeBG>{aA4=H=xQES1PG{aA4=H=yLf8LY0iEkrUvj6}!G6kmq diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..00b0c1e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +pythonpath = . +addopts = --maxfail=1 --disable-warnings -v diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..40ef36d --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,11 @@ +import pytest +from blogexample.app import create_app # Adjust to your actual app location + +@pytest.fixture +def app(): + app = create_app() # If your app creation function is called create_app + yield app + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/test_routes.py b/tests/test_routes.py new file mode 100644 index 0000000..63d383a --- /dev/null +++ b/tests/test_routes.py @@ -0,0 +1,4 @@ +def test_home_route_status_code(client): + """Test the status code of the posts route""" + response = client.get('/posts') + assert response.status_code == 200