forked from mardix/flask-recaptcha
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_flask_hcaptcha.py
40 lines (34 loc) · 1.32 KB
/
test_flask_hcaptcha.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask
from flask_hcaptcha import hCaptcha
app = Flask(__name__)
app.config.update({
"debug": True,
"HCAPTCHA_SITE_KEY": "SITE_KEY",
"HCAPTCHA_SITE_SECRET": "SECRET",
"HCAPTCHA_ENABLED": True
})
def test_hcaptcha_enabled():
hcaptcha = hCaptcha(site_key="SITE_KEY", secret_key="SECRET_KEY")
assert isinstance(hcaptcha, hCaptcha)
assert hcaptcha.is_enabled == True
assert "script" in hcaptcha.get_code()
assert hcaptcha.verify(response="None", remote_ip="0.0.0.0") == False
def test_hcaptcha_enabled_flask():
hcaptcha = hCaptcha(app=app)
assert isinstance(hcaptcha, hCaptcha)
assert hcaptcha.is_enabled == True
assert "script" in hcaptcha.get_code()
assert hcaptcha.verify(response="None", remote_ip="0.0.0.0") == False
def test_hcaptcha_disabled():
hcaptcha = hCaptcha(site_key="SITE_KEY", secret_key="SECRET_KEY", is_enabled=False)
assert hcaptcha.is_enabled == False
assert hcaptcha.get_code() == ""
assert hcaptcha.verify(response="None", remote_ip="0.0.0.0") == True
def test_hcaptcha_disabled_flask():
app.config.update({
"HCAPTCHA_ENABLED": False
})
hcaptcha = hCaptcha(app=app)
assert hcaptcha.is_enabled == False
assert hcaptcha.get_code() == ""
assert hcaptcha.verify(response="None", remote_ip="0.0.0.0") == True