From fe4465b91296ca7d41c4f7c8006cbd8d50851a09 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Fri, 20 Nov 2015 17:48:38 -0800 Subject: wiki2/tests - commit progress --- docs/tutorials/wiki2/tests.rst | 77 +++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 24 deletions(-) (limited to 'docs/tutorials/wiki2/tests.rst') diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index 9db95334a..64025421f 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -2,25 +2,38 @@ Adding Tests ============ -We will now add tests for the models and the views and a few functional tests -in ``tests.py``. Tests ensure that an application works, and that it -continues to work when changes are made in the future. +We will now add tests for the models and views as well as a few functional +tests in a new ``tests`` subpackage. Tests ensure that an application works, +and that it continues to work when changes are made in the future. + +The file ``tests.py`` was generated as part of the ``alchemy`` scaffold, but it +is a common practice to put tests into a ``tests`` subpackage, especially as +projects grow in size and complexity. Each module in the test subpackage +should contain tests for its corresponding module in our application. Each +corresponding pair of modules should have the same names, except the test +module should have the prefix "test_". + +We will move parts of ``tests.py`` into appropriate new files in the ``tests`` +subpackage, and add several new tests. + Test the models =============== -To test the model class ``Page`` we'll add a new ``PageModelTests`` class to -our ``tests.py`` file that was generated as part of the ``alchemy`` scaffold. +To test the model class ``Page``, we'll add a new ``PageModelTests`` class to +a new file ``tests/test_models.py`` + Test the views ============== -We'll modify our ``tests.py`` file, adding tests for each view function we -added previously. As a result, we'll *delete* the ``ViewTests`` class that -the ``alchemy`` scaffold provided, and add four other test classes: -``ViewWikiTests``, ``ViewPageTests``, ``AddPageTests``, and ``EditPageTests``. -These test the ``view_wiki``, ``view_page``, ``add_page``, and ``edit_page`` -views. +We'll create a new ``tests/test_views.py`` file, adding tests for each view +function we previously added to our application. As a result, we'll *delete* +the ``ViewTests`` class that the ``alchemy`` scaffold provided, and add four +other test classes: ``ViewWikiTests``, ``ViewPageTests``, ``AddPageTests``, and +``EditPageTests``. These test the ``view_wiki``, ``view_page``, ``add_page``, +and ``edit_page`` views. + Functional tests ================ @@ -30,23 +43,41 @@ tested in the unit tests, like logging in, logging out, checking that the ``viewer`` user cannot add or edit pages, but the ``editor`` user can, and so on. -View the results of all our edits to ``tests.py`` -================================================= -Open the ``tutorial/tests.py`` module, and edit it such that it appears as +View the results of all our edits to ``tests`` subpackage +========================================================= + +Open ``tutorial/tests/test_models.py``, and edit it such that it appears as follows: -.. literalinclude:: src/tests/tutorial/tests.py +.. literalinclude:: src/tests/tutorial/tests/test_models.py :linenos: :language: python +Open ``tutorial/tests/test_views.py``, and edit it such that it appears as +follows: + +.. literalinclude:: src/tests/tutorial/tests/test_views.py + :linenos: + :language: python + +Open ``tutorial/tests/test_.py``, and edit it such that it appears as +follows: + +.. literalinclude:: src/tests/tutorial/tests/test_.py + :linenos: + :language: python + + Running the tests ================= We can run these tests by using ``setup.py test`` in the same way we did in -:ref:`running_tests`. However, first we must edit our ``setup.py`` to -include a dependency on WebTest, which we've used in our ``tests.py``. -Change the ``requires`` list in ``setup.py`` to include ``WebTest``. +:ref:`running_tests`. However, first we must edit our ``setup.py`` to include +a dependency on `WebTest +`_, which we've used +in our ``tests.py``. Change the ``requires`` list in ``setup.py`` to include +``WebTest``. .. literalinclude:: src/tests/setup.py :linenos: @@ -56,12 +87,11 @@ Change the ``requires`` list in ``setup.py`` to include ``WebTest``. After we've added a dependency on WebTest in ``setup.py``, we need to run ``setup.py develop`` to get WebTest installed into our virtualenv. Assuming -our shell's current working directory is the "tutorial" distribution -directory: +our shell's current working directory is the "tutorial" distribution directory: On UNIX: -.. code-block:: text +.. code-block:: bash $ $VENV/bin/python setup.py develop @@ -71,12 +101,11 @@ On Windows: c:\pyramidtut\tutorial> %VENV%\Scripts\python setup.py develop -Once that command has completed successfully, we can run the tests -themselves: +Once that command has completed successfully, we can run the tests themselves: On UNIX: -.. code-block:: text +.. code-block:: bash $ $VENV/bin/python setup.py test -q -- cgit v1.2.3 From f10fb24a3663cb070b28b8020fde957d16563400 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 2 Dec 2015 04:18:10 -0800 Subject: - rewrite wiki2/tests.rst (removed an obsolete reference to testing models, per 2885a7b96545c037109d7999319f74869a640050) - add wiki2/src/tests/ files. special thanks to @ppaez --- docs/tutorials/wiki2/tests.rst | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'docs/tutorials/wiki2/tests.rst') diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index 64025421f..fe3fdaf2c 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -11,17 +11,12 @@ is a common practice to put tests into a ``tests`` subpackage, especially as projects grow in size and complexity. Each module in the test subpackage should contain tests for its corresponding module in our application. Each corresponding pair of modules should have the same names, except the test -module should have the prefix "test_". +module should have the prefix ``test_``. We will move parts of ``tests.py`` into appropriate new files in the ``tests`` subpackage, and add several new tests. - -Test the models -=============== - -To test the model class ``Page``, we'll add a new ``PageModelTests`` class to -a new file ``tests/test_models.py`` +Start by creating a new directory and a new empty file ``tests/__init__.py``. Test the views @@ -47,13 +42,6 @@ can, and so on. View the results of all our edits to ``tests`` subpackage ========================================================= -Open ``tutorial/tests/test_models.py``, and edit it such that it appears as -follows: - -.. literalinclude:: src/tests/tutorial/tests/test_models.py - :linenos: - :language: python - Open ``tutorial/tests/test_views.py``, and edit it such that it appears as follows: @@ -61,10 +49,10 @@ follows: :linenos: :language: python -Open ``tutorial/tests/test_.py``, and edit it such that it appears as +Open ``tutorial/tests/test_functional.py``, and edit it such that it appears as follows: -.. literalinclude:: src/tests/tutorial/tests/test_.py +.. literalinclude:: src/tests/tutorial/tests/test_functional.py :linenos: :language: python @@ -119,8 +107,10 @@ The expected result should look like the following: .. code-block:: text - ...................... + .................... ---------------------------------------------------------------------- - Ran 21 tests in 2.700s + Ran 20 tests in 0.524s OK + + Process finished with exit code 0 -- cgit v1.2.3 From 1c108019dae884e810d6436e10f8648c77bdd181 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 8 Feb 2016 00:43:47 -0600 Subject: [wip] update tests in wiki2 tutorial --- docs/tutorials/wiki2/tests.rst | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'docs/tutorials/wiki2/tests.rst') diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index fe3fdaf2c..a99cd68cc 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -18,6 +18,14 @@ subpackage, and add several new tests. Start by creating a new directory and a new empty file ``tests/__init__.py``. +.. warning:: + + It is very important when refactoring a Python module into a package to + be sure to delete the cache files (``.pyc`` files or ``__pycache__`` + folders) sitting around! Python will prioritize the cache files before + traversing into folders and so it will use the old code and you will wonder + why none of your changes are working! + Test the views ============== -- cgit v1.2.3 From 66fabb4ac707b5b4289db0094756f1a1af7269cc Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 18 Feb 2016 02:32:08 -0600 Subject: update tests chapter --- docs/tutorials/wiki2/tests.rst | 43 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'docs/tutorials/wiki2/tests.rst') diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index a99cd68cc..667550467 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -43,7 +43,7 @@ Functional tests We'll test the whole application, covering security aspects that are not tested in the unit tests, like logging in, logging out, checking that -the ``viewer`` user cannot add or edit pages, but the ``editor`` user +the ``basic`` user cannot edit pages it didn't create, but the ``editor`` user can, and so on. @@ -65,39 +65,20 @@ follows: :language: python -Running the tests -================= - -We can run these tests by using ``setup.py test`` in the same way we did in -:ref:`running_tests`. However, first we must edit our ``setup.py`` to include -a dependency on `WebTest -`_, which we've used -in our ``tests.py``. Change the ``requires`` list in ``setup.py`` to include -``WebTest``. - -.. literalinclude:: src/tests/setup.py - :linenos: - :language: python - :lines: 11-22 - :emphasize-lines: 11 +.. note:: -After we've added a dependency on WebTest in ``setup.py``, we need to run -``setup.py develop`` to get WebTest installed into our virtualenv. Assuming -our shell's current working directory is the "tutorial" distribution directory: + We're utilizing the excellent WebTest_ package to do functional testing + of the application. This is defined in the ``tests_require`` section of + our ``setup.py``. Any other dependencies needed only for testing purposes + can be added there and will be installed automatically when running + ``setup.py test``. -On UNIX: - -.. code-block:: bash - $ $VENV/bin/python setup.py develop - -On Windows: - -.. code-block:: text - - c:\pyramidtut\tutorial> %VENV%\Scripts\python setup.py develop +Running the tests +================= -Once that command has completed successfully, we can run the tests themselves: +We can run these tests by using ``setup.py test`` in the same way we did in +:ref:`running_tests`: On UNIX: @@ -122,3 +103,5 @@ The expected result should look like the following: OK Process finished with exit code 0 + +.. _webtest: http://docs.pylonsproject.org/projects/webtest/en/latest/ -- cgit v1.2.3 From 606f753fc2ca310debc501874db16b60180773d2 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 28 Feb 2016 02:34:24 -0800 Subject: update tests.rst (done) - minor grammar - mention BaseTest class - clean up test output --- docs/tutorials/wiki2/tests.rst | 52 +++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'docs/tutorials/wiki2/tests.rst') diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index 667550467..fa9cbe2fc 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -13,38 +13,36 @@ should contain tests for its corresponding module in our application. Each corresponding pair of modules should have the same names, except the test module should have the prefix ``test_``. -We will move parts of ``tests.py`` into appropriate new files in the ``tests`` -subpackage, and add several new tests. - -Start by creating a new directory and a new empty file ``tests/__init__.py``. +Start by deleting ``tests.py``, then create a new directory to contain our new +tests as well as a new empty file ``tests/__init__.py``. .. warning:: - It is very important when refactoring a Python module into a package to - be sure to delete the cache files (``.pyc`` files or ``__pycache__`` - folders) sitting around! Python will prioritize the cache files before - traversing into folders and so it will use the old code and you will wonder - why none of your changes are working! + It is very important when refactoring a Python module into a package to be + sure to delete the cache files (``.pyc`` files or ``__pycache__`` folders) + sitting around! Python will prioritize the cache files before traversing + into folders, using the old code, and you will wonder why none of your + changes are working! Test the views ============== -We'll create a new ``tests/test_views.py`` file, adding tests for each view -function we previously added to our application. As a result, we'll *delete* -the ``ViewTests`` class that the ``alchemy`` scaffold provided, and add four -other test classes: ``ViewWikiTests``, ``ViewPageTests``, ``AddPageTests``, and -``EditPageTests``. These test the ``view_wiki``, ``view_page``, ``add_page``, -and ``edit_page`` views. +We'll create a new ``tests/test_views.py`` file, adding a ``BaseTest`` class +used as the base for other test classes. Next we'll add tests for each view +function we previously added to our application. We'll add four test classes: +``ViewWikiTests``, ``ViewPageTests``, ``AddPageTests``, and ``EditPageTests``. +These test the ``view_wiki``, ``view_page``, ``add_page``, and ``edit_page`` +views. Functional tests ================ -We'll test the whole application, covering security aspects that are not -tested in the unit tests, like logging in, logging out, checking that -the ``basic`` user cannot edit pages it didn't create, but the ``editor`` user -can, and so on. +We'll test the whole application, covering security aspects that are not tested +in the unit tests, like logging in, logging out, checking that the ``basic`` +user cannot edit pages that it didn't create but the ``editor`` user can, and +so on. View the results of all our edits to ``tests`` subpackage @@ -67,10 +65,10 @@ follows: .. note:: - We're utilizing the excellent WebTest_ package to do functional testing - of the application. This is defined in the ``tests_require`` section of - our ``setup.py``. Any other dependencies needed only for testing purposes - can be added there and will be installed automatically when running + We're utilizing the excellent WebTest_ package to do functional testing of + the application. This is defined in the ``tests_require`` section of our + ``setup.py``. Any other dependencies needed only for testing purposes can be + added there and will be installed automatically when running ``setup.py test``. @@ -88,7 +86,7 @@ On UNIX: On Windows: -.. code-block:: text +.. code-block:: ps1con c:\pyramidtut\tutorial> %VENV%\Scripts\python setup.py test -q @@ -96,12 +94,10 @@ The expected result should look like the following: .. code-block:: text - .................... + ..................... ---------------------------------------------------------------------- - Ran 20 tests in 0.524s + Ran 21 tests in 5.117s OK - Process finished with exit code 0 - .. _webtest: http://docs.pylonsproject.org/projects/webtest/en/latest/ -- cgit v1.2.3 From de3062576ce5aa8b2e854626a48e3f5c46b29cb7 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 28 Feb 2016 11:57:14 -0800 Subject: add note about deprecation warnings on py3 --- docs/tutorials/wiki2/tests.rst | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'docs/tutorials/wiki2/tests.rst') diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index fa9cbe2fc..dabb73956 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -100,4 +100,11 @@ The expected result should look like the following: OK +.. note:: If you use Python 3 during this tutorial, you will see deprecation + warnings in the output, which we will choose to ignore. In making this + tutorial run on both Python 2 and 3, the authors prioritized simplicity and + focus for the learner over accommodating warnings. In your own app or as + extra credit, you may choose to either drop Python 2 support or hack your + code to work without warnings on both Python 2 and 3. + .. _webtest: http://docs.pylonsproject.org/projects/webtest/en/latest/ -- cgit v1.2.3 From 3e30040da7c2d5c38b330727b48d9f6b852956d9 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 28 Feb 2016 22:30:22 -0800 Subject: redirect to edit page when user attempts to add page that already exists - update src/*/views/default.py - update src/*/routes.py - write new test - revise docs, double-checking line counts and highlighting --- docs/tutorials/wiki2/tests.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorials/wiki2/tests.rst') diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index dabb73956..54aea28c6 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -96,7 +96,7 @@ The expected result should look like the following: ..................... ---------------------------------------------------------------------- - Ran 21 tests in 5.117s + Ran 22 tests in 5.320s OK -- cgit v1.2.3