Coverage for portality / events / consumers / article_ris_generator.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-04 09:41 +0100

1# ~~ AccountCreatedEmail:Consumer ~~ 

2from portality.bll import DOAJ 

3from portality.events.consumer import EventConsumer 

4from portality import constants, models 

5 

6 

7class ArticleRISGenerator(EventConsumer): 

8 ID = "article:ris_generator" 

9 

10 @classmethod 

11 def should_consume(cls, event): 

12 return event.id == constants.EVENT_ARTICLE_SAVE and event.context.get("article") is not None 

13 

14 @classmethod 

15 def consume(cls, event): 

16 context = event.context 

17 

18 if "article" not in context: 

19 raise Exception("No article found in event context") 

20 

21 # this could raise an exception, which will cause the event not be be consumed, and will be 

22 # caught and logged at the level above 

23 article = models.Article(**context.get("article")) 

24 

25 exportSvc = DOAJ.exportService() 

26 exportSvc.ris(article, save=True)