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
34 changes: 34 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: |
uv venv
uv pip install .[dev]

- name: Run tests
run: |
uv run pytest
4 changes: 3 additions & 1 deletion gittask/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@app.command()
def login(
token: str = typer.Option(None, prompt=True, hide_input=True, help="Asana Personal Access Token"),
token: str = typer.Option(None, help="Asana Personal Access Token"),
github: bool = typer.Option(False, "--github", help="Login with GitHub Token")
):
"""
Expand All @@ -20,6 +20,8 @@ def login(
config.set_github_token(github_token)
console.print("[green]Successfully logged in to GitHub![/green]")
else:
if not token:
token = typer.prompt("Asana Personal Access Token", hide_input=True)
config.set_api_token(token)
console.print("[green]Successfully logged in to Asana![/green]")

Expand Down
7 changes: 1 addition & 6 deletions gittask/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ def commit(
# Git commit failed (e.g., nothing to commit)
raise typer.Exit(code=1)

try:
subprocess.run(cmd, check=True)
console.print("[green]Commit successful.[/green]")
except subprocess.CalledProcessError:
# Git commit failed (e.g., nothing to commit)
raise typer.Exit(code=1)


# Asana posting moved to 'push' command
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ dependencies = [
"PyGithub",
]

[project.optional-dependencies]
dev = [
"pytest",
"pytest-mock",
]

[project.scripts]
gittask = "gittask.main:app"
gt = "gittask.main:app"
Expand Down
57 changes: 57 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest
from unittest.mock import MagicMock
import os
import tempfile
from pathlib import Path
from gittask.database import DBManager
from gittask.config import ConfigManager

@pytest.fixture
def mock_db(tmp_path):
"""
Fixture for a temporary database.
"""
db_path = tmp_path / "db.json"
db = DBManager(str(db_path))
return db

@pytest.fixture
def mock_asana(mocker):
"""
Fixture for mocking AsanaClient.
"""
mock_client = MagicMock()
mocker.patch("gittask.commands.track.AsanaClient", return_value=mock_client)
mocker.patch("gittask.commands.checkout.AsanaClient", return_value=mock_client)
return mock_client

@pytest.fixture
def mock_git(mocker):
"""
Fixture for mocking GitHandler.
"""
mock_git_handler = MagicMock()
mocker.patch("gittask.commands.checkout.GitHandler", return_value=mock_git_handler)
mocker.patch("gittask.commands.session.GitHandler", return_value=mock_git_handler)

# Default behavior
mock_git_handler.get_current_branch.return_value = "main"
mock_git_handler.get_repo_root.return_value = "/tmp/mock_repo"

return mock_git_handler

@pytest.fixture
def mock_config(mocker, mock_db):
"""
Fixture for mocking ConfigManager.
"""
mock_config_manager = MagicMock()
mocker.patch("gittask.commands.track.ConfigManager", return_value=mock_config_manager)
mocker.patch("gittask.commands.checkout.ConfigManager", return_value=mock_config_manager)

# Default behavior
mock_config_manager.get_api_token.return_value = "mock_token"
mock_config_manager.get_default_workspace.return_value = "mock_workspace_gid"
mock_config_manager.get_default_project.return_value = "mock_project_gid"

return mock_config_manager
Loading