dcache/tests/mcaptcha.py

92 lines
2.3 KiB
Python
Raw Normal View History

2023-12-31 01:19:53 +05:30
#!/bin/env /usr/bin/python3
#
# Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
2023-12-31 01:28:59 +05:30
#
2023-12-31 01:19:53 +05:30
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2023-12-31 01:28:59 +05:30
#
2023-12-31 01:19:53 +05:30
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
2023-12-31 01:28:59 +05:30
#
2023-12-31 01:19:53 +05:30
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
import utils
2023-12-31 01:28:59 +05:30
from dcache import (
grpc_add_captcha,
grpc_add_vote,
grpc_captcha_exists,
grpc_rename_captcha,
)
2023-12-31 01:19:53 +05:30
from dcache import grpc_delete_captcha
from stub import get_stub
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
def delete_captcha(key):
grpc_delete_captcha(key)
def add_captcha(key):
grpc_add_captcha(key)
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
def rename_captcha(key, new_key):
grpc_rename_captcha(key, new_key)
def captcha_exists(key):
return grpc_captcha_exists(captcha_id=key)
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
def register(key):
if captcha_exists(key):
delete_captcha(key)
add_captcha(key)
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
async def captcha_exists_works():
key = "captcha_delete_works"
if captcha_exists(key):
delete_captcha(key)
assert captcha_exists(key) is False
register(key)
assert captcha_exists(key) is True
print("[*] Captcha delete works")
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
async def register_captcha_works():
key = "register_captcha_works"
register(key)
assert captcha_exists(key) is True
print("[*] Add captcha works")
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
async def delete_captcha_works():
key = "delete_captcha_works"
register(key)
exists = captcha_exists(key)
assert exists is True
delete_captcha(key)
assert captcha_exists(key) is False
print("[*] Delete captcha works")
async def rename_captcha_works():
key = "rename_captcha_works"
new_key = "new_key_rename_captcha_works"
register(key)
exists = captcha_exists(key)
assert exists is True
rename_captcha(key, new_key)
print(captcha_exists(key))
assert captcha_exists(key) is False
assert captcha_exists(new_key) is True
print("[*] Rename captcha works")