Skip to content

Commit

Permalink
ZO-4267: Raise KeyError when unlocking nonexisting resource
Browse files Browse the repository at this point in the history
  • Loading branch information
louika committed Feb 28, 2024
1 parent 9f8f30b commit 7dc7e85
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions core/src/zeit/connector/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ def unlock(self, id, locktoken=None):
return locktoken

def locked(self, id):
if id not in self._data:
raise KeyError(id)
id = self._get_cannonical_id(id)
return self._locked.get(id, (None, None, False))

Expand Down
6 changes: 3 additions & 3 deletions core/src/zeit/connector/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,14 @@ def lock(self, id, principal, until):
case LockStatus.NO_LOCK:
return self._add_lock(id, principal, until)
case LockStatus.OWN_LOCK:
raise LockingError(id, 'You already own the lock of %s.', id)
raise LockingError(id, f'You already own the lock of {id}.')
case LockStatus.OTHERS_LOCK:
raise LockingError(id, '%s is already locked.', id)
raise LockingError(id, f'{id} is already locked.')

def unlock(self, id, locktoken=None):
path = self.session.get(Path, self._pathkey(id))
if path is None:
return
raise KeyError(f'The resource {id} does not exist.')
lock = self.session.get(Lock, (path.parent_path, path.name, path.id))
# XXX is this the stored locktoken in connector or what does the test mean?
if lock and locktoken is None:
Expand Down
3 changes: 2 additions & 1 deletion core/src/zeit/connector/tests/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def test_query_lock_status_for_non_existent_resource(self):
)

def test_unlocking_non_existent_resource(self):
self.assertIsNone(self.connector.unlock('http://xml.zeit.de/nonexistent'), None)
with self.assertRaises(KeyError):
self.connector.unlock('http://xml.zeit.de/nonexistent')

def test_locking_non_existent_resource(self):
token = self.connector.lock(
Expand Down

0 comments on commit 7dc7e85

Please sign in to comment.