Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirddog committed Jan 3, 2024
1 parent 1369010 commit 9a112a4
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@
from typing import Any
from spiffworkflow_backend.models.process_instance_file_data import ProcessInstanceFileDataModel
import base64
import hashlib

_sample_prefix = "testing"
def _file_content(i: int) -> bytes:
return f"testing{i}\n".encode("utf-8")

def _sample_content(i: int) -> str:
return f"{_sample_prefix}{i}\n".encode("utf-8")
def _file_data(i: int) -> str:
b64 = base64.b64encode(_file_content(i))
return f"data:some/mimetype;name=testing{i}.txt;base64,{b64}"

def _sample_file_data(i: int) -> str:
b64 = base64.b64encode(_sample_content(i))
return f"data:some/mimetype;name={_sample_prefix}{i}.txt;base64,{b64}"
def _digest_reference(i: int) -> str:
sha = haslib.sha256(_file_content(i)).hexdigest()
b64 = f"{ProcessInstanceService.FILE_DATA_DIGEST_PREFIX}{sha}"
return f"data:some/mimetype;name=testing{i}.txt;base64,{b64}"

class TestProcessInstanceService(BaseTest):
SAMPLE_FILE_DATA = "data:some/mimetype;name=testing.txt;base64,dGVzdGluZwo="
SAMPLE_DIGEST_REFERENCE = f"data:some/mimetype;name=testing.txt;base64,{ProcessInstanceService.FILE_DATA_DIGEST_PREFIX}12a61f4e173fb3a11c05d6471f74728f76231b4a5fcd9667cef3af87a3ae4dc2" # noqa: B950,E501

@pytest.mark.parametrize("data,process_instance_id,expected_data,expected_models", [
({}, 123, {}, []),
({"key": "value"}, 123, {"key": "value"}, []),
@pytest.mark.parametrize("data,process_instance_id,expected_data,expected_models_len", [
({}, 123, {}, 0),
({"key": "value"}, 123, {"key": "value"}, 0),
])
def test_save_file_data_v0(
self,
Expand All @@ -36,7 +37,7 @@ def test_save_file_data_v0(
data: dict[str, Any],
process_instance_id: int,
expected_data: dict[str, Any],
expected_models: list[ProcessInstanceFileDataModel],
expected_models_len: int,
) -> None:
ProcessInstanceService.save_file_data_and_replace_with_digest_references(
data,
Expand All @@ -47,7 +48,7 @@ def test_save_file_data_v0(
process_instance_id=process_instance_id,
).order_by(ProcessInstanceFileDataModel.id).all()

assert len(saved_file_data) == len(expected_models)
assert len(saved_file_data) == expected_models_len



Expand Down

0 comments on commit 9a112a4

Please sign in to comment.