Add draft test writing MERC.
Signed-off-by: Michael Price <loneviking72@gmail.com> Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
committed by
Roberto Rosario
parent
6886b22360
commit
c21fec9e1d
@@ -90,7 +90,7 @@ into the main source code repository, the status will be changed to
|
||||
"Final".
|
||||
|
||||
MERC format
|
||||
==========
|
||||
===========
|
||||
|
||||
MERCs need to follow a common format and outline; this section describes
|
||||
that format.
|
||||
@@ -147,7 +147,7 @@ Each MERC should have the following parts:
|
||||
|
||||
|
||||
MERC Metadata
|
||||
------------
|
||||
-------------
|
||||
|
||||
Each MERC must begin with some metadata given as an rST
|
||||
`field list <http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#field-lists>`_.
|
||||
|
||||
@@ -18,6 +18,7 @@ Draft
|
||||
:maxdepth: 1
|
||||
|
||||
0001-merc-process
|
||||
test-writing
|
||||
|
||||
|
||||
Type
|
||||
|
||||
82
docs/mercs/test-writing.rst
Normal file
82
docs/mercs/test-writing.rst
Normal file
@@ -0,0 +1,82 @@
|
||||
=====================
|
||||
MERC XX: Test writing
|
||||
=====================
|
||||
|
||||
:MERC: XX
|
||||
:Author: Michael Price
|
||||
:Status: Draft
|
||||
:Type: Process
|
||||
:Created: 2018-02-22
|
||||
:Last-Modified: 2018-02-22
|
||||
|
||||
.. contents:: Table of Contents
|
||||
:depth: 3
|
||||
:local:
|
||||
|
||||
Abstract
|
||||
========
|
||||
|
||||
This MERC proposes a standard methodology for writing tests for Mayan EDMS.
|
||||
|
||||
Motivation
|
||||
==========
|
||||
|
||||
Having a standard methodology for writing tests has the following advantages:
|
||||
|
||||
1. Scaffolding can be reduced by providing the most frequently used
|
||||
paradigms as methods or helper functions.
|
||||
2. Reduce the probabilities of errors slipping through poorly written tests.
|
||||
|
||||
|
||||
Specification
|
||||
=============
|
||||
|
||||
1. Tests must test each view in at least two ways:
|
||||
|
||||
A. Object creations views must be tested with and without permissions.
|
||||
B. Object detail, list and delete views must be tested with and without
|
||||
object access.
|
||||
|
||||
2. Tests must assert the status code of the response even
|
||||
when the expected status is HTTP 200.
|
||||
3. The actual request performed must be enclosed in a private methods
|
||||
so that the fail and pass tests use the same HTTP request.
|
||||
4. Test must verify that changes happened and didn't happened in the
|
||||
database regardless of the return code. Even is an edit view returns
|
||||
and error 4XX (404-Not found, 403-Forbidden, etc), the test must
|
||||
ensure that the data was not indeed modified.
|
||||
5. All tests must use the test user created by the BaseAPITestCase and not
|
||||
an super user unless absolutely required by the test.
|
||||
6. Each test must test just one thing.
|
||||
7. If a test object needs to be created before the execution of a request
|
||||
this object must be created by a private method.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def _request_tag_create(self):
|
||||
return self.post(
|
||||
viewname='rest_api:tag-list', data={
|
||||
'label': TEST_TAG_LABEL, 'color': TEST_TAG_COLOR
|
||||
}
|
||||
)
|
||||
|
||||
def test_tag_create_view_no_permission(self):
|
||||
response = self._request_tag_create()
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
self.assertEqual(Tag.objects.count(), 0)
|
||||
|
||||
def test_tag_create_view_with_permission(self):
|
||||
self.grant_permission(permission=permission_tag_create)
|
||||
response = self._request_tag_create()
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
tag = Tag.objects.first()
|
||||
self.assertEqual(response.data['id'], tag.pk)
|
||||
self.assertEqual(response.data['label'], TEST_TAG_LABEL)
|
||||
self.assertEqual(response.data['color'], TEST_TAG_COLOR)
|
||||
|
||||
self.assertEqual(Tag.objects.count(), 1)
|
||||
self.assertEqual(tag.label, TEST_TAG_LABEL)
|
||||
self.assertEqual(tag.color, TEST_TAG_COLOR)
|
||||
@@ -1,24 +1,9 @@
|
||||
===========
|
||||
OCR backend
|
||||
===========
|
||||
|
||||
Test writing
|
||||
~~~~~~~~~~~~
|
||||
|
||||
All view and API tests must test each view in at least two ways:
|
||||
|
||||
- Object creations views must be tested with and without permissions.
|
||||
- Object detail, list and delete views must be tested with and without
|
||||
object access.
|
||||
|
||||
All view and API tests must assert the status code of the response even
|
||||
when the expected status if HTTP 200.
|
||||
============
|
||||
Pending work
|
||||
============
|
||||
|
||||
|
||||
Pending tasks
|
||||
-------------
|
||||
|
||||
These are task that need to be completed but are missing a dependency or
|
||||
These are tasks that need to be completed but are missing a dependency or
|
||||
a design decision. As more information is added to each, they should be
|
||||
converted into a MERC.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user