| 1 | from flexoentity.in_memory_backend import InMemoryBackend
|
|---|
| 2 | from flexoentity.composite_backend import CompositeBackend
|
|---|
| 3 | from flexoentity.domain import Domain
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | def test_composite_writes_to_all_backends(sample_domain):
|
|---|
| 7 | primary = InMemoryBackend(Domain)
|
|---|
| 8 | secondary = InMemoryBackend(Domain)
|
|---|
| 9 |
|
|---|
| 10 | backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary])
|
|---|
| 11 |
|
|---|
| 12 | backend.save(sample_domain)
|
|---|
| 13 |
|
|---|
| 14 | fid = sample_domain.flexo_id
|
|---|
| 15 |
|
|---|
| 16 | # both must see the entity
|
|---|
| 17 | assert primary.load(fid) is not None
|
|---|
| 18 | assert secondary.load(fid) is not None
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | def test_composite_reads_from_primary_only(sample_domain):
|
|---|
| 22 | primary = InMemoryBackend(Domain)
|
|---|
| 23 | secondary = InMemoryBackend(Domain)
|
|---|
| 24 |
|
|---|
| 25 | backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary])
|
|---|
| 26 |
|
|---|
| 27 | primary.save(sample_domain)
|
|---|
| 28 |
|
|---|
| 29 | # secondary has nothing, but composite should still load from primary
|
|---|
| 30 | fid = sample_domain.flexo_id
|
|---|
| 31 | loaded = backend.load(fid)
|
|---|
| 32 | assert isinstance(loaded, Domain)
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | def test_composite_clear_propagates(sample_domain):
|
|---|
| 36 | primary = InMemoryBackend(Domain)
|
|---|
| 37 | secondary = InMemoryBackend(Domain)
|
|---|
| 38 |
|
|---|
| 39 | backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary])
|
|---|
| 40 |
|
|---|
| 41 | backend.save(sample_domain)
|
|---|
| 42 |
|
|---|
| 43 | backend.clear()
|
|---|
| 44 |
|
|---|
| 45 | assert primary.load_all() == []
|
|---|
| 46 | assert secondary.load_all() == []
|
|---|