diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 783e9da..41b2cd2 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -24,12 +24,27 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} + - name: Set environment variables + env: + DEMO_API_TOKEN: ${{ secrets.DEMO_API_TOKEN }} + DEMO_APIACCOUNT: ${{ vars.DEMO_APIACCOUNT }} + DEMO_APIURL: ${{ vars.DEMO_APIURL }} + run: | + echo "Environment variables set:" + echo "DEMO_API_TOKEN=${{ secrets.DEMO_API_TOKEN }}" # Avoid printing sensitive secrets in real workflows + echo "DEMO_APIACCOUNT=${{ vars.DEMO_APIACCOUNT }}" + echo "DEMO_APIURL=${{ vars.DEMO_APIURL }}" - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install flake8 pytest + python -m pip install flake8 pytest python-dotenv if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Test with pytest + env: + APITOKEN: ${{ secrets.DEMO_API_TOKEN }} + APIACCOUNT: ${{ vars.DEMO_APIACCOUNT }} + APIURL: ${{ vars.DEMO_APIURL }} run: | - #pytest ./tests - pytest ./src/ --doctest-modules -v + pytest ./tests/ + pytest ./src/ --doctest-modules -v + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ad7af29 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md index 3f69802..d168c39 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,15 @@ # Change Log +## v0.0.2.8 + +### Bug Fixes + +- Core: __append_per_page: exclude auto append for /me + +### Breaking Changes + +- Request: request.workflow is now a Workflow object instead of a dict --> request.workflow.id instead of request.workflow['id'] + ## v0.0.2.7 ### Bug Fixes diff --git a/pyproject.toml b/pyproject.toml index 825d698..c7e5e4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "xurrent" -version = "0.0.2.7" +version = "0.0.2.8" authors = [ { name="Fabian Steiner", email="fabian@stei-ner.net" }, ] diff --git a/requirements.txt b/requirements.txt index 5e40a10..663bd1f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -pytest requests \ No newline at end of file diff --git a/src/xurrent/core.py b/src/xurrent/core.py index 20dcc12..987835a 100644 --- a/src/xurrent/core.py +++ b/src/xurrent/core.py @@ -1,6 +1,6 @@ from __future__ import annotations # Needed for forward references -import logging import requests +import logging import json import re @@ -56,11 +56,13 @@ def __append_per_page(self, uri, per_page=100): 'https://api.example.com/tasks?per_page=100' >>> helper._XurrentApiHelper__append_per_page('https://api.example.com/tasks?per_page=50', 100) 'https://api.example.com/tasks?per_page=50' + >>> helper._XurrentApiHelper__append_per_page('https://api.example.com/people/me', 100) + 'https://api.example.com/people/me' """ if '?' in uri and not 'per_page=' in uri: return f'{uri}&per_page={per_page}' - elif not re.search(r'\d$', uri) and not 'per_page=' in uri: + elif not re.search(r'\d$', uri) and not 'per_page=' in uri and not uri.endswith('me'): if uri.endswith('/'): uri = uri[:-1] return f'{uri}?per_page={per_page}' diff --git a/src/xurrent/requests.py b/src/xurrent/requests.py index 85cbb3d..72ec312 100644 --- a/src/xurrent/requests.py +++ b/src/xurrent/requests.py @@ -1,3 +1,4 @@ +from __future__ import annotations # Needed for forward references from .core import XurrentApiHelper from .core import JsonSerializableDict from enum import Enum @@ -56,6 +57,7 @@ def __init__(self, service_instance: Optional[Dict[str, str]] = None, created_at: Optional[datetime] = None, updated_at: Optional[datetime] = None, + workflow: Optional[Workflow] = None, **kwargs): self.id = id self._connection_object = connection_object # Private attribute for connection object @@ -73,6 +75,9 @@ def __init__(self, self.service_instance = service_instance self.created_at = created_at self.updated_at = updated_at + if(workflow): + from .workflows import Workflow + self.workflow = Workflow.from_data(connection_object, workflow) # Initialize any additional attributes for key, value in kwargs.items(): setattr(self, key, value) diff --git a/tests/core_test.py b/tests/core_test.py new file mode 100644 index 0000000..97a1726 --- /dev/null +++ b/tests/core_test.py @@ -0,0 +1,44 @@ +import pytest +import os +import sys +from dotenv import load_dotenv + +# Add the `../src` directory to sys.path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))) + +# Now you can import the module +from xurrent.core import XurrentApiHelper +from xurrent.people import Person + +# FILE: src/xurrent/test_core.py + +@pytest.fixture +def x_api_helper(): + # Retrieve environment variables + # Load .env file only if the environment variables are not already set + if not os.getenv("APITOKEN") or not os.getenv("APIACCOUNT") or not os.getenv("APIURL"): + load_dotenv() + api_token = os.getenv("APITOKEN") # Fetches DEMO_API_TOKEN, returns None if not set + api_account = os.getenv("APIACCOUNT") + api_url = os.getenv("APIURL") + + # Check if the environment variables are properly set + if not all([api_token, api_account, api_url]): + raise EnvironmentError("One or more environment variables are missing.") + helper = XurrentApiHelper(api_url, api_token, api_account, True) + return helper + +def test_api_helper_setup(x_api_helper): + api_token = os.getenv("APITOKEN") # Fetches DEMO_API_TOKEN, returns None if not set + api_account = os.getenv("APIACCOUNT") + api_url = os.getenv("APIURL") + assert x_api_helper is not None + assert x_api_helper.base_url == api_url + assert x_api_helper.api_account == api_account + + #check if the api_user is an instance of Person and has an id, which is int + assert isinstance(x_api_helper.api_user, Person) + assert x_api_helper.api_user.id is not None + assert isinstance(x_api_helper.api_user.id, int) + + \ No newline at end of file