Skip to content

Commit 6513797

Browse files
Further update missing documentation
1 parent 76f6c9e commit 6513797

File tree

4 files changed

+252
-66
lines changed

4 files changed

+252
-66
lines changed

django_expanded_test_cases/mixins/core_mixin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ def get_user(self, user, password=ETC_DEFAULT_USER_PASSWORD, extra_usergen_kwarg
600600
601601
:param user: User model, or corresponding user identifier, to use.
602602
:param password: Password str to assign to user.
603-
:param extra_usergen_kwargs: Optional extra kwargs to pass into the get_user_model().objects.create_user()
603+
:param extra_usergen_kwargs: Optional extra kwargs to pass into the
604+
get_user_model().objects.create_user()
604605
function.
605606
:return: User object
606607
"""

docs/source/test_cases/base_test_case.rst

Lines changed: 187 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,83 @@ Custom Assertions
1515
=================
1616

1717

18-
assertText
19-
----------
18+
assertText()
19+
------------
2020

2121
.. code::
2222
23-
assertText(actual_text, expected_text, strip=True)
23+
self.assertText(expected_text, actual_text, strip=True)
2424
2525
26-
Currently, this is mostly a wrapper for assertEqual(), which prints full
27-
values to console on mismatch.
26+
This is effectively a wrapper for assertEqual(), which is meant specifically
27+
for comparing two bits of text.
28+
The difference is that on failure, this attempts to print full values to
29+
console on mismatch (``assertEqual()`` will truncate if values are too long).
2830

29-
In the future, this may be updated to have more useful AssertionFailure
30-
output, particularly for long values.
31+
Furthermore if `Colorama <https://pypi.org/project/colorama/>`_ is installed,
32+
then text will be colored according to what characters did and did not match.
3133

32-
:param actual_text: The value you wish to verify.
33-
:param expected_text: The value to compare against. These should match.
34+
35+
:param expected_text: The value you expect to find.
36+
:param actual_text: The variable value you're testing against, to match against
37+
``expected_text``.
38+
:param strip: A boolean indicating if white space characters should be stripped
39+
from both comparison values, prior to comparing.
40+
Set False to skip stripping.
41+
42+
43+
assertTextStartsWith()
44+
----------------------
45+
46+
.. code::
47+
48+
self.assertTextStartsWith(expected_text, actual_text, strip=True)
49+
50+
Similar to above
51+
:ref:`test_cases/base_test_case:assertText()`, except it only cares about
52+
matching from the start of the comparison strings.
53+
54+
If ``expected_text`` is shorter than ``actual_text``, then this assertion
55+
only matches equal to the total characters found in ``expected_text``.
56+
57+
If ``expected_text`` is longer than ``actual_text``, then raise an error
58+
for the missing characters, but still attempt to compare full strings to
59+
indicate if all other values match or not.
60+
61+
62+
:param expected_text: The value you expect to find.
63+
:param actual_text: The variable value you're testing against, to match against
64+
``expected_text``.
65+
:param strip: A boolean indicating if white space characters should be stripped
66+
from both comparison values, prior to comparing.
67+
Set False to skip stripping.
68+
69+
70+
assertTextEndsWith()
71+
----------------------
72+
73+
.. code::
74+
75+
self.assertTextEndsWith(expected_text, actual_text, strip=True)
76+
77+
Similar to above
78+
:ref:`test_cases/base_test_case:assertText()`, except it only cares about
79+
matching from the end of the comparison strings.
80+
81+
If ``expected_text`` is shorter than ``actual_text``, then this assertion
82+
only matches equal to the total characters found in ``expected_text``.
83+
84+
If ``expected_text`` is longer than ``actual_text``, then raise an error
85+
for the missing characters, but still attempt to compare full strings to
86+
indicate if all other values match or not.
87+
88+
89+
:param expected_text: The value you expect to find.
90+
:param actual_text: The variable value you're testing against, to match against
91+
``expected_text``.
92+
:param strip: A boolean indicating if white space characters should be stripped
93+
from both comparison values, prior to comparing.
94+
Set False to skip stripping.
3495

3596

3697
Helper Functions
@@ -41,81 +102,177 @@ Reminder that the ``BaseTestCase`` class is meant to be minimalistic. So most
41102
types of input, and then return the expected value.
42103

43104

44-
get_user
45-
--------
105+
User Helper Functions
106+
---------------------
107+
108+
get_user()
109+
^^^^^^^^^^
46110

47111
.. code::
48112
49-
get_user(user, password='password')
113+
self.get_user(user, password='password', extra_usergen_kwargs=**kwargs)
50114
51115
Helper function to obtain a given User object.
52116

53-
Treats the provided value as the `username` field. Returns the User object that
54-
matches. If no such User exists in the database yet, then a new one is first
55-
created.
117+
Treats the provided value as the field defined in settings as the
118+
:ref:`user model identifier <configuration/auth:USER_MODEL_IDENTIFIER>`.
119+
120+
Returns the User object that matches.
121+
If no such User exists in the database yet, then a new one is first created.
56122

57123
For testing purposes, also makes sure the provided password is assigned to the
58-
user, and then includes this raw value as an attribute on the returned object.
124+
test user object, and then includes this raw value as an attribute on the
125+
returned object, found as ``user_object.password``.
126+
59127

128+
:param user: Identifier to use to attempt to get user with.
60129
:param password: The password to assign this user. On the returned User
61130
object, the raw password value can be accessed via a
62131
provided ``unhashed_password`` field.
132+
:param extra_usergen_kwargs: Optional extra kwargs to pass into the
133+
``get_user_model().objects.create_user()`` function.
134+
If your project has custom logic for the
135+
``create_user()`` function, then you can use this to
136+
pass additional values in.
63137

64138
:return: Found User object.
65139

66140

67-
add_user_permission
68-
-------------------
141+
add_user_permission()
142+
^^^^^^^^^^^^^^^^^^^^^
69143

70144
.. code::
71145
72-
add_user_permission(user_permission, user='test_user')
146+
self.add_user_permission(user_permission, user='test_user')
73147
74148
Helper function to add
75149
`permissions <https://docs.djangoproject.com/en/dev/topics/auth/default/#permissions-and-authorization>`_
76150
to a given User.
77151

152+
78153
:param user_permission: Permission object, or name of permission object, to
79154
add to User.
80-
:parm user: User to add permission to. Defaults to ``test_user``.
155+
:parm user: User to add permission to.
156+
Can take in either a literal user object, or the identifier of a
157+
user.
158+
Defaults to ``test_user``.
81159

82160
:return: Updated User object.
83161

84162

85-
add_user_group
86-
--------------
163+
add_user_group()
164+
^^^^^^^^^^^^^^^^
87165

88166
.. code::
89167
90-
add_user_group(user_group, user='test_user')
168+
self.add_user_group(user_group, user='test_user')
91169
92170
Helper function to add
93171
`groups <https://docs.djangoproject.com/en/dev/topics/auth/default/#groups>`_
94172
to a given User.
95173

174+
96175
:param user_group: Group object, or name of group object, to add to User.
97-
:param user: User to add group to. Defaults to ``test_user``.
176+
:param user: User to add group to.
177+
Can take in either a literal user object, or the identifier of a
178+
user.
179+
Defaults to ``test_user``.
98180

99181
:return: Updated User object.
100182

101183

102-
generate_get_url
103-
----------------
184+
Other Helper Functions
185+
----------------------
186+
187+
generate_get_url()
188+
^^^^^^^^^^^^^^^^^^
104189

105190
.. code::
106191
107-
generate_get_url(url=None, **kwargs)
192+
self.generate_get_url(url=None, **kwargs)
108193
109194
Helper function to generate a full GET request URL.
110195

111-
Note: If you're repeatedly accessing the same URL, you can define the value
112-
```self.url``` in the **BaseTestCase** class.
113-
114196
Any provided kwargs are assumed to be
115197
`URL Parameters <https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL#parameters>`_,
116198
and are appended to the end of the URL accordingly.
117199

200+
.. note::
201+
202+
If you're repeatedly accessing the same URL, you can define the value
203+
``self.url`` class variable.
204+
205+
118206
:param url: The desired url string value to use as the
119207
`URL path <https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL#path_to_resource>`_.
208+
:param kwargs: A dictionary of key-value pairs, to be converted to Url
209+
Parameters in the final url.
120210

121211
:return: The generated url string.
212+
213+
214+
standardize_characters()
215+
^^^^^^^^^^^^^^^^^^^^^^^^
216+
217+
.. code::
218+
219+
self.standardize_characters(value)
220+
221+
Standardizes characters in provided string.
222+
223+
For example, in HTML, the "greater than" symbol can be denoted in multiple
224+
ways, such as ``>``, ``&gt;``, ``&#62;``, or ``&#x3E``.
225+
226+
This function takes all such known "equivalent" representations of various
227+
characters, and reformats them to a single type for consistency.
228+
229+
Many of the assertions in this package use this function, in order to make
230+
testing easier and more consistent. (In our above example, the programmer
231+
probably doesn't care WHICH version of the "greater than" symbol is present.
232+
They most likely would only care that one of the several representations is
233+
present.)
234+
235+
236+
:param value: A string value to convert to standardized characters.
237+
238+
:return: A string of more standardized characters.
239+
240+
241+
standardize_whitespace()
242+
^^^^^^^^^^^^^^^^^^^^^^^^
243+
244+
.. code::
245+
246+
self.standardize_whitespace(value)
247+
248+
Standardizes whitespace characters in provided string.
249+
250+
When possible, all repeating whitespace and whitespace-esque characters
251+
(including newlines) are reduced down to a single space.
252+
253+
254+
:param value: A string value to convert to standardized characters.
255+
256+
:return: A string of more standardized characters.
257+
258+
259+
standardize_newlines()
260+
^^^^^^^^^^^^^^^^^^^^^^
261+
262+
.. code::
263+
264+
self.standardize_newlines(value)
265+
266+
Standardizes newline/whitespace characters in provided string.
267+
268+
When possible, all repeating newlines are converted down to a single ``\n``
269+
character, and whitespace and whitespace-esque characters
270+
(excluding newlines) are reduced down to a single space.
271+
272+
If multiple newline characters and space characters repeat in a row, then
273+
that's reduced down to a single newline with up to one space on either side.
274+
275+
276+
:param value: A string value to convert to standardized characters.
277+
278+
:return: A string of more standardized characters.

docs/source/test_cases/integration_test_case/other_functionality.rst

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -322,38 +322,61 @@ inject.
322322
By default, these functions do nothing on their own and are fully safe to
323323
override.
324324

325-
* ``self._get_login_user__extra_user_auth_setup()``
326-
- This function is called after getting the corresponding
327-
:doc:`User object for authentication<../../managing_test_users>`, but prior
328-
to attempting to process the request-response cycle.
325+
_get_login_user__extra_user_auth_setup()
326+
----------------------------------------
329327

330-
This is critical for projects with additional authentication logic.
331-
If a project has additional authentication logic to process (such as
332-
authentication keys or custom Auth backend logic), then it should be done
333-
here.
328+
.. code::
329+
330+
self._get_login_user__extra_user_auth_setup(*args, **kwargs)
331+
332+
This function is called after getting the corresponding
333+
:doc:`User object for authentication<../../managing_test_users>`, but prior
334+
to attempting to process the
335+
`request-response <https://docs.djangoproject.com/en/dev/ref/request-response/>`_
336+
cycle.
337+
338+
This is critical for projects with additional authentication logic.
339+
If a project has additional authentication logic to process (such as
340+
authentication keys or custom Auth backend logic), then it should be done
341+
here to ensure test users can authenticate.
334342

335-
This hook receives only known args/kwargs that are related to user
336-
authentication and request processing.
343+
This hook receives only known args/kwargs that are related to user
344+
authentication and request processing.
345+
346+
347+
_assertResponse__pre_builtin_tests()
348+
------------------------------------
349+
350+
.. code::
337351
338-
* ``self._assertResponse__pre_builtin_tests()``
339-
- This function is called after getting the page response, but prior to
340-
calling any assertion checks on it.
352+
self._assertResponse__pre_builtin_tests(*args, **kwargs)
353+
354+
This function is called after getting the
355+
`page response <https://docs.djangoproject.com/en/dev/ref/request-response/#httpresponse-objects>`_,
356+
but prior to calling any assertion checks on it.
357+
358+
If a project requires any additional pre-check setup, or should have any
359+
custom checks to run prior to those built into ETC, then it should be done here.
360+
361+
This hook receives all known args/kwargs that the response assertion receives.
362+
363+
364+
_assertResponse__post_builtin_tests()
365+
-------------------------------------
366+
367+
.. code::
341368
342-
If a project requires any additional pre-check setup, or should have any
343-
custom checks to run prior to those built into ETC, then it should be done
344-
here.
369+
self._assertResponse__post_builtin_tests()
345370
346-
This hook receives all known args/kwargs that the response assertion receives.
347371
348-
* ``self._assertResponse__post_builtin_tests()``
349-
- This function is called after
350-
getting the page response, and after calling all provided assertion checks
351-
on it.
372+
This function is called after getting the
373+
`page response <https://docs.djangoproject.com/en/dev/ref/request-response/#httpresponse-objects>`_,
374+
and after calling all provided assertion checks on it.
352375

353-
If a project requires any additional clean-up processing, or should have any
354-
custom checks to run after those built into ETC, then it should be done here.
376+
If a project requires any additional clean-up processing, or should have any
377+
custom checks to run after those built into ETC, then it should be done here.
355378

356-
This hook receives all known args/kwargs that the response assertion receives.
379+
This hook receives all known args/kwargs that the response assertion receives.
357380

358381

359382
Implementing Hooks

0 commit comments

Comments
 (0)