From 94fd8de4263dc6294aa62425a5f98d905ef0584a Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 25 Dec 2019 03:35:14 -0800 Subject: Update quick_tour with cookiecutter master branch --- docs/quick_tour.rst | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index a428a77c3..e6914337f 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -493,7 +493,8 @@ So far we have done all of our *Quick Tour* as a single Python file. No Python packages, no structure. Most Pyramid projects, though, aren't developed this way. -To ease the process of getting started, the Pylons Project provides a :term:`cookiecutter` that generates sample Pyramid projects from project templates. This cookiecutter will install Pyramid and its dependencies as well. +To ease the process of getting started, the Pylons Project provides a :term:`cookiecutter` that generates a sample Pyramid project from project templates. +This cookiecutter will install Pyramid and its dependencies as well. First you'll need to install cookiecutter. @@ -894,9 +895,22 @@ We then run through the following commands as before. # Reset our environment variable for a new virtual environment. export VENV=~/sqla_demo/env -We now have a working sample SQLAlchemy application with all dependencies -installed. The sample project provides a console script to initialize a SQLite -database with tables. Let's run it, then start the application: +We now have a working sample SQLAlchemy application with all dependencies installed. +The sample project provides a method to generate a database migration from existing models and upgrade the database schema using Alembic. +Let's generate the first revision. + +.. code-block:: bash + + $VENV/bin/alembic -c development.ini revision --autogenerate -m "init" + +Now let's upgrade the database schema. + +.. code-block:: bash + + $VENV/bin/alembic -c development.ini upgrade head + +The sample project also provides a console script to load data into the SQLite database. +Let's run it, then start the application: .. code-block:: bash -- cgit v1.2.3 From 80e9923262fee4892a750d0d6366b193cb4204ba Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 1 Jan 2020 17:40:46 -0800 Subject: Resync through Quick Tour after moving tests directory --- docs/quick_tour.rst | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index e6914337f..b6e456d2b 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -676,15 +676,15 @@ the relevant ``.ini`` configuration file. :ref:`Quick Tutorial pyramid_debugtoolbar ` and :ref:`pyramid_debugtoolbar ` -Unit tests and ``pytest`` -========================= +Unit and functional tests and ``pytest`` +======================================== Yikes! We got this far and we haven't yet discussed tests. This is particularly egregious, as Pyramid has had a deep commitment to full test coverage since before its release. -Our ``pyramid-cookiecutter-starter`` cookiecutter generated a ``tests.py`` module with -one unit test and one functional test in it. It also configured ``setup.py`` with test requirements: +Our ``pyramid-cookiecutter-starter`` cookiecutter generated a ``test_it.py`` module inside the ``tests`` package with two unit tests and two functional tests in it. +It also configured ``setup.py`` with test requirements: ``pytest`` as the test runner, ``WebTest`` for running view tests, and the ``pytest-cov`` tool which yells at us for code that isn't tested: @@ -709,33 +709,35 @@ This yields the following output. .. code-block:: text =========================== test session starts =========================== - platform darwin -- Python 3.6.0, pytest-3.0.5, py-1.4.32, pluggy-0.4.0 - rootdir: /Users/stevepiercy/hello_world, inifile: pytest.ini - plugins: cov-2.4.0 - collected 2 items - - hello_world/tests.py .. - - ------------- coverage: platform darwin, python 3.6.0-final-0 ------------- - Name Stmts Miss Cover Missing - ----------------------------------------------------------------------- - hello_world/__init__.py 8 0 100% - hello_world/views.py 3 0 100% - ----------------------------------------------------------------------- - TOTAL 11 0 100% - - - ========================= 2 passed in 1.37 seconds ========================= + platform darwin -- Python 3.7.3, pytest-5.3.2, py-1.8.1, pluggy-0.13.1 + rootdir: //hello_world, inifile: pytest.ini, testpaths: hello_world, tests + plugins: cov-2.8.1 + collected 4 items + + tests/test_it.py .... [100%] + + ---------- coverage: platform darwin, python 3.7.3-final-0 ----------- + Name Stmts Miss Cover Missing + ------------------------------------------------------------- + hello_world/__init__.py 7 0 100% + hello_world/routes.py 3 0 100% + hello_world/views/__init__.py 0 0 100% + hello_world/views/default.py 3 0 100% + hello_world/views/notfound.py 4 0 100% + ------------------------------------------------------------- + TOTAL 17 0 100% + + ======================== 4 passed in 0.65 seconds ========================= Our tests passed, and its coverage is complete. What did our test look like? -.. literalinclude:: quick_tour/package/hello_world/tests.py +.. literalinclude:: quick_tour/package/hello_world/tests/test_it.py :language: python :linenos: -Pyramid supplies helpers for test writing, which we use in the test setup and -teardown. Our first test imports the view, makes a dummy request, and sees if the -view returns what we expected. Our second test verifies that the response body from a request to the web root contains what we expected. +Pyramid supplies helpers for test writing, which we use in the test setup and teardown. +Our view tests import the view, make a dummy request, and sees if the view returns what we expected. +Our functional tests verify that the response body from a request to the web root contains what we expected and that the expected response code for making a request to ``/badurl`` results in ``404``. .. seealso:: See also: :ref:`Quick Tutorial Unit Testing `, :ref:`Quick -- cgit v1.2.3 From dcdb9168aece7afd03194c11554d4a7e1bc32d06 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 1 Jan 2020 19:59:29 -0800 Subject: Fix broken literalinclude paths --- docs/quick_tour.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index b6e456d2b..062693d24 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -731,7 +731,7 @@ This yields the following output. Our tests passed, and its coverage is complete. What did our test look like? -.. literalinclude:: quick_tour/package/hello_world/tests/test_it.py +.. literalinclude:: quick_tour/package/tests/test_it.py :language: python :linenos: -- cgit v1.2.3