1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
# SPDX-FileCopyrightText: 2024-present Hinrich Mahler <chango@mahlerhome.de>
#
# SPDX-License-Identifier: MIT
import pytest
from pydantic import ValidationError
from chango.action import ChanGoActionData, LinkedIssue, ParentPullRequest
@pytest.fixture(scope="module")
def parent_pull_request():
return ParentPullRequest(
number=1, author_login="author", title="title", url="http://example.com", state="OPEN"
)
@pytest.fixture(scope="module")
def linked_issue():
return LinkedIssue(number=1, title="title", labels=["label1", "label2"], issue_type="type")
class TestParentPullRequest:
def test_init_basic(self, parent_pull_request):
assert parent_pull_request.number == 1
assert parent_pull_request.author_login == "author"
assert parent_pull_request.title == "title"
assert str(parent_pull_request.url) == "http://example.com/"
assert parent_pull_request.state == "OPEN"
def test_frozen(self, parent_pull_request):
with pytest.raises(ValidationError, match="frozen"):
parent_pull_request.number = 2
def test_invalid_url(self):
with pytest.raises(ValidationError, match="input_value='example.com'"):
ParentPullRequest(
number=1, author_login="author", title="title", url="example.com", state="open"
)
def test_invalid_state(self):
with pytest.raises(ValidationError, match="input_value='invalid'"):
ParentPullRequest(
number=1,
author_login="author",
title="title",
url="http://example.com",
state="invalid",
)
class TestLinkedIssue:
def test_init_basic(self, linked_issue):
assert linked_issue.number == 1
assert linked_issue.title == "title"
assert linked_issue.labels == ("label1", "label2")
assert linked_issue.issue_type == "type"
def test_init_no_optional(self):
linked_issue = LinkedIssue(number=1, title="title", labels=None)
assert linked_issue.labels is None
assert linked_issue.issue_type is None
def test_frozen(self, linked_issue):
with pytest.raises(ValidationError, match="frozen"):
linked_issue.number = 2
def test_init_none_labels(self):
linked_issue = LinkedIssue(number=1, title="title", labels=None, issue_type=None)
assert linked_issue.labels is None
assert linked_issue.issue_type is None
class TestChanGoActionData:
def test_init_basic(self, parent_pull_request, linked_issue):
data = ChanGoActionData(
parent_pull_request=parent_pull_request, linked_issues=[linked_issue]
)
assert data.parent_pull_request == parent_pull_request
assert data.linked_issues == (linked_issue,)
def test_init_none(self):
data = ChanGoActionData(parent_pull_request=None, linked_issues=None)
assert data.parent_pull_request is None
assert data.linked_issues is None
def test_frozen(self, parent_pull_request, linked_issue):
data = ChanGoActionData(
parent_pull_request=parent_pull_request, linked_issues=[linked_issue]
)
with pytest.raises(ValidationError, match="frozen"):
data.parent_pull_request = None
with pytest.raises(ValidationError, match="frozen"):
data.linked_issues = None
|