From f2d3d8714477f50af815015f46261d6c2faf2715 Mon Sep 17 00:00:00 2001 From: Shahriar Date: Tue, 18 Jun 2024 18:33:36 +0200 Subject: [PATCH 1/6] feat: Refactor unit test command in GitHub workflow --- .github/workflows/test.yml | 5 +---- tests/test_omnivoreql.py | 11 +++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4b85683..be5a034 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,10 +18,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: Run unit tests - run: | - cd tests - python -m unittest test_omnivoreql.py + run: python -m unittest discover -s tests env: OMNIVORE_API_TOKEN: ${{ secrets.OMNIVORE_API_TOKEN }} diff --git a/tests/test_omnivoreql.py b/tests/test_omnivoreql.py index 5cd053a..b0c6788 100644 --- a/tests/test_omnivoreql.py +++ b/tests/test_omnivoreql.py @@ -2,13 +2,8 @@ import unittest import sys from dotenv import load_dotenv - -# Add the parent directory to the path to import the OmnivoreQL module -current_dir = os.path.dirname(os.path.abspath(__file__)) -omnivoreql_dir = os.path.join(current_dir, "..", "omnivoreql") -sys.path.insert(0, omnivoreql_dir) -from omnivoreql import OmnivoreQL, CreateLabelInput - +from omnivoreql.omnivoreql import OmnivoreQL +from omnivoreql.models import CreateLabelInput class TestOmnivoreQL(unittest.TestCase): client = None @@ -21,7 +16,7 @@ def setUpClass(cls): This method initializes the OmnivoreQL client with an API token. The 'OMNIVORE_API_TOKEN' must be specified either in a '.env' file located in the same directory as this script or passed directly when executing the test script. - + Example command to run tests with an environment variable: python -m unittest test_omnivoreql.py OMNIVORE_API_TOKEN='your_api_token_here' From 4bec320cb792a4dad85c6f0ef8086bf7a0429659 Mon Sep 17 00:00:00 2001 From: Shahriar Date: Tue, 18 Jun 2024 18:34:20 +0200 Subject: [PATCH 2/6] fix: change importing modules way --- omnivoreql/__init__.py | 1 + omnivoreql/omnivoreql.py | 8 ++++---- setup.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/omnivoreql/__init__.py b/omnivoreql/__init__.py index b92d4a4..fc59754 100644 --- a/omnivoreql/__init__.py +++ b/omnivoreql/__init__.py @@ -1 +1,2 @@ from .omnivoreql import OmnivoreQL +from .models import CreateLabelInput \ No newline at end of file diff --git a/omnivoreql/omnivoreql.py b/omnivoreql/omnivoreql.py index 062a0db..e3c9f88 100644 --- a/omnivoreql/omnivoreql.py +++ b/omnivoreql/omnivoreql.py @@ -1,11 +1,11 @@ -from gql import gql, Client -from gql.transport.requests import RequestsHTTPTransport import uuid -from models import CreateLabelInput -from dataclasses import asdict import os import glob from typing import List, Optional +from gql.transport.requests import RequestsHTTPTransport +from gql import gql, Client +from dataclasses import asdict +from .models import CreateLabelInput class OmnivoreQL: diff --git a/setup.py b/setup.py index cc25c23..51aa978 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import setup, find_packages import subprocess @@ -37,7 +37,7 @@ def read_requirements(): description="Omnivore API Client for Python", author="Shahriar Yazdipour", author_email="git@yazdipour.com", - packages=["omnivoreql"], + packages=find_packages(), long_description=open("README.md").read(), long_description_content_type="text/markdown", license="MIT", From e0030b16be192589d854713a924f92b372f021e1 Mon Sep 17 00:00:00 2001 From: Shahriar Date: Tue, 18 Jun 2024 18:46:09 +0200 Subject: [PATCH 3/6] refactor: Remove unused imports in models.py --- omnivoreql/models.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/omnivoreql/models.py b/omnivoreql/models.py index ce9d469..4b8c60c 100644 --- a/omnivoreql/models.py +++ b/omnivoreql/models.py @@ -1,6 +1,3 @@ -from dataclasses import dataclass -from typing import Optional - from dataclasses import dataclass, field from typing import Optional From cc07cfde2593372c8f9050bd73b908a4ea944930 Mon Sep 17 00:00:00 2001 From: Shahriar Date: Tue, 18 Jun 2024 18:57:53 +0200 Subject: [PATCH 4/6] feat: Add print statement for starting OmnivoreQL tests --- tests/test_omnivoreql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_omnivoreql.py b/tests/test_omnivoreql.py index b0c6788..972bb31 100644 --- a/tests/test_omnivoreql.py +++ b/tests/test_omnivoreql.py @@ -16,13 +16,13 @@ def setUpClass(cls): This method initializes the OmnivoreQL client with an API token. The 'OMNIVORE_API_TOKEN' must be specified either in a '.env' file located in the same directory as this script or passed directly when executing the test script. - Example command to run tests with an environment variable: python -m unittest test_omnivoreql.py OMNIVORE_API_TOKEN='your_api_token_here' Raises: ValueError: If the 'OMNIVORE_API_TOKEN' is not set. """ + print("\nStarting OmnivoreQL tests...\n") api_token = cls.getEnvVariable("OMNIVORE_API_TOKEN") if api_token is None: raise ValueError("OMNIVORE_API_TOKEN is not set") From 404a40d56f9c0071f4aae93376ca58056f40c6bd Mon Sep 17 00:00:00 2001 From: Shahriar Date: Tue, 18 Jun 2024 19:09:06 +0200 Subject: [PATCH 5/6] chore: Update unit test command --- tests/test_omnivoreql.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_omnivoreql.py b/tests/test_omnivoreql.py index 972bb31..631e4de 100644 --- a/tests/test_omnivoreql.py +++ b/tests/test_omnivoreql.py @@ -5,6 +5,11 @@ from omnivoreql.omnivoreql import OmnivoreQL from omnivoreql.models import CreateLabelInput +""" +Unit tests for the OmnivoreQL client. +To run the tests, execute the following command: + python -m unittest discover -s tests +""" class TestOmnivoreQL(unittest.TestCase): client = None From 6d7302264091560782a93d3eae37cb1ce8ccc80b Mon Sep 17 00:00:00 2001 From: Shahriar Date: Tue, 18 Jun 2024 19:10:30 +0200 Subject: [PATCH 6/6] feat: Update GitHub workflow to trigger on push events only --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be5a034..ff3def0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Unit Tests -on: [push, pull_request] +on: [push] jobs: test: