Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1117] Lots of work on the testing coding standards
- Loading branch information
Sean Hammond
committed
Aug 2, 2013
1 parent
17626e4
commit 8feecf5
Showing
16 changed files
with
581 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
''' | ||
.. todo:: | ||
Write the tests for one controller, figuring out the best way to write | ||
controller tests. Then fill in this guidelines section, using the first set | ||
of controller tests as an example. | ||
Some things have been decided already: | ||
* All controller methods should have tests | ||
* Controller tests should be high-level tests that work by posting simulated | ||
HTTP requests to CKAN URLs and testing the response. So the controller | ||
tests are also testing CKAN's templates and rendering - these are CKAN's | ||
front-end tests. | ||
For example, maybe we use a webtests testapp and then use beautiful soup | ||
to parse the HTML? | ||
* In general the tests for a controller shouldn't need to be too detailed, | ||
because there shouldn't be a lot of complicated logic and code in | ||
controller classes. The logic should be handled in other places such as | ||
:mod:`ckan.logic` and :mod:`ckan.lib`, where it can be tested easily and | ||
also shared with other code. | ||
* The tests for a controller should: | ||
* Make sure that the template renders without crashing. | ||
* Test that the page contents seem basically correct, or test certain | ||
important elements in the page contents (but don't do too much HTML | ||
parsing). | ||
* Test that submitting any forms on the page works without crashing and | ||
has the expected side-effects. | ||
* When asserting side-effects after submitting a form, controller tests | ||
should user the :func:`ckan.new_tests.helpers.call_action` function. For | ||
example after creating a new user by submitting the new user form, a | ||
test could call the :func:`~ckan.logic.action.get.user_show` action | ||
function to verify that the user was created with the correct values. | ||
.. warning:: | ||
Some CKAN controllers *do* contain a lot of complicated logic code. These | ||
controllers should be refactored to move the logic into :mod:`ckan.logic` or | ||
:mod:`ckan.lib` where it can be tested easily. Unfortunately in cases like | ||
this it may be necessary to write a lot of controller tests to get this | ||
code's behavior into a test harness before it can be safely refactored. | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'''**All lib functions should have tests**. | ||
.. todo:: | ||
Write the tests for one ``ckan.lib`` module, figuring out the best way | ||
to write lib tests. Then fill in this guidelines section, using the first | ||
We probably want to make these unit tests rather than high-level tests and | ||
mock out ``ckan.model``, so the tests are really fast and simple. | ||
Note that some things in lib are particularly important, e.g. the functions | ||
in :py:mod:`ckan.lib.helpers` are exported for templates (including | ||
extensions) to use, so all of these functions should really have tests and | ||
docstrings. It's probably worth focusing on these modules first. | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'''**All action functions should have tests.** | ||
Most action function tests will be high-level tests that both test the code in | ||
the action function itself, and also indirectly test the code in | ||
:mod:`ckan.lib`, :mod:`ckan.model`, :mod:`ckan.logic.schema` etc. that the | ||
action function calls. | ||
Tests for action functions should use the | ||
:func:`ckan.new_tests.helpers.call_action` function to call the action | ||
functions. | ||
One thing :func:`~ckan.new_tests.helpers.call_action` does is to add | ||
``ignore_auth: True`` into the ``context`` dict that's passed to the action | ||
function, so that CKAN will not call the action function's authorization | ||
function. The tests for an action function *don't* need to cover | ||
authorization, because the authorization functions have their own tests in | ||
:mod:`ckan.new_tests.logic.auth`. But action function tests *do* need to cover | ||
validation, more on that later. | ||
Action function tests *should* test the logic of the actions themselves, and | ||
*should* test validation (e.g. that various kinds of valid input work as | ||
expected, and invalid inputs raise the expected exceptions). | ||
Here's an example of a simple :mod:`ckan.logic.action` test: | ||
.. literalinclude:: ../ckan/new_tests/logic/action/test_update.py | ||
:start-after: ## START-AFTER | ||
:end-before: ## END-BEFORE | ||
.. todo:: | ||
Insert the names of all tests for ``ckan.logic.action.update.user_update``, | ||
for example, to show what level of detail things should be tested in. | ||
''' |
Oops, something went wrong.