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
36 changes: 27 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,62 @@ jobs:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]" || pip install -e .
pip install pytest pytest-asyncio
- name: Run tests
run: pytest -v || echo "No tests yet"
pip install -e ".[dev]"

- name: Run tests with coverage
run: |
pytest -v --cov=meshguard --cov-report=xml --cov-report=term-missing

- name: Upload coverage to Codecov
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false
verbose: true

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install linting tools
run: |
python -m pip install --upgrade pip
pip install ruff mypy
- name: Type check
run: mypy src/ --ignore-missing-imports || true
- name: Lint
run: ruff check src/ || true
pip install ruff mypy httpx

- name: Lint with Ruff
run: ruff check meshguard/

- name: Type check with mypy
run: mypy meshguard/ --ignore-missing-imports

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Build package
run: |
python -m pip install --upgrade pip build
python -m build

- name: Check package
run: |
pip install twine
Expand Down
78 changes: 78 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Ruff
.ruff_cache/

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# macOS
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# MeshGuard Python SDK

[![CI](https://github.com/meshguard/meshguard-python/actions/workflows/ci.yml/badge.svg)](https://github.com/meshguard/meshguard-python/actions/workflows/ci.yml)
[![PyPI version](https://badge.fury.io/py/meshguard.svg)](https://pypi.org/project/meshguard/)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# MeshGuard Python SDK Tests
54 changes: 54 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Pytest configuration and fixtures for MeshGuard tests.
"""

import pytest
import httpx
from unittest.mock import MagicMock


@pytest.fixture
def mock_client():
"""Create a mock httpx client for testing."""
return MagicMock(spec=httpx.Client)


@pytest.fixture
def gateway_url():
"""Default gateway URL for tests."""
return "https://test.meshguard.app"


@pytest.fixture
def agent_token():
"""Test agent token."""
return "test-agent-token-12345"


@pytest.fixture
def admin_token():
"""Test admin token."""
return "test-admin-token-67890"


@pytest.fixture
def mock_response():
"""Factory for creating mock responses."""
def _make_response(
status_code: int = 200,
json_data: dict = None,
content: bytes = None,
):
response = MagicMock(spec=httpx.Response)
response.status_code = status_code
response.content = content or (json_data and b"{}") or b""
response.text = str(json_data) if json_data else ""

if json_data is not None:
response.json.return_value = json_data
else:
response.json.side_effect = ValueError("No JSON content")

return response

return _make_response
Loading
Loading