forked from mardix/flask-recaptcha
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_flask_turnstile.py
39 lines (34 loc) · 1.35 KB
/
test_flask_turnstile.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
from flask import Flask
from flask_turnstile import Turnstile
app = Flask(__name__)
app.config.update({
"debug": True,
"TURNSTILE_SITE_KEY": "SITE_KEY",
"TURNSTILE_SITE_SECRET": "SECRET",
"TURNSTILE_ENABLED": True
})
def test_turnstile_enabled():
turnstile = Turnstile(site_key="SITE_KEY", secret_key="SECRET_KEY")
assert isinstance(turnstile, Turnstile)
assert turnstile.is_enabled == True
assert "script" in turnstile.get_code()
assert turnstile.verify(response="None", remote_ip="0.0.0.0") == False
def test_turnstile_enabled_flask():
turnstile = Turnstile(app=app)
assert isinstance(turnstile, Turnstile)
assert turnstile.is_enabled == True
assert "script" in turnstile.get_code()
assert turnstile.verify(response="None", remote_ip="0.0.0.0") == False
def test_turnstile_disabled():
turnstile = Turnstile(site_key="SITE_KEY", secret_key="SECRET_KEY", is_enabled=False)
assert turnstile.is_enabled == False
assert turnstile.get_code() == ""
assert turnstile.verify(response="None", remote_ip="0.0.0.0") == True
def test_turnstile_disabled_flask():
app.config.update({
"TURNSTILE_ENABLED": False
})
turnstile = Turnstile(app=app)
assert turnstile.is_enabled == False
assert turnstile.get_code() == ""
assert turnstile.verify(response="None", remote_ip="0.0.0.0") == True