casebench
test cases straight onto the board.
git clone https://owenrusk.dev/casebench.git
commit 2ed08da9f0fdef0bfd189c05e9176fc18c36b7e3 parent 641dbfcd4fd650023107462d523c2ec7b7b46018 author Owen Rusk <owen@papermothgames.com> date 2025-09-09 14:51:46 -0500
memstore: keep notes and lock when a case is put again postgres always kept them. the memstore threw them away with the old items.
| casebench/memstore.py | +6 | -1 |
| tests/test_commands.py | +8 | -0 |
diff --git a/casebench/memstore.py b/casebench/memstore.py index c9d0d25..a0e197b 100644 --- a/casebench/memstore.py +++ b/casebench/memstore.py @@ -68,7 +68,12 @@ class MemStore: self.media.setdefault(sha, image) shas.append(sha) items.append(_Item(item.id, item.title, item.text, shas))- self.cases[(player.id, case.id)] = _Case(case.title, BENCH, datetime.now(UTC), items)+ old = self.cases.get((player.id, case.id)) + if old is None: + self.cases[(player.id, case.id)] = _Case(case.title, BENCH, datetime.now(UTC), items) + else: + # as in postgres: the title and items are replaced, notes and a lock stay. + old.title, old.items = case.title, items def pull(self, player: Player, case_id: str) -> None: del self.cases[(player.id, case_id)] diff --git a/tests/test_commands.py b/tests/test_commands.py index 6236cd3..0d356f7 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -17,6 +17,14 @@ class PutTest(unittest.TestCase): self.assertEqual(self.store.items(self.owen, "test-lost-umbrella"), ["ticket", "log", "umbrella"]) self.assertIsNone(self.store.placed(self.store.player("tess"), "test-lost-umbrella")) + def test_putting_again_keeps_notes_and_lock(self): + run(self.store, "put", str(UMBRELLA), "--player", "owen") + run(self.store, "note", "test-lost-umbrella", "keep me", "--player", "owen") + run(self.store, "lock", "test-lost-umbrella", "--answer", "a", "--player", "owen") + run(self.store, "put", str(UMBRELLA), "--player", "owen") + self.assertEqual(self.store.notes(self.owen, "test-lost-umbrella"), [(None, "keep me")]) + self.assertIsNotNone(self.store.get_lock(self.owen, "test-lost-umbrella")) + def test_no_such_player(self): code, _, err = run(self.store, "put", str(UMBRELLA), "--player", "nobody") self.assertEqual(code, 1)