initial ai implementation
This commit is contained in:
91
tests/test_core.py
Normal file
91
tests/test_core.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import pytest
|
||||
from linear_gitea_integration.services.linear_client import extract_issue_ids
|
||||
|
||||
|
||||
class TestExtractIssueIds:
|
||||
def test_simple_issue_id(self):
|
||||
text = "This is a fix for LIN-123"
|
||||
assert extract_issue_ids(text) == ["LIN-123"]
|
||||
|
||||
def test_multiple_issue_ids(self):
|
||||
text = "Fixes LIN-123 and fixes PROJ-456"
|
||||
ids = extract_issue_ids(text)
|
||||
assert "LIN-123" in ids
|
||||
assert "PROJ-456" in ids
|
||||
assert len(ids) == 2
|
||||
|
||||
def test_no_issue_id(self):
|
||||
text = "This is just a regular commit"
|
||||
assert extract_issue_ids(text) == []
|
||||
|
||||
def test_issue_id_in_branch(self):
|
||||
text = "feature/LIN-123-add-login"
|
||||
assert extract_issue_ids(text) == ["LIN-123"]
|
||||
|
||||
def test_issue_id_in_pr_title(self):
|
||||
text = "[LIN-456] Add new feature"
|
||||
assert extract_issue_ids(text) == ["LIN-456"]
|
||||
|
||||
def test_issue_id_with_underscore(self):
|
||||
text = "MYPROJ-789 fix"
|
||||
assert extract_issue_ids(text) == ["MYPROJ-789"]
|
||||
|
||||
|
||||
class TestConfig:
|
||||
def test_default_config(self):
|
||||
from linear_gitea_integration.config import Config
|
||||
|
||||
config = Config()
|
||||
assert config.server.port == 8080
|
||||
assert config.server.host == "0.0.0.0"
|
||||
|
||||
def test_status_mappings(self):
|
||||
from linear_gitea_integration.config import StatusMappings
|
||||
|
||||
mappings = StatusMappings()
|
||||
assert mappings.pr_created == "In Progress"
|
||||
assert mappings.pr_merged == "Done"
|
||||
assert mappings.pr_closed == "Todo"
|
||||
|
||||
|
||||
class TestModels:
|
||||
def test_gitea_pull_request_model(self):
|
||||
from linear_gitea_integration.models import GiteaPullRequest
|
||||
from linear_gitea_integration.services.linear_client import extract_issue_ids
|
||||
|
||||
pr = GiteaPullRequest(
|
||||
id=1,
|
||||
number=123,
|
||||
title="Test PR",
|
||||
state="open",
|
||||
head_branch="feature/LIN-1",
|
||||
base_branch="main",
|
||||
html_url="https://gitea.com/org/repo/pulls/123",
|
||||
)
|
||||
issue_ids = extract_issue_ids(pr.head_branch)
|
||||
assert "LIN-1" in issue_ids
|
||||
|
||||
def test_linear_issue_model(self):
|
||||
from linear_gitea_integration.models import LinearIssue
|
||||
|
||||
issue = LinearIssue(
|
||||
id="issue_123",
|
||||
identifier="LIN-123",
|
||||
title="Test Issue",
|
||||
)
|
||||
assert issue.identifier == "LIN-123"
|
||||
|
||||
|
||||
class TestParseRepo:
|
||||
def test_valid_repo(self):
|
||||
from linear_gitea_integration.services.gitea_client import parse_repo
|
||||
|
||||
owner, repo = parse_repo("my-org/my-repo")
|
||||
assert owner == "my-org"
|
||||
assert repo == "my-repo"
|
||||
|
||||
def test_invalid_repo(self):
|
||||
from linear_gitea_integration.services.gitea_client import parse_repo
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
parse_repo("invalid-repo")
|
||||
Reference in New Issue
Block a user