source: flexoentity/tests/conftest.py@ 524040a

Last change on this file since 524040a was 524040a, checked in by Enrico Schwass <ennoausberlin@…>, 3 months ago

add lots of convinience methods

  • Property mode set to 100644
File size: 2.0 KB
Line 
1# tests/conftest.py
2
3import pytest
4import json
5from flexoentity import FlexoEntity, EntityType, EntityState, Domain
6
7
8class DummyEntity(FlexoEntity):
9 """Minimal concrete subclass for testing FlexoEntity logic."""
10
11 def __init__(self, domain, etype, state, seed="DUMMY"):
12 self._seed = seed
13 super().__init__(domain, etype, state)
14
15 @property
16 def text_seed(self) -> str:
17 return self._seed
18
19 @classmethod
20 def from_dict(cls, data):
21 """Ensure enums and seed are reconstructed correctly."""
22 domain = data["domain"]
23 etype = EntityType[data["etype"]] if isinstance(data["etype"], str) else data["etype"]
24 state = EntityState[data["state"]] if isinstance(data["state"], str) else data["state"]
25 seed = data.get("text_seed", "DUMMY-CONTENT")
26 return cls(domain=domain, etype=etype, state=state, seed=seed)
27
28 @classmethod
29 def from_json(cls, data_str: str):
30 return cls.from_dict(json.loads(data_str))
31
32@pytest.fixture
33def entity():
34 """Generic FlexoEntity-like instance in draft state."""
35 return DummyEntity(
36 domain=Domain(domain="SIG", etype=EntityType.DOMAIN, state=EntityState.DRAFT, fullname="Signal Corps", classification="RESTRICTED"),
37 etype=EntityType.CATALOG,
38 state=EntityState.DRAFT,
39 )
40
41@pytest.fixture
42def sample_exam():
43 """Reusable Exam fixture with default metadata for tests."""
44 exam = Exam(
45 domain="AF",
46 etype=EntityType.EXAM,
47 state=EntityState.DRAFT,
48 title="Signals Exam",
49 duration="30 min",
50 allowed_aids="none",
51 headline="Basics of Signals",
52 intro_note="Welcome to the exam",
53 submit_note="Submit carefully",
54 author="Tester",
55 )
56 return exam
57
58@pytest.fixture
59def null_media():
60 """Provide a default NullMediaItem instance for tests."""
61 return NullMediaItem(
62 domain="GEN",
63 etype=EntityType.MEDIA,
64 state=EntityState.DRAFT
65 )
Note: See TracBrowser for help on using the repository browser.