From 0fb88fb39a3dc39122dc2897abbd2d77ff413823 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sun, 31 Dec 2023 21:10:07 +0530 Subject: [PATCH] feat: test API library against mcaptcha server --- .env_sample | 3 +++ Makefile | 17 +++++++++++++++++ tests/__init__.py | 4 ++++ tests/test_client.py | 17 +++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 .env_sample create mode 100644 Makefile create mode 100644 tests/__init__.py create mode 100644 tests/test_client.py diff --git a/.env_sample b/.env_sample new file mode 100644 index 0000000..62108cb --- /dev/null +++ b/.env_sample @@ -0,0 +1,3 @@ +export USERNAME= +export PASSWORD= +export INSTANCE_URL= diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b86abd8 --- /dev/null +++ b/Makefile @@ -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/ diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..d8b4d92 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: Apache-2.0 +# SPDX-License-Identifier: MIT diff --git a/tests/test_client.py b/tests/test_client.py new file mode 100644 index 0000000..5fd99db --- /dev/null +++ b/tests/test_client.py @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# 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