From 3b52ee4b70ee2da2962eea34526aacab0d8bf84b Mon Sep 17 00:00:00 2001 From: huyenngn Date: Mon, 9 Oct 2023 14:46:35 +0200 Subject: [PATCH 1/2] feat: separate attachment checksum --- polarion_rest_api_client/data_models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/polarion_rest_api_client/data_models.py b/polarion_rest_api_client/data_models.py index 1e7d80c6..4a5582e4 100644 --- a/polarion_rest_api_client/data_models.py +++ b/polarion_rest_api_client/data_models.py @@ -110,13 +110,17 @@ def calculate_checksum(self) -> str: del data["checksum"] del data["id"] - for at in data["attachments"]: - del at["id"] + attachments = data.pop("attachments") data = dict(sorted(data.items())) converted = json.dumps(data).encode("utf8") - self._checksum = hashlib.sha256(converted).hexdigest() + converted_attachments = json.dumps(attachments).encode("utf8") + self._checksum = ( + hashlib.sha256(converted).hexdigest() + + " " + + hashlib.sha256(converted_attachments).hexdigest() + ) return self._checksum def get_current_checksum(self) -> str | None: From 3feeedbbf22b0638e8473cf189462f210edb848a Mon Sep 17 00:00:00 2001 From: huyenngn Date: Mon, 9 Oct 2023 14:54:57 +0200 Subject: [PATCH 2/2] fix: serialize attachments --- .gitignore | 3 +++ polarion_rest_api_client/data_models.py | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 975287e9..4baa4a10 100644 --- a/.gitignore +++ b/.gitignore @@ -137,6 +137,9 @@ venv.bak/ .spyderproject .spyproject +# VS Code settings +.vscode/ + # Rope project settings .ropeproject diff --git a/polarion_rest_api_client/data_models.py b/polarion_rest_api_client/data_models.py index 4a5582e4..41349bb4 100644 --- a/polarion_rest_api_client/data_models.py +++ b/polarion_rest_api_client/data_models.py @@ -3,6 +3,7 @@ """Data model classes returned by the client.""" from __future__ import annotations +import base64 import dataclasses import hashlib import json @@ -110,17 +111,18 @@ def calculate_checksum(self) -> str: del data["checksum"] del data["id"] - attachments = data.pop("attachments") + for attachment in data["attachments"]: + try: + attachment["content_bytes"] = base64.b64encode( + attachment["content_bytes"] + ).decode("utf8") + except TypeError: + pass data = dict(sorted(data.items())) converted = json.dumps(data).encode("utf8") - converted_attachments = json.dumps(attachments).encode("utf8") - self._checksum = ( - hashlib.sha256(converted).hexdigest() - + " " - + hashlib.sha256(converted_attachments).hexdigest() - ) + self._checksum = hashlib.sha256(converted).hexdigest() return self._checksum def get_current_checksum(self) -> str | None: