|
Last change
on this file was 753855a, checked in by Enrico Schwass <ennoausberlin@…>, 6 weeks ago |
|
add more backends and tests
|
-
Property mode
set to
100644
|
|
File size:
900 bytes
|
| Line | |
|---|
| 1 | #!/usr/bin/env python3
|
|---|
| 2 |
|
|---|
| 3 | from flexoentity.domain import Domain
|
|---|
| 4 | from flexoentity.json_file_backend import JsonFileBackend
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | def make_domain(domain_id="PY_ARITHM"):
|
|---|
| 8 | return Domain.with_domain_id(
|
|---|
| 9 | subtype="Domain",
|
|---|
| 10 | domain_id=domain_id,
|
|---|
| 11 | fullname="PYTHON_ARITHMETIC",
|
|---|
| 12 | description="ALL ABOUT ARITHMETIC IN PYTHON",
|
|---|
| 13 | classification="UNCLASSIFIED",
|
|---|
| 14 | )
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | def test_jsonfile_roundtrip(tmp_path):
|
|---|
| 18 | path = tmp_path / "domains.json"
|
|---|
| 19 | backend = JsonFileBackend(Domain, path)
|
|---|
| 20 |
|
|---|
| 21 | dom1 = make_domain("PY_ARITHM")
|
|---|
| 22 | dom2 = make_domain("PY_STRINGS")
|
|---|
| 23 |
|
|---|
| 24 | backend.save(dom1)
|
|---|
| 25 | backend.save(dom2)
|
|---|
| 26 | backend.flush_to_file()
|
|---|
| 27 |
|
|---|
| 28 | # new instance simulating a reload
|
|---|
| 29 | backend2 = JsonFileBackend(Domain, path)
|
|---|
| 30 | backend2.load_from_file()
|
|---|
| 31 |
|
|---|
| 32 | loaded = backend2.load_all()
|
|---|
| 33 | ids = sorted(d.domain_id for d in loaded)
|
|---|
| 34 | assert ids == ["PY_ARITHM", "PY_STRINGS"]
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.