Coverage for portality/events/consumers/application_editor_group_assigned_notify.py: 97%

32 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-08-04 15:38 +0100

1# from flask import url_for 

2from portality.util import url_for 

3 

4from portality.events.consumer import EventConsumer 

5from portality import constants 

6from portality import models 

7from portality.bll import DOAJ 

8from portality.bll import exceptions 

9 

10 

11class ApplicationEditorGroupAssignedNotify(EventConsumer): 

12 ID = "application:editor_group:assigned:notify" 

13 

14 @classmethod 

15 def consumes(cls, event): 

16 return event.id == constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED and \ 

17 event.context.get("application") is not None 

18 

19 @classmethod 

20 def consume(cls, event): 

21 app_source = event.context.get("application") 

22 

23 try: 

24 application = models.Application(**app_source) 

25 except Exception as e: 

26 raise exceptions.NoSuchObjectException("Unable to construct Application from supplied source - data structure validation error, {x}".format(x=e)) 

27 

28 if not application.editor_group: 

29 return 

30 

31 editor_group = models.EditorGroup.pull_by_key("name", application.editor_group) 

32 

33 if not editor_group.editor: 

34 raise exceptions.NoSuchPropertyException("Editor Group {x} does not have property `editor`".format(x=editor_group.id)) 

35 

36 svc = DOAJ.notificationsService() 

37 

38 notification = models.Notification() 

39 notification.who = editor_group.editor 

40 notification.created_by = cls.ID 

41 notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN 

42 

43 notification.long = svc.long_notification(cls.ID).format( 

44 journal_name=application.bibjson().title 

45 ) 

46 notification.short = svc.short_notification(cls.ID) 

47 

48 notification.action = url_for("editor.application", application_id=application.id) 

49 

50 svc.notify(notification)