feat: test API library against mcaptcha server

This commit is contained in:
Aravinth Manivannan 2023-12-31 21:10:07 +05:30
parent b6732958c9
commit 0fb88fb39a
Signed by: realaravinth
GPG key ID: F8F50389936984FF
4 changed files with 41 additions and 0 deletions

3
.env_sample Normal file
View file

@ -0,0 +1,3 @@
export USERNAME=
export PASSWORD=
export INSTANCE_URL=

17
Makefile Normal file
View file

@ -0,0 +1,17 @@
env:
./scripts/download-cli.sh download
. venv/bin/activate && pip install -r requirements.txt
. venv/bin/activate && pip install -e .
test:
$(eval SECRET = $(shell . ./venv/bin/activate && python ./scripts/create_captcha.py get_secret $(INSTANCE_URL) $(USERNAME) $(PASSWORD)))
$(eval SITEKEY = $(shell . ./venv/bin/activate && python ./scripts/create_captcha.py create_captcha $(INSTANCE_URL) $(USERNAME) $(PASSWORD)))
$(eval WIDGET_URL = $(shell . ./venv/bin/activate && python ./scripts/create_captcha.py widget_url $(INSTANCE_URL) $(SITEKEY)))
$(eval TOKEN = $(shell ./scripts/download-cli.sh gen_pow $(WIDGET_URL)))
. venv/bin/activate && \
SITEKEY=$(SITEKEY) SECRET=$(SECRET) \
INSTANCE_URL=$(INSTANCE_URL) \
TOKEN=$(TOKEN) pytest -rP
lint:
black src/ scripts/

4
tests/__init__.py Normal file
View file

@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

17
tests/test_client.py Normal file
View file

@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT
import os
from mcaptcha_api import MCaptcha
INSTANCE_URL = os.environ["INSTANCE_URL"]
SITEKEY = os.environ["SITEKEY"]
SECRET = os.environ["SECRET"]
TOKEN = os.environ["TOKEN"]
def test_client():
mcaptcha = MCaptcha(instance_url=INSTANCE_URL, sitekey=SITEKEY, secret=SECRET)
assert mcaptcha.verify(token=TOKEN) is True
assert mcaptcha.verify(token="foo") is False