| 1 | import pytest
|
|---|
| 2 | from flexoentity.in_memory_backend import InMemoryBackend
|
|---|
| 3 | from flexoentity.domain import Domain
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | def test_save_and_load_roundtrip(backend, sample_domain):
|
|---|
| 9 | backend.save(sample_domain)
|
|---|
| 10 |
|
|---|
| 11 | loaded = backend.load(sample_domain.flexo_id)
|
|---|
| 12 | assert isinstance(loaded, Domain)
|
|---|
| 13 | # important: entity equality is probably identity-based, so compare dicts:
|
|---|
| 14 | assert loaded.to_dict() == sample_domain.to_dict()
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | def test_update_overwrites_entity(backend, sample_domain):
|
|---|
| 18 | backend.save(sample_domain)
|
|---|
| 19 |
|
|---|
| 20 | # change something
|
|---|
| 21 | sample_domain.description = "UPDATED DESC"
|
|---|
| 22 | backend.update(sample_domain)
|
|---|
| 23 |
|
|---|
| 24 | loaded = backend.load(sample_domain.flexo_id)
|
|---|
| 25 | assert loaded.description == "UPDATED DESC"
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | def test_delete_removes_entity(backend, sample_domain):
|
|---|
| 29 | backend.save(sample_domain)
|
|---|
| 30 | backend.delete(sample_domain.flexo_id)
|
|---|
| 31 |
|
|---|
| 32 | assert backend.load(sample_domain.flexo_id) is None
|
|---|
| 33 | assert backend.load_all() == []
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | def test_clear_removes_all(backend, sample_domain):
|
|---|
| 37 | backend.save(sample_domain)
|
|---|
| 38 | backend.clear()
|
|---|
| 39 |
|
|---|
| 40 | assert backend.load(sample_domain.flexo_id) is None
|
|---|
| 41 | assert backend.load_all() == []
|
|---|