Skip to content

Commit

Permalink
Add boolean for new announcement
Browse files Browse the repository at this point in the history
  • Loading branch information
shrivaths16 committed Oct 17, 2023
1 parent 4cb0c6a commit 3323115
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 12 additions & 6 deletions sleap/gui/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,28 @@ def previous_announcement_date(self):
_previous_announcement_date = self.app.state["announcement last seen date"]
return _previous_announcement_date

def _read_bulletin_data(self) -> Dict[str, str]:
def _read_bulletin_data(self):
"""Reads the bulletin data from the JSON file."""
try:
with open(self.bulletin_json_path, "r") as jsf:
data = json.load(jsf)
return data[0]
self._latest_data = data[0]
except FileNotFoundError:
return {}
self._latest_data = {}

def get_latest_announcement(self) -> Optional[Tuple[str, str]]:
"""Return latest announcements on the releases page not seen by user."""
self._latest_data = self._read_bulletin_data()
@property
def new_announcement(self) -> bool:
self._read_bulletin_data()
if (
self._latest_data
and self._latest_data["date"] != self.previous_announcement_date
):
return True
return False

def get_latest_announcement(self) -> Optional[Tuple[str, str]]:
"""Return latest announcements on the releases page not seen by user."""
if self.new_announcement:
return (self._latest_data["date"], self._latest_data["content"])
return None

Expand Down
7 changes: 3 additions & 4 deletions tests/gui/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,18 @@ def test_announcementchecker():

# Create dummy JSON file to check
bulletin_data = [
{"title": "title1", "date": "10/11/2023", "content": "New announcement"},
{"title": "title1", "date": "10/12/2023", "content": "New announcement"},
{"title": "title2", "date": "10/07/2023", "content": "Old Announcment"},
]
with open(BULLETIN_JSON_PATH, "w") as test_file:
json.dump(bulletin_data, test_file)
assert checker._read_bulletin_data() == bulletin_data[0]

# Check if latest announcement is fetched
announcement = checker.get_latest_announcement()
assert announcement == ("10/11/2023", "New announcement")
assert announcement == ("10/12/2023", "New announcement")

checker.update_announcement()
assert app.state["announcement last seen date"] == "10/11/2023"
assert app.state["announcement last seen date"] == "10/12/2023"
assert app.state["announcement"] == "New announcement"

# Delete the JSON file
Expand Down

0 comments on commit 3323115

Please sign in to comment.