From c21fec9e1dc814fed122d48d0eefa197025698c0 Mon Sep 17 00:00:00 2001 From: Michael Price Date: Thu, 22 Feb 2018 03:39:58 -0400 Subject: [PATCH] Add draft test writing MERC. Signed-off-by: Michael Price Signed-off-by: Roberto Rosario --- docs/mercs/0001-merc-process.rst | 4 +- docs/mercs/index.rst | 1 + docs/mercs/test-writing.rst | 82 ++++++++++++++++++++++++++++++++ docs/topics/pending_work.rst | 23 ++------- 4 files changed, 89 insertions(+), 21 deletions(-) create mode 100644 docs/mercs/test-writing.rst diff --git a/docs/mercs/0001-merc-process.rst b/docs/mercs/0001-merc-process.rst index c775e8666d..a131fcc709 100644 --- a/docs/mercs/0001-merc-process.rst +++ b/docs/mercs/0001-merc-process.rst @@ -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 `_. diff --git a/docs/mercs/index.rst b/docs/mercs/index.rst index 1d9a696d09..07c60dfc08 100644 --- a/docs/mercs/index.rst +++ b/docs/mercs/index.rst @@ -18,6 +18,7 @@ Draft :maxdepth: 1 0001-merc-process + test-writing Type diff --git a/docs/mercs/test-writing.rst b/docs/mercs/test-writing.rst new file mode 100644 index 0000000000..bfaac78aa1 --- /dev/null +++ b/docs/mercs/test-writing.rst @@ -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) diff --git a/docs/topics/pending_work.rst b/docs/topics/pending_work.rst index 9f69c1e509..3dab8f588b 100644 --- a/docs/topics/pending_work.rst +++ b/docs/topics/pending_work.rst @@ -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.