29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from uuid import uuid4
|
|
|
|
from archive_clients.state import ClientStore, CommandConflict
|
|
|
|
|
|
class ClientStoreTests(unittest.TestCase):
|
|
def test_command_acceptance_is_durable_and_content_addressed(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
database = Path(directory) / "state.db"
|
|
store = ClientStore(database)
|
|
store.initialize()
|
|
command_id = str(uuid4())
|
|
first = store.accept_command(command_id, '{"b":2,"a":1}', '{"ok":true}')
|
|
duplicate = ClientStore(database).accept_command(
|
|
command_id, '{"a":1,"b":2}', '{"ok":false}'
|
|
)
|
|
self.assertFalse(first.duplicate)
|
|
self.assertTrue(duplicate.duplicate)
|
|
self.assertEqual(duplicate.acknowledgement_json, '{"ok":true}')
|
|
with self.assertRaises(CommandConflict):
|
|
store.accept_command(command_id, '{"a":2}', '{"ok":true}')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|