Skip to content

Commit

Permalink
Mock validation during tests (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
christianwgd committed Apr 12, 2024
1 parent f0cab68 commit 1af9c30
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 0.1.11 (2024-04-12)
--------------------------

* New: Add a new settings option FRC_CAPTCHA_MOCKED_VALUE for
testing purposes.


Version 0.1.10 (2024-03-29)
--------------------------

Expand Down
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ When setting FAIL_SILENT to True it's up to you to handle captcha verification:
else:
# captcha verification failed, do nothing ...
As of version 0.1.11 there's a new settings option to get a mocked
value from the captcha verification. You can set FRC_CAPTCHA_MOCKED_VALUE
to True or False, depending on the vaule you need for testing.
The default value is unset which equals to None.

.. code-block::
FRC_CAPTCHA_MOCKED_VALUE = None|False|True
Custom widget attributes
########################

Expand Down
7 changes: 7 additions & 0 deletions friendly_captcha/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def __init__(self, *args, **kwargs):
super(FrcCaptchaField, self).__init__(*args, **kwargs)

def clean(self, value):
# Mock the response of verification for testing purposes
mocked_value = getattr(settings, 'FRC_CAPTCHA_MOCKED_VALUE', None)
print('mocked value', mocked_value)
if mocked_value is not None:
logger.info('Captcha mocked value set to %s', mocked_value)
return mocked_value

clean_value = False
# handle captcha field
captcha_secret = getattr(settings, 'FRC_CAPTCHA_SECRET', None)
Expand Down
2 changes: 1 addition & 1 deletion friendly_captcha/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
# from django.test import TestCase

# Create your tests here.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def read(fname):

setup(
name='django-friendly-captcha',
version='0.1.10',
version='0.1.11',
description='Django library for friendly captcha',
long_description=read('README.rst'),
long_description_content_type='text/x-rst',
Expand Down Expand Up @@ -37,6 +37,8 @@ def read(fname):
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
zip_safe=False,
)

0 comments on commit 1af9c30

Please sign in to comment.