From c1c4c88a4b7c976062f892caea70fcd40974fd11 Mon Sep 17 00:00:00 2001 From: Noah Haf <61884850+Noah-Haf@users.noreply.github.com> Date: Sat, 3 May 2025 16:21:08 +0100 Subject: [PATCH] Create tests --- .example.env | 3 +++ .github/workflows/main.yml | 4 ++++ CONTRIBUTING.md | 2 ++ pyproject.toml | 1 + tests/test_example.py | 11 ----------- tests/test_ranks.py | 36 ++++++++++++++++++++++++++++++++++++ uv.lock | 11 +++++++++++ 7 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 .example.env delete mode 100644 tests/test_example.py create mode 100644 tests/test_ranks.py diff --git a/.example.env b/.example.env new file mode 100644 index 0000000..e2c2acd --- /dev/null +++ b/.example.env @@ -0,0 +1,3 @@ +RANKGUN_TOKEN="*****" +WORKSPACE_ID="***" +TESTING_USER_ID="***" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3e5e63..fee106a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,6 +44,10 @@ jobs: python-version: ${{ matrix.python-version }} - name: Run tests + env: + RANKGUN_TOKEN: ${{ secrets.RANKGUN_TOKEN }} + WORKSPACE_ID: ${{ secrets.WORKSPACE_ID }} + TESTING_USER_ID: ${{ secrets.TESTING_USER_ID }} run: uv run python -m pytest tests - name: Check typing diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 81ba778..90fc87c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,6 +62,8 @@ git clone git@github.com:YOUR_NAME/rankgun.git cd rankgun ``` +Copy ``.example.env`` to ``.env`` and set your variables as necessary. + Then, install and activate the environment with: ```bash diff --git a/pyproject.toml b/pyproject.toml index d42c097..b0fc80a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dev = [ "deptry>=0.23.0", "mypy>=0.991", "ruff>=0.11.5", + "python-dotenv>=1.1.0", ] [build-system] diff --git a/tests/test_example.py b/tests/test_example.py deleted file mode 100644 index 870d7ef..0000000 --- a/tests/test_example.py +++ /dev/null @@ -1,11 +0,0 @@ -"""A test example.""" - - -def inc(x): - """Increment a number.""" - return x + 1 - - -def test_answer(): - """Example test.""" - assert inc(3) == 4 diff --git a/tests/test_ranks.py b/tests/test_ranks.py new file mode 100644 index 0000000..ed6a38c --- /dev/null +++ b/tests/test_ranks.py @@ -0,0 +1,36 @@ +"""Tests for ranking logic.""" + +import os + +from dotenv import load_dotenv + +from src.rankgun.main import Client + +load_dotenv() + + +TOKEN = os.environ["RANKGUN_TOKEN"] +WID = os.environ["WORKSPACE_ID"] +TESTINGUSERID = os.environ["TESTING_USER_ID"] + +client = Client(wid=WID, token=TOKEN) + + +def test_set_rank_one(): + """Sets the rank of a test user.""" + assert client.setRank(TESTINGUSERID, 3).user == f"users/{TESTINGUSERID}" + + +def test_promotion(): + """Promote a test user.""" + assert client.promote(TESTINGUSERID).user == f"users/{TESTINGUSERID}" + + +def test_demotion(): + """Demote a test user.""" + assert client.demote(TESTINGUSERID).user == f"users/{TESTINGUSERID}" + + +def test_set_rank_two(): + """Sets the rank of a test user.""" + assert client.setRank(TESTINGUSERID, 2).user == f"users/{TESTINGUSERID}" diff --git a/uv.lock b/uv.lock index e0a1000..869c124 100644 --- a/uv.lock +++ b/uv.lock @@ -463,6 +463,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/30/3d/64ad57c803f1fa1e963a7946b6e0fea4a70df53c1a7fed304586539c2bac/pytest-8.3.5-py3-none-any.whl", hash = "sha256:c69214aa47deac29fad6c2a4f590b9c4a9fdb16a403176fe154b79c0b4d4d820", size = 343634, upload-time = "2025-03-02T12:54:52.069Z" }, ] +[[package]] +name = "python-dotenv" +version = "1.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/88/2c/7bb1416c5620485aa793f2de31d3df393d3686aa8a8506d11e10e13c5baf/python_dotenv-1.1.0.tar.gz", hash = "sha256:41f90bc6f5f177fb41f53e87666db362025010eb28f60a01c9143bfa33a2b2d5", size = 39920, upload-time = "2025-03-25T10:14:56.835Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1e/18/98a99ad95133c6a6e2005fe89faedf294a748bd5dc803008059409ac9b1e/python_dotenv-1.1.0-py3-none-any.whl", hash = "sha256:d7c01d9e2293916c18baf562d95698754b0dbbb5e74d457c45d4f6561fb9d55d", size = 20256, upload-time = "2025-03-25T10:14:55.034Z" }, +] + [[package]] name = "pyyaml" version = "6.0.2" @@ -531,6 +540,7 @@ dev = [ { name = "mypy" }, { name = "pre-commit" }, { name = "pytest" }, + { name = "python-dotenv" }, { name = "ruff" }, { name = "tox-uv" }, ] @@ -547,6 +557,7 @@ dev = [ { name = "mypy", specifier = ">=0.991" }, { name = "pre-commit", specifier = ">=2.20.0" }, { name = "pytest", specifier = ">=7.2.0" }, + { name = "python-dotenv", specifier = ">=1.1.0" }, { name = "ruff", specifier = ">=0.11.5" }, { name = "tox-uv", specifier = ">=1.11.3" }, ]