From b1b92284f496800a4dfd2cea72cb9be07ba8661c Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 16:52:14 -0400 Subject: First cut at import of quick tutorial. --- docs/quick_tutorial/functional_testing.rst | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 docs/quick_tutorial/functional_testing.rst (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst new file mode 100644 index 000000000..777cb01e2 --- /dev/null +++ b/docs/quick_tutorial/functional_testing.rst @@ -0,0 +1,68 @@ +=================================== +06: Functional Testing with WebTest +=================================== + +Write end-to-end full-stack testing using ``webtest``. + +Background +========== + +Unit tests are a common and popular approach to test-driven development +(TDD.) In web applications, though, the templating and entire apparatus +of a web site are important parts of the delivered quality. We'd like a +way to test these. + +WebTest is a Python package that does functional testing. With WebTest +you can write tests which simulate a full HTTP request against a WSGI +application, then test the information in the response. For speed +purposes, WebTest skips the setup/teardown of an actual HTTP server, +providing tests that run fast enough to be part of TDD. + +Objectives +========== + +- Write a test which checks the contents of the returned HTML + +Steps +===== + +#. First we copy the results of the previous step, as well as install + the ``webtest`` package: + + .. code-block:: bash + + (env27)$ cd ..; cp -r unit_testing functional_testing; cd functional_testing + (env27)$ python setup.py develop + (env27)$ easy_install webtest + +#. Let's extend ``unit_testing/tutorial/tests.py`` to include a + functional test: + + .. literalinclude:: functional_testing/tutorial/tests.py + :linenos: + +#. Now run the tests: + + .. code-block:: bash + + + (env27)$ nosetests tutorial + . + ---------------------------------------------------------------------- + Ran 2 tests in 0.141s + + OK + +Analysis +======== + +We now have the end-to-end testing we were looking for. WebTest lets us +simply extend our existing ``nose``-based test approach with functional +tests that are reported in the same output. These new tests not only +cover our templating, but they didn't dramatically increase the +execution time of our tests. + +Extra Credit +============ + +#. Why do our functional tests use ``b''``? \ No newline at end of file -- cgit v1.2.3 From 0a784868bdbc3a0eb226ed00e8d89cda9d181ec5 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 17:11:42 -0400 Subject: Fix naming of virtualenv prefix. --- docs/quick_tutorial/functional_testing.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index 777cb01e2..c3d3299bc 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -31,9 +31,9 @@ Steps .. code-block:: bash - (env27)$ cd ..; cp -r unit_testing functional_testing; cd functional_testing - (env27)$ python setup.py develop - (env27)$ easy_install webtest + (env)$ cd ..; cp -r unit_testing functional_testing; cd functional_testing + (env)$ python setup.py develop + (env)$ easy_install webtest #. Let's extend ``unit_testing/tutorial/tests.py`` to include a functional test: @@ -46,7 +46,7 @@ Steps .. code-block:: bash - (env27)$ nosetests tutorial + (env)$ nosetests tutorial . ---------------------------------------------------------------------- Ran 2 tests in 0.141s -- cgit v1.2.3 From b0b28ede912c817a62a84b97c332e39eda02d166 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 16 Sep 2013 02:14:53 +0200 Subject: s/env/venv just for sake of consistency --- docs/quick_tutorial/functional_testing.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index c3d3299bc..c7accdc4e 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -31,9 +31,9 @@ Steps .. code-block:: bash - (env)$ cd ..; cp -r unit_testing functional_testing; cd functional_testing - (env)$ python setup.py develop - (env)$ easy_install webtest + (venv)$ cd ..; cp -r unit_testing functional_testing; cd functional_testing + (venv)$ python setup.py develop + (venv)$ easy_install webtest #. Let's extend ``unit_testing/tutorial/tests.py`` to include a functional test: @@ -46,7 +46,7 @@ Steps .. code-block:: bash - (env)$ nosetests tutorial + (venv)$ nosetests tutorial . ---------------------------------------------------------------------- Ran 2 tests in 0.141s -- cgit v1.2.3 From 187104fd81418beeb51592913041d9751bafe08d Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Wed, 25 Sep 2013 09:27:43 -0400 Subject: Quick Tutorial: Improve the setup instructions (adapted from Steve Piercy's work), particularly for Windows. Change all the steps to use $VENV/bin prefixes on commands (don't presume that they have done source env/bin/activate). --- docs/quick_tutorial/functional_testing.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index c7accdc4e..c9c99d76f 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -31,9 +31,9 @@ Steps .. code-block:: bash - (venv)$ cd ..; cp -r unit_testing functional_testing; cd functional_testing - (venv)$ python setup.py develop - (venv)$ easy_install webtest + $ cd ..; cp -r unit_testing functional_testing; cd functional_testing + $ $VENV/bin/python setup.py develop + $ $VENV/bin/easy_install webtest #. Let's extend ``unit_testing/tutorial/tests.py`` to include a functional test: @@ -46,7 +46,7 @@ Steps .. code-block:: bash - (venv)$ nosetests tutorial + $ $VENV/bin/nosetests tutorial . ---------------------------------------------------------------------- Ran 2 tests in 0.141s -- cgit v1.2.3 From b731b5fca253d9d95b3307490aa585e194676c01 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Thu, 26 Sep 2013 17:41:44 -0400 Subject: Quick Tour: shorten the setup part and point to Quick Tutorial Requirements for more explanation. Cross link each Quick Tour section with its Quick Tutorial match. --- docs/quick_tutorial/functional_testing.rst | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index c9c99d76f..205ddf5cb 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -1,3 +1,5 @@ +.. _qtut_functional_testing: + =================================== 06: Functional Testing with WebTest =================================== -- cgit v1.2.3 From c92f49b63f005a63a0d9ac33973e7cec84b07c55 Mon Sep 17 00:00:00 2001 From: deisner Date: Mon, 6 Oct 2014 17:01:40 -0400 Subject: Update functional_testing.rst Make it clear that the tests.py file in the functional_testing directory is the one to edit. Also, warn about a potential "gotcha": if the tests.py file is executable, it will be silently ignored. (I ran into this problem while going through the tutorial. This can happen if the file is being edited on a network file share from a different OS, for example.). --- docs/quick_tutorial/functional_testing.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index 205ddf5cb..ddcf6b77d 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -37,12 +37,14 @@ Steps $ $VENV/bin/python setup.py develop $ $VENV/bin/easy_install webtest -#. Let's extend ``unit_testing/tutorial/tests.py`` to include a +#. Let's extend ``functional_testing/tutorial/tests.py`` to include a functional test: .. literalinclude:: functional_testing/tutorial/tests.py :linenos: + Be sure this file is not executable, or ``nosetests`` may not include your tests. + #. Now run the tests: .. code-block:: bash @@ -67,4 +69,4 @@ execution time of our tests. Extra Credit ============ -#. Why do our functional tests use ``b''``? \ No newline at end of file +#. Why do our functional tests use ``b''``? -- cgit v1.2.3 From 34e9381a628d4e5d061d8fe902579a9b9b9cb33c Mon Sep 17 00:00:00 2001 From: David Eisner Date: Mon, 6 Oct 2014 19:27:36 -0400 Subject: Update functional_testing.rst Wrap long line. --- docs/quick_tutorial/functional_testing.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index ddcf6b77d..09b05b0bc 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -43,7 +43,8 @@ Steps .. literalinclude:: functional_testing/tutorial/tests.py :linenos: - Be sure this file is not executable, or ``nosetests`` may not include your tests. + Be sure this file is not executable, or ``nosetests`` may not + include your tests. #. Now run the tests: -- cgit v1.2.3 From bbb8f374eb7a1dcbc92f732cc4ccc0a2c92526d5 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 20 May 2015 23:47:23 -0700 Subject: punctuation fix --- docs/quick_tutorial/functional_testing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index 09b05b0bc..6f1544e79 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -10,7 +10,7 @@ Background ========== Unit tests are a common and popular approach to test-driven development -(TDD.) In web applications, though, the templating and entire apparatus +(TDD). In web applications, though, the templating and entire apparatus of a web site are important parts of the delivered quality. We'd like a way to test these. -- cgit v1.2.3 From 9459d8c11a1bd8d62c84c7ff1f761c6aead61510 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 7 Apr 2016 03:17:03 -0700 Subject: - update functional_testing.rst --- docs/quick_tutorial/functional_testing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index 6f1544e79..b8aa7e87d 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -34,8 +34,8 @@ Steps .. code-block:: bash $ cd ..; cp -r unit_testing functional_testing; cd functional_testing - $ $VENV/bin/python setup.py develop - $ $VENV/bin/easy_install webtest + $ $VENV/bin/pip install -e . + $ $VENV/bin/pip install webtest #. Let's extend ``functional_testing/tutorial/tests.py`` to include a functional test: -- cgit v1.2.3 From ccf3974f81fa0e026fadd42ba5259c838aeab68b Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 16 Apr 2016 04:50:39 -0700 Subject: quick_tutorial cleanup - replace nose with pytest - cleanup functional_testing.rst --- docs/quick_tutorial/functional_testing.rst | 52 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'docs/quick_tutorial/functional_testing.rst') diff --git a/docs/quick_tutorial/functional_testing.rst b/docs/quick_tutorial/functional_testing.rst index b8aa7e87d..33793578a 100644 --- a/docs/quick_tutorial/functional_testing.rst +++ b/docs/quick_tutorial/functional_testing.rst @@ -6,30 +6,33 @@ Write end-to-end full-stack testing using ``webtest``. + Background ========== -Unit tests are a common and popular approach to test-driven development -(TDD). In web applications, though, the templating and entire apparatus -of a web site are important parts of the delivered quality. We'd like a -way to test these. +Unit tests are a common and popular approach to test-driven development (TDD). +In web applications, though, the templating and entire apparatus of a web site +are important parts of the delivered quality. We'd like a way to test these. + +`WebTest `_ is a +Python package that does functional testing. With WebTest you can write tests +which simulate a full HTTP request against a WSGI application, then test the +information in the response. For speed purposes, WebTest skips the +setup/teardown of an actual HTTP server, providing tests that run fast enough +to be part of TDD. -WebTest is a Python package that does functional testing. With WebTest -you can write tests which simulate a full HTTP request against a WSGI -application, then test the information in the response. For speed -purposes, WebTest skips the setup/teardown of an actual HTTP server, -providing tests that run fast enough to be part of TDD. Objectives ========== -- Write a test which checks the contents of the returned HTML +- Write a test which checks the contents of the returned HTML. + Steps ===== -#. First we copy the results of the previous step, as well as install - the ``webtest`` package: +#. First we copy the results of the previous step, as well as install the + ``webtest`` package: .. code-block:: bash @@ -43,31 +46,28 @@ Steps .. literalinclude:: functional_testing/tutorial/tests.py :linenos: - Be sure this file is not executable, or ``nosetests`` may not - include your tests. + Be sure this file is not executable, or ``pytest`` may not include your + tests. #. Now run the tests: .. code-block:: bash + $ $VENV/bin/py.test tutorial/tests.py -q + .. + 2 passed in 0.25 seconds - $ $VENV/bin/nosetests tutorial - . - ---------------------------------------------------------------------- - Ran 2 tests in 0.141s - - OK Analysis ======== -We now have the end-to-end testing we were looking for. WebTest lets us -simply extend our existing ``nose``-based test approach with functional -tests that are reported in the same output. These new tests not only -cover our templating, but they didn't dramatically increase the -execution time of our tests. +We now have the end-to-end testing we were looking for. WebTest lets us simply +extend our existing ``pytest``-based test approach with functional tests that +are reported in the same output. These new tests not only cover our templating, +but they didn't dramatically increase the execution time of our tests. + -Extra Credit +Extra credit ============ #. Why do our functional tests use ``b''``? -- cgit v1.2.3