Coverage for apps/comments_views/journal/utils.py: 93%

12 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-19 19:20 +0000

1from django.http import HttpRequest 

2 

3SESSION_PENDING_COMMENT = "pending_comment" 

4 

5 

6def pending_comment_session_key(doi: str) -> str: 

7 """ 

8 Returns the session key for a pending comment. 

9 There can be max. one pending comment per session per DOI. 

10 """ 

11 return f"{SESSION_PENDING_COMMENT}_{doi}" 

12 

13 

14def add_pending_comment(request: HttpRequest, doi: str, comment: dict): 

15 """Stores a comment in the current session.""" 

16 request.session[pending_comment_session_key(doi)] = comment 

17 

18 

19def get_pending_comment(request: HttpRequest, doi: str) -> dict | None: 

20 """ 

21 Retrieves the pending comment associated to the given DOI from the session, if any. 

22 """ 

23 return request.session.get(pending_comment_session_key(doi)) 

24 

25 

26def delete_pending_comment(request: HttpRequest, doi: str): 

27 """Removes the pending comment associated to the given DOI stored in the session.""" 

28 session_key = pending_comment_session_key(doi) 

29 if session_key in request.session: 29 ↛ exitline 29 didn't return from function 'delete_pending_comment', because the condition on line 29 was never false

30 del request.session[session_key]