Skip to content

Commit

Permalink
Merge pull request #5 from zyv/feature/status-enum
Browse files Browse the repository at this point in the history
Add import status enum for type safety
  • Loading branch information
zyv authored Feb 14, 2025
2 parents 6246a04 + 30769e7 commit 58c91f0
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 207 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![PyPI License](https://img.shields.io/pypi/l/github-issues-import)](https://github.com/zyv/github-issues-import/blob/main/LICENSE)
[![PyPI project](https://img.shields.io/pypi/v/github-issues-import.svg?logo=python&logoColor=edb641)](https://pypi.python.org/pypi/ruff)
![Python versions](https://img.shields.io/badge/python-3.10+-blue?logo=python&logoColor=edb641)
![Python versions](https://img.shields.io/pypi/pyversions/github-issues-import.svg?logo=python&logoColor=edb641)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![CI](https://github.com/zyv/github-issues-import/workflows/CI/badge.svg)](https://github.com/zyv/github-issues-import/actions)
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dynamic = ["version"]
requires-python = ">=3.10"
requires-python = ">=3.11"
dependencies = [
"pydantic>=2.0",
"httpx",
Expand All @@ -25,7 +29,6 @@ dependencies = [
[dependency-groups]
dev = [
"hatch>=1.14.0",
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"pytest-httpx>=0.35.0",
"ruff>=0.9.5",
Expand Down Expand Up @@ -64,8 +67,7 @@ select = [
]

ignore = [
"COM812",
"UP017", # TODO: drop when Python 3.10 is EOL
"COM812", # comma consistency enforced by formatter
]

fixable = ["ALL"]
Expand Down
10 changes: 8 additions & 2 deletions src/github_issues_import/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Literal
from enum import StrEnum, auto

from pydantic import AwareDatetime, ConfigDict, HttpUrl
from pydantic import BaseModel as PydanticBaseModel
Expand Down Expand Up @@ -50,9 +50,15 @@ class IssueImportError(BaseModel):
code: str


class IssueImportStatus(StrEnum):
PENDING = auto()
IMPORTED = auto()
FAILED = auto()


class IssueImportStatusResponse(BaseModel):
id: int
status: Literal["pending", "imported", "failed"]
status: IssueImportStatus
url: HttpUrl
import_issues_url: HttpUrl
repository_url: HttpUrl
Expand Down
18 changes: 7 additions & 11 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import re
from datetime import datetime, timezone
from datetime import UTC, datetime

import httpx
import pytest
Expand All @@ -9,7 +9,7 @@
from pytest_httpx import HTTPXMock

from github_issues_import.client import ApiClient
from github_issues_import.models import IssueImportRequest, IssueImportStatusResponse
from github_issues_import.models import IssueImportRequest, IssueImportStatus, IssueImportStatusResponse

from .utils import get_fixture

Expand Down Expand Up @@ -38,9 +38,7 @@ def test_timeout_default(httpx_mock: HTTPXMock):
status_code=httpx.codes.BAD_GATEWAY,
)
with pytest.raises(httpx.HTTPStatusError):
ApiClient(token=GITHUB_TOKEN, base_url="https://test").get_status_multiple(
"foo", "bar", datetime.now(tz=timezone.utc)
)
ApiClient(token=GITHUB_TOKEN, base_url="https://test").get_status_multiple("foo", "bar", datetime.now(tz=UTC))


def test_timeout_set(httpx_mock: HTTPXMock):
Expand All @@ -50,7 +48,7 @@ def test_timeout_set(httpx_mock: HTTPXMock):
)
with pytest.raises(httpx.HTTPStatusError):
ApiClient(token=GITHUB_TOKEN, base_url="https://test", timeout=123).get_status_multiple(
"foo", "bar", datetime.now(tz=timezone.utc)
"foo", "bar", datetime.now(tz=UTC)
)


Expand All @@ -59,9 +57,7 @@ def test_base_url(httpx_mock: HTTPXMock):
url=re.compile(r"^https://test/repos/foo/bar/import/issues"),
text=get_fixture("response-multiple-check-status-of-multiple-issues.json"),
)
ApiClient(token=GITHUB_TOKEN, base_url="https://test").get_status_multiple(
"foo", "bar", datetime.now(tz=timezone.utc)
)
ApiClient(token=GITHUB_TOKEN, base_url="https://test").get_status_multiple("foo", "bar", datetime.now(tz=UTC))


def test_raise_for_status(api_client: ApiClient, httpx_mock: HTTPXMock):
Expand All @@ -87,7 +83,7 @@ def test_import_issue(api_client: ApiClient, httpx_mock: HTTPXMock):
)

assert response == IssueImportStatusResponse.model_validate_json(import_response)

assert response.status == IssueImportStatus.PENDING
request = httpx_mock.get_request()

assert request.url == "https://api.github.com/repos/owner/repository/import/issues"
Expand All @@ -109,7 +105,7 @@ def test_get_import_status(api_client: ApiClient, httpx_mock: HTTPXMock):

def test_get_import_status_multiple(api_client: ApiClient, httpx_mock: HTTPXMock):
multiple_status_response = get_fixture("response-multiple-check-status-of-multiple-issues.json")
since = datetime.now(tz=timezone.utc)
since = datetime.now(tz=UTC)

httpx_mock.add_response(
url=httpx.URL(
Expand Down
Loading

0 comments on commit 58c91f0

Please sign in to comment.