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

33 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-11-09 15:10 +0000

1# from flask import url_for 

2from portality.util import url_for 

3 

4from portality.core import app 

5from portality.events.consumer import EventConsumer 

6from portality import constants 

7from portality import models 

8from portality.bll import DOAJ, exceptions 

9from portality.lib.seamless import SeamlessException 

10from portality.lib.dates import human_date 

11 

12class ApplicationPublisherInprogressNotify(EventConsumer): 

13 ID = "application:publisher:inprogress:notify" 

14 

15 @classmethod 

16 def consumes(cls, event): 

17 return event.id == constants.EVENT_APPLICATION_STATUS and \ 

18 event.context.get("application") is not None and \ 

19 event.context.get("old_status") == constants.APPLICATION_STATUS_PENDING and \ 

20 event.context.get("new_status") == constants.APPLICATION_STATUS_IN_PROGRESS 

21 

22 @classmethod 

23 def consume(cls, event): 

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

25 try: 

26 application = models.Application(**app_source) 

27 except SeamlessException as e: 

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

29 

30 if application.owner is None: 

31 return 

32 

33 svc = DOAJ.notificationsService() 

34 

35 notification = models.Notification() 

36 notification.who = application.owner 

37 notification.created_by = cls.ID 

38 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE 

39 

40 title = application.bibjson().title 

41 date_applied = human_date(application.date_applied) 

42 volunteers = app.config.get("BASE_URL") + url_for("doaj.volunteers") 

43 

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

45 title=title, 

46 date_applied=date_applied, 

47 volunteers=volunteers 

48 ) 

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

50 

51 svc.notify(notification)