Skip to content

Commit

Permalink
Update advanced.rst by adding unittest example
Browse files Browse the repository at this point in the history
I tried so hard to find how to use automated test with django-simple-captcha, so I decided to add a code snippet for later people
  • Loading branch information
songsammy authored Dec 19, 2024
1 parent b7abe2e commit 82d798a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ Use this for testing purposes. Warning: do NOT set this to True in production.

Defaults to: False

.. code:: python
from django.test import TestCase, Client
from django.urls import reverse
from captcha.conf import settings as captcha_settings
class ApplicationTestCase(TestCase):
def setUp(self):
self.client = Client()
self.url = reverse('application')
captcha_settings.CAPTCHA_TEST_MODE = True
def test_post_valid_form(self):
data = {
'name': 'Your Name',
"captcha_0": "any-random-string",
"captcha_1": "PASSED",
}
response = self.client.post(self.url, data)
self.assertEqual(response.status_code, 200)
CAPTCHA_GET_FROM_POOL
---------------------
Expand Down

0 comments on commit 82d798a

Please sign in to comment.