Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" },
]
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pytest
requests
6 changes: 4 additions & 2 deletions src/xurrent/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations # Needed for forward references
import logging
import requests
import logging
import json
import re

Expand Down Expand Up @@ -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}'
Expand Down
5 changes: 5 additions & 0 deletions src/xurrent/requests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations # Needed for forward references
from .core import XurrentApiHelper
from .core import JsonSerializableDict
from enum import Enum
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions tests/core_test.py
Original file line number Diff line number Diff line change
@@ -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)


Loading