Changeset fd1913f in flexoentity
- Timestamp:
- 11/20/25 12:01:11 (8 weeks ago)
- Branches:
- master
- Children:
- 9592936
- Parents:
- 32fdc4a
- Files:
-
- 5 edited
-
flexoentity/domain.py (modified) (2 diffs)
-
flexoentity/flexo_entity.py (modified) (3 diffs)
-
flexoentity/id_factory.py (modified) (1 diff)
-
tests/conftest.py (modified) (1 diff)
-
tests/test_flexoid.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
flexoentity/domain.py
r32fdc4a rfd1913f 22 22 fullname="Generic Domain", classification="UNCLASSIFIED") 23 23 24 def __post_init__(self):25 super().__post_init__()26 # Create a FlexOID only if none was restored27 if not getattr(self, "flexo_id", None):28 self.flexo_id = FlexOID.safe_generate(29 domain_id=self.domain_id,30 entity_type=self.ENTITY_TYPE.value, # "D"31 state=EntityState.DRAFT.value, # "D"32 text=self.domain_id, # seed must be stable33 version=1,34 )35 36 24 @property 37 25 def text_seed(self) -> str: … … 56 44 flexo_id = FlexOID(data["flexo_id"]) 57 45 58 print("Data:", data)59 46 obj = cls( 60 47 fullname=data.get("fullname", ""), -
flexoentity/flexo_entity.py
r32fdc4a rfd1913f 320 320 321 321 @classmethod 322 def from_json(cls, data_str: str) -> "FlexoEntity":322 def from_json(cls, data_str: str): 323 323 """I create a new instance from a JSON string.""" 324 324 data = json.loads(data_str) 325 325 return cls.from_dict(data) 326 326 327 @staticmethod328 def should_version(state) -> bool:329 """330 FIXME: This is now superfluous, because lifecycle changes should not increment331 version at all.332 I determine if a given lifecycle state should trigger a version increment.333 334 Entities typically version when they move into more stable or335 externally visible states, such as APPROVED, SIGNED, or PUBLISHED.336 """337 338 return state in (339 EntityState.APPROVED,340 EntityState.APPROVED_AND_SIGNED,341 EntityState.PUBLISHED,342 )343 344 327 def _compute_fingerprint(self) -> str: 345 """I alwaysrecompute the entity's content fingerprint."""328 """I recompute the entity's content fingerprint.""" 346 329 seed = self.canonical_seed() 347 330 return hashlib.blake2s(seed.encode("utf-8"), digest_size=8).hexdigest().upper() … … 349 332 def _update_fingerprint(self) -> bool: 350 333 """ 351 FIXME: I am not sure if this is correct behaviour. 352 I Update FlexOID if the content fingerprint changed. 334 I update FlexOID if the content fingerprint changed. 353 335 """ 354 336 new_fp = self._compute_fingerprint() … … 379 361 self.flexo_id = self.flexo_id.with_state(EntityState.OBSOLETE.value) 380 362 return 381 382 # version bump only for stable/external states383 if self.should_version(target_state):384 self._update_fingerprint()385 self.flexo_id = FlexOID.next_version(self.flexo_id)386 363 387 364 self.state = target_state -
flexoentity/id_factory.py
r32fdc4a rfd1913f 354 354 return FlexOID.safe_generate(domain, entity_type, state, text, version=1) 355 355 356 def parsed(self) -> dict:356 def to_dict(self) -> dict: 357 357 """ 358 358 I answer a dictionary that describes all my components — -
tests/conftest.py
r32fdc4a rfd1913f 82 82 # restore FlexoEntity core fields 83 83 if "flexo_id" in data: 84 obj.flexo_id = FlexOID. parsed(data["flexo_id"])84 obj.flexo_id = FlexOID.to_dict(data["flexo_id"]) 85 85 return obj 86 86 -
tests/test_flexoid.py
r32fdc4a rfd1913f 134 134 def test_parsed_returns_expected_dict(): 135 135 fid = FlexOID("GEN-I251101-ABCDEF123456@007S") 136 data = fid. parsed()136 data = fid.to_dict() 137 137 assert data["domain_id"] == "GEN" 138 138 assert data["entity_type"] == "I"
Note:
See TracChangeset
for help on using the changeset viewer.
