Skip to content

Commit d3d0515

Browse files
committed
Merge github.com:DSD-DBS/polarion-rest-api-client into add-documents
2 parents 0538068 + 30a4b84 commit d3d0515

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

.github/workflows/build-test-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name: Build
66
on:
77
push:
88
branches: ["*"]
9-
pull_request: [master]
9+
pull_request: [main]
1010
tags: ["v*.*.*"]
1111

1212
jobs:
@@ -18,12 +18,12 @@ jobs:
1818
matrix:
1919
os: [ubuntu-latest]
2020
python_version:
21-
- "3.9"
2221
- "3.10"
2322
- "3.11"
23+
- "3.12"
2424
include:
2525
- os: windows-latest
26-
python_version: "3.9"
26+
python_version: "3.12"
2727
steps:
2828
- uses: actions/checkout@v3
2929
- name: Set up Python ${{matrix.python_version}}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ venv.bak/
140140
.spyderproject
141141
.spyproject
142142

143+
# VS Code settings
144+
.vscode/
145+
143146
# Rope project settings
144147
.ropeproject
145148

polarion_rest_api_client/data_models.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Data model classes returned by the client."""
44
from __future__ import annotations
55

6+
import base64
67
import dataclasses
78
import hashlib
89
import json
@@ -112,6 +113,70 @@ def __setattr__(self, key: str, value: t.Any):
112113
else:
113114
self.additional_attributes[key] = value
114115

116+
def __eq__(self, other: object) -> bool:
117+
"""Compare only WorkItem attributes."""
118+
if not isinstance(other, WorkItem):
119+
return NotImplemented
120+
if self.get_current_checksum() is None:
121+
self.calculate_checksum()
122+
if other.get_current_checksum() is None:
123+
other.calculate_checksum()
124+
125+
return self.get_current_checksum() == other.get_current_checksum()
126+
127+
def to_dict(self) -> dict[str, t.Any]:
128+
"""Return the content of the WorkItem as dictionary."""
129+
sorted_links = sorted(
130+
self.linked_work_items,
131+
key=lambda x: f"{x.role}/{x.secondary_work_item_project}/{x.secondary_work_item_id}", # pylint: disable=line-too-long
132+
)
133+
134+
sorted_attachments = sorted(
135+
self.attachments, key=lambda x: x.file_name or ""
136+
)
137+
138+
return {
139+
"id": self.id,
140+
"title": self.title,
141+
"description_type": self.description_type,
142+
"description": self.description,
143+
"type": self.type,
144+
"status": self.status,
145+
"additional_attributes": dict(
146+
sorted(self.additional_attributes.items())
147+
),
148+
"checksum": self._checksum,
149+
"linked_work_items": [
150+
dataclasses.asdict(lwi) for lwi in sorted_links
151+
],
152+
"attachments": [
153+
dataclasses.asdict(at) for at in sorted_attachments
154+
],
155+
}
156+
157+
def calculate_checksum(self) -> str:
158+
"""Calculate and return a checksum for this WorkItem.
159+
160+
In addition, the checksum will be written to self._checksum.
161+
"""
162+
data = self.to_dict()
163+
del data["checksum"]
164+
del data["id"]
165+
166+
for attachment in data["attachments"]:
167+
try:
168+
attachment["content_bytes"] = base64.b64encode(
169+
attachment["content_bytes"]
170+
).decode("utf8")
171+
except TypeError:
172+
pass
173+
174+
data = dict(sorted(data.items()))
175+
176+
converted = json.dumps(data).encode("utf8")
177+
self._checksum = hashlib.sha256(converted).hexdigest()
178+
return self._checksum
179+
115180

116181
@dataclasses.dataclass
117182
class WorkItemLink:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dynamic = ["version"]
1111
name = "polarion-rest-api-client"
1212
description = "An API Client for the Polarion REST API"
1313
readme = "README.md"
14-
requires-python = ">=3.9, <3.12"
14+
requires-python = ">=3.10, <3.13"
1515
license = { text = "Apache-2.0" }
1616
authors = [
1717
{ name = "DB Netz AG" },
@@ -23,9 +23,9 @@ classifiers = [
2323
"Natural Language :: English",
2424
"Operating System :: OS Independent",
2525
"Programming Language :: Python :: 3 :: Only",
26-
"Programming Language :: Python :: 3.9",
2726
"Programming Language :: Python :: 3.10",
2827
"Programming Language :: Python :: 3.11",
28+
"Programming Language :: Python :: 3.12",
2929
]
3030
dependencies = [
3131
"httpx>=0.20.0,<0.25.0",

0 commit comments

Comments
 (0)