Skip to content

Commit

Permalink
fix: Locking an unlocked EncEntry did not update locked status
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler committed Dec 2, 2024
1 parent 031b337 commit 41cda4a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
4 changes: 2 additions & 2 deletions encyclopaedia/encentry_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ def locked(self, new_value: bool) -> None:

# Only run if the entry was locked
if (self._locked is not False) and (new_value is False):
self._locked = new_value

if self.parent is not None:
self.parent._add_entry_to_unlocked_entries(self)
self.parent.emit("entry_unlocked")

self.emit("unlocked")

self._locked = new_value

@property
def viewed(self) -> bool:
"""Determine if the entry has been viewed or not.
Expand Down
22 changes: 0 additions & 22 deletions tests/encentry/test_encentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@ def test_image():
assert e.has_image


def test_unlock_entry():
enc = Encyclopaedia()

e = EncEntry(
parent=enc,
name="Test Name",
text=["Test Text"],
locked=True,

)

assert e in enc.all_entries
assert e not in enc.unlocked_entries

# Unlock the first entry
e.locked = False
assert e.locked is False

assert e in enc.all_entries
assert e in enc.unlocked_entries


def test_add_page():
"""
When an EncEntry has another EncEntry as a parent
Expand Down
43 changes: 43 additions & 0 deletions tests/encentry/test_encentry_locked.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from encyclopaedia import EncEntry, Encyclopaedia


def test_encentry_lock():
"""
When an EncEntry is unlocked
And it's locked
Then the locked status should update
"""
enc = Encyclopaedia()

e = EncEntry(
parent=enc,
name="Test Name",
text=["Test Text"],
locked=False,
)

e.locked = True

assert e.locked is True


def test_encentry_unlock():
enc = Encyclopaedia()

e = EncEntry(
parent=enc,
name="Test Name",
text=["Test Text"],
locked=True,

)

assert e in enc.all_entries
assert e not in enc.unlocked_entries

# Unlock the first entry
e.locked = False
assert e.locked is False

assert e in enc.all_entries
assert e in enc.unlocked_entries

0 comments on commit 41cda4a

Please sign in to comment.