def test_template_get_email_headers_00013(self, fake_download_email_templates_from_s3): fake_download_email_templates_from_s3 = self.fake_download_email_templates_from_s3( self.activity.get_tmp_dir(), True) email_type = "author_publication_email_VOR_no_POA" authors = self.fake_authors(13) article_object = article() article_object.parse_article_file("tests/test_data/elife00013.xml") article_type = article_object.article_type feature_article = False related_insight_article = None recipient_authors = self.activity.choose_recipient_authors(authors, article_type, feature_article, related_insight_article) author = recipient_authors[2] format = "html" expected_headers = {'format': 'html', u'email_type': u'author_publication_email_VOR_no_POA', u'sender_email': u'*****@*****.**', u'subject': u'Author\xe9, Your eLife paper is now online'} body = self.activity.templates.get_email_headers( email_type=email_type, author=author, article=article_object, format=format) self.assertEqual(body, expected_headers)
def __init__(self, settings, logger, conn=None, token=None, activity_task=None): activity.activity.__init__(self, settings, logger, conn, token, activity_task) self.name = "LensArticle" self.version = "1" self.default_task_heartbeat_timeout = 30 self.default_task_schedule_to_close_timeout = 60 * 5 self.default_task_schedule_to_start_timeout = 30 self.default_task_start_to_close_timeout = 60 * 5 self.description = "Create a lens article index.html page for the particular article." # Create the filesystem provider self.fs = fslib.Filesystem(self.get_tmp_dir()) # Templates provider self.templates = templatelib.Templates(settings, self.get_tmp_dir()) # article data provider self.article = articlelib.article(settings, self.get_tmp_dir()) # Default templates directory self.from_dir = "template" # CDN bucket self.cdn_bucket = settings.publishing_buckets_prefix + settings.ppp_cdn_bucket self.article_xml_filename = None self.article_s3key = None self.article_html = None
def test_template_get_email_body_00353( self, fake_download_email_templates_from_s3): fake_download_email_templates_from_s3 = self.fake_download_email_templates_from_s3( self.activity.get_tmp_dir(), True) email_type = "author_publication_email_Feature" authors = self.fake_authors() article_object = article() article_object.parse_article_file("tests/test_data/elife-00353-v1.xml") article_type = article_object.article_type feature_article = True related_insight_article = None recipient_authors = self.activity.choose_recipient_authors( authors, article_type, feature_article, related_insight_article) author = recipient_authors[0] format = "html" expected_body = 'Header\n<p>Dear Features</p>\n"A good life"\n<a href="https://doi.org/10.7554/eLife.00353">read it</a>\n<a href="http://twitter.com/intent/tweet?text=https%3A%2F%2Fdoi.org%2F10.7554%2FeLife.00353+%40eLife">social media</a>\n<a href="https://lens.elifesciences.org/00353">online viewer</a>\n\[email protected]\n\[email protected]\n\[email protected]\n' body = self.activity.templates.get_email_body(email_type=email_type, author=author, article=article_object, authors=authors, format=format) self.assertEqual(body, expected_body)
def __init__(self, settings, logger, conn=None, token=None, activity_task=None): activity.activity.__init__(self, settings, logger, conn, token, activity_task) self.name = "LensArticle" self.version = "1" self.default_task_heartbeat_timeout = 30 self.default_task_schedule_to_close_timeout = 60 * 5 self.default_task_schedule_to_start_timeout = 30 self.default_task_start_to_close_timeout = 60 * 5 self.description = "Create a lens article index.html page for the particular article." # Create the filesystem provider self.fs = fslib.Filesystem(self.get_tmp_dir()) # Templates provider self.templates = templatelib.Templates(settings, self.get_tmp_dir()) # article data provider self.article = articlelib.article(settings, self.get_tmp_dir()) # Default templates directory self.from_dir = "template" # CDN bucket self.cdn_bucket = settings.publishing_buckets_prefix + settings.ppp_cdn_bucket
def test_template_get_email_body_00353(self, fake_download_email_templates_from_s3): fake_download_email_templates_from_s3 = self.fake_download_email_templates_from_s3( self.activity.get_tmp_dir(), True) email_type = "author_publication_email_Feature" authors = self.fake_authors() article_object = article() article_object.parse_article_file("tests/test_data/elife-00353-v1.xml") article_type = article_object.article_type feature_article = True related_insight_article = None recipient_authors = self.activity.choose_recipient_authors(authors, article_type, feature_article, related_insight_article) author = recipient_authors[0] format = "html" expected_body = 'Header\n<p>Dear Features</p>\n"A good life"\n<a href="http://dx.doi.org/10.7554/eLife.00353">read it</a>\n<a href="http://twitter.com/intent/tweet?text=http%3A%2F%2Fdx.doi.org%2F10.7554%2FeLife.00353+%40eLife">social media</a>\n<a href="http://lens.elifesciences.org/00353">online viewer</a>\n\[email protected]\n\[email protected]\n\[email protected]\n' body = self.activity.templates.get_email_body( email_type=email_type, author=author, article=article_object, authors=authors, format=format) self.assertEqual(body, expected_body)
def __init__(self, settings, logger, conn=None, token=None, activity_task=None): activity.activity.__init__(self, settings, logger, conn, token, activity_task) self.name = "DepositCrossref" self.version = "1" self.default_task_heartbeat_timeout = 30 self.default_task_schedule_to_close_timeout = 60 * 30 self.default_task_schedule_to_start_timeout = 30 self.default_task_start_to_close_timeout = 60 * 15 self.description = ( "Download article XML from crossref outbox, " + "generate crossref XML, and deposit with crossref.") # Directory where POA library is stored self.poa_lib_dir_name = "elife-poa-xml-generation" # Where we specify the library to be imported self.elife_poa_lib = None # Import the libraries we will need self.import_imports() # Create output directories self.create_activity_directories() self.date_stamp = self.set_datestamp() # Data provider where email body is saved self.db = dblib.SimpleDB(settings) # Instantiate a new article object to provide some helper functions self.article = articlelib.article(self.settings, self.get_tmp_dir()) # Bucket for outgoing files self.publish_bucket = settings.poa_packaging_bucket self.outbox_folder = "crossref/outbox/" self.published_folder = "crossref/published/" # Track the success of some steps self.activity_status = None self.generate_status = None self.approve_status = None self.outbox_status = None self.publish_status = None # HTTP requests status self.http_request_status_code = [] self.http_request_status_text = [] self.outbox_s3_key_names = None # Track XML files selected for pubmed XML self.article_published_file_names = [] self.article_not_published_file_names = []
def __init__(self, settings, logger, conn=None, token=None, activity_task=None): activity.activity.__init__(self, settings, logger, conn, token, activity_task) self.name = "PubRouterDeposit" self.version = "1" self.default_task_heartbeat_timeout = 30 self.default_task_schedule_to_close_timeout = 60 * 30 self.default_task_schedule_to_start_timeout = 30 self.default_task_start_to_close_timeout = 60 * 15 self.description = ("Download article XML from pub_router outbox, \ approve each for publication, and deposit files via FTP to pub router.") # Create output directories self.date_stamp = self.set_datestamp() # Data provider where email body is saved self.db = dblib.SimpleDB(settings) # Instantiate a new article object to provide some helper functions self.article = articlelib.article(self.settings, self.get_tmp_dir()) # Bucket for outgoing files self.publish_bucket = settings.poa_packaging_bucket self.outbox_folder = None self.published_folder = None # Bucket settings for source files of FTPArticle workflows self.pmc_zip_bucket = settings.poa_packaging_bucket self.pmc_zip_folder = "pmc/zip/" # Bucket settings for source files of PMCDeposit workflows self.archive_bucket = self.settings.publishing_buckets_prefix + self.settings.archive_bucket # Track the success of some steps self.activity_status = None self.ftp_status = None self.outbox_status = None self.publish_status = None self.outbox_s3_key_names = None # Type of FTPArticle workflow to start, will be specified in data self.workflow = None # Track XML files selected self.article_xml_filenames = [] self.xml_file_to_doi_map = {} self.articles = [] #self.article_published_file_names = [] #self.article_not_published_file_names = [] self.admin_email_content = '' # journal self.journal = 'elife'
def __init__(self, settings, logger, conn=None, token=None, activity_task=None): activity.activity.__init__(self, settings, logger, conn, token, activity_task) self.name = "DepositCrossref" self.version = "1" self.default_task_heartbeat_timeout = 30 self.default_task_schedule_to_close_timeout = 60 * 30 self.default_task_schedule_to_start_timeout = 30 self.default_task_start_to_close_timeout = 60 * 15 self.description = ("Download article XML from crossref outbox, " + "generate crossref XML, and deposit with crossref.") # Directory where POA library is stored self.poa_lib_dir_name = "elife-poa-xml-generation" # Where we specify the library to be imported self.elife_poa_lib = None # Import the libraries we will need self.import_imports() # Create output directories self.create_activity_directories() self.date_stamp = self.set_datestamp() # Data provider where email body is saved self.db = dblib.SimpleDB(settings) # Instantiate a new article object to provide some helper functions self.article = articlelib.article(self.settings, self.get_tmp_dir()) # Bucket for outgoing files self.publish_bucket = settings.poa_packaging_bucket self.outbox_folder = "crossref/outbox/" self.published_folder = "crossref/published/" # Track the success of some steps self.activity_status = None self.generate_status = None self.approve_status = None self.outbox_status = None self.publish_status = None # HTTP requests status self.http_request_status_code = [] self.http_request_status_text = [] self.outbox_s3_key_names = None # Track XML files selected for pubmed XML self.article_published_file_names = [] self.article_not_published_file_names = []
def i_create_an_article_provider(step): try: world.settings = world.settings except AttributeError: world.settings = None try: world.tmp_dir = world.tmp_dir except AttributeError: world.tmp_dir = None world.article = articlelib.article(world.settings, world.tmp_dir) assert world.article is not None, \ "Got article %s" % world.article
def do_activity(self, data): try: article_id = data['article_id'] version = data['version'] run = data['run'] except Exception as e: self.logger.error("Error retrieving basic article data. Data: %s, Exception: %s" % (str(data), str(e))) return activity.activity.ACTIVITY_PERMANENT_FAILURE try: self.emit_monitor_event(self.settings, article_id, version, run, self.pretty_name, "start", "Starting check for generation of pdf cover.") article = articlelib.article() if not (hasattr(self.settings, "pdf_cover_generator")) or \ (hasattr(self.settings, "pdf_cover_generator") and self.settings.pdf_cover_generator == None) or \ (hasattr(self.settings, "pdf_cover_generator") and len(self.settings.pdf_cover_generator) < 1): self.emit_monitor_event(self.settings, article_id, version, run, self.pretty_name, "start", "pdf_cover_generator variable is missing from " "settings file. PDF not generated but flag is set " "for the activity to succeed.") return activity.activity.ACTIVITY_SUCCESS pdf_cover = article.get_pdf_cover_link(self.settings.pdf_cover_generator, article_id, self.logger) assert "a4" in pdf_cover and "letter" in pdf_cover and len(pdf_cover["a4"]) > 1 \ and len(pdf_cover["letter"]) > 1, "Unexpected result from pdf covers API." dashboard_message = ("Finished check for generation of pdf cover. S3 url for a4: %s; " "S3 url for letter %s.") % (pdf_cover["a4"], pdf_cover["letter"]) self.emit_monitor_event(self.settings, article_id, version, run, self.pretty_name, "end", dashboard_message) return activity.activity.ACTIVITY_SUCCESS except AssertionError as err: error_message = str(err) self.logger.error(error_message) self.emit_monitor_event(self.settings, article_id, version, run, self.pretty_name, "error", error_message) return activity.activity.ACTIVITY_PERMANENT_FAILURE except Exception as e: error_message = str(e) self.logger.error(error_message) self.emit_monitor_event(self.settings, article_id, version, run, self.pretty_name, "error", error_message) return activity.activity.ACTIVITY_PERMANENT_FAILURE
def create_article(self, doi_id = None): """ Instantiate an article object and optionally populate it with data for the doi_id (int) supplied """ # Instantiate a new article object article = articlelib.article(self.settings, self.get_tmp_dir()) if doi_id: # Get and parse the article XML for data # Convert the doi_id to 5 digit string in case it was an integer if type(doi_id) == int: doi_id = str(doi_id).zfill(5) article_xml_filename = article.download_article_xml_from_s3(doi_id) article.parse_article_file(self.get_tmp_dir() + os.sep + article_xml_filename) return article
def test_do_activity(self, fake_clean_tmp_dir, fake_elife_add_email_to_email_queue, fake_find_latest_s3_file_name, fake_ejp_get_s3key, fake_check_is_article_published_by_lax, fake_article_get_folder_names_from_bucket, fake_download_email_templates_from_s3, fake_download_files_from_s3_outbox, mock_lax_provider_article_versions): directory = TempDirectory() fake_clean_tmp_dir = self.fake_clean_tmp_dir() # Prime the related article property for when needed related_article = article() related_article.parse_article_file( "tests/test_data/elife-15747-v2.xml") self.activity.related_articles = [related_article] # Basic fake data for all activity passes fake_article_get_folder_names_from_bucket.return_value = self.fake_article_get_folder_names_from_bucket( ) fake_check_is_article_published_by_lax.return_value = True fake_ejp_get_s3key.return_value = self.fake_ejp_get_s3key( directory, self.activity.get_tmp_dir(), "authors.csv", "tests/test_data/ejp_author_file.csv") fake_find_latest_s3_file_name.return_value = mock.MagicMock() fake_elife_add_email_to_email_queue.return_value = mock.MagicMock() mock_lax_provider_article_versions.return_value = 200, [] # do_activity for test_data in self.do_activity_passes: fake_download_email_templates_from_s3 = self.fake_download_email_templates_from_s3( self.activity.get_tmp_dir(), test_data["templates_warmed"]) fake_download_files_from_s3_outbox.return_value = self.fake_download_files_from_s3_outbox( test_data["article_xml_filenames"], self.activity.get_tmp_dir()) success = self.activity.do_activity(test_data["input_data"]) self.assertEqual(True, test_data["activity_success"]) self.assertEqual(len(self.activity.articles_approved), test_data["articles_approved_len"]) self.assertEqual(len(self.activity.articles_approved_prepared), test_data["articles_approved_prepared_len"])
def create_article(self, doi_id=None): """ Instantiate an article object and optionally populate it with data for the doi_id (int) supplied """ # Instantiate a new article object article = articlelib.article(self.settings, self.get_tmp_dir()) if doi_id: # Get and parse the article XML for data # Convert the doi_id to 5 digit string in case it was an integer if type(doi_id) == int: doi_id = str(doi_id).zfill(5) article_xml_filename = article.download_article_xml_from_s3(doi_id) article.parse_article_file(self.get_tmp_dir() + os.sep + article_xml_filename) return article
def __init__(self, settings, logger, conn = None, token = None, activity_task = None): activity.activity.__init__(self, settings, logger, conn, token, activity_task) self.name = "LensArticle" self.version = "1" self.default_task_heartbeat_timeout = 30 self.default_task_schedule_to_close_timeout = 60*5 self.default_task_schedule_to_start_timeout = 30 self.default_task_start_to_close_timeout= 60*5 self.description = "Create a lens article index.html page for the particular article." # Templates provider self.templates = templatelib.Templates(settings, self.get_tmp_dir()) # article data provider self.article = articlelib.article(settings, self.get_tmp_dir()) # Default templates directory self.from_dir = "template"
def test_do_activity(self, fake_clean_tmp_dir, fake_elife_add_email_to_email_queue, fake_find_latest_s3_file_name, fake_ejp_get_s3key, fake_check_is_article_published_by_lax, fake_article_get_folder_names_from_bucket, fake_download_email_templates_from_s3, fake_download_files_from_s3_outbox): directory = TempDirectory() fake_clean_tmp_dir = self.fake_clean_tmp_dir() # Prime the related article property for when needed related_article = article() related_article.parse_article_file("tests/test_data/elife-15747-v2.xml") self.activity.related_articles = [related_article] # Basic fake data for all activity passes fake_article_get_folder_names_from_bucket.return_value = self.fake_article_get_folder_names_from_bucket() fake_check_is_article_published_by_lax.return_value = True fake_ejp_get_s3key.return_value = self.fake_ejp_get_s3key( directory, self.activity.get_tmp_dir(), "authors.csv", "tests/test_data/ejp_author_file.csv") fake_find_latest_s3_file_name.return_value = mock.MagicMock() fake_elife_add_email_to_email_queue.return_value = mock.MagicMock() # do_activity for test_data in self.do_activity_passes: fake_download_email_templates_from_s3 = self.fake_download_email_templates_from_s3( self.activity.get_tmp_dir(), test_data["templates_warmed"]) fake_download_files_from_s3_outbox.return_value = self.fake_download_files_from_s3_outbox( test_data["article_xml_filenames"], self.activity.get_tmp_dir()) success = self.activity.do_activity(test_data["input_data"]) self.assertEqual(True, test_data["activity_success"]) self.assertEqual(len(self.activity.articles_approved), test_data["articles_approved_len"]) self.assertEqual(len(self.activity.articles_approved_prepared), test_data["articles_approved_prepared_len"])
def test_template_get_email_headers_00013( self, fake_download_email_templates_from_s3): fake_download_email_templates_from_s3 = self.fake_download_email_templates_from_s3( self.activity.get_tmp_dir(), True) email_type = "author_publication_email_VOR_no_POA" authors = self.fake_authors(13) article_object = article() article_object.parse_article_file("tests/test_data/elife00013.xml") article_type = article_object.article_type feature_article = False related_insight_article = None recipient_authors = self.activity.choose_recipient_authors( authors, article_type, feature_article, related_insight_article) author = recipient_authors[2] format = "html" expected_headers = { 'format': 'html', u'email_type': u'author_publication_email_VOR_no_POA', u'sender_email': u'*****@*****.**', u'subject': u'Author\xe9, Your eLife paper is now online' } body = self.activity.templates.get_email_headers( email_type=email_type, author=author, article=article_object, format=format) self.assertEqual(body, expected_headers)
def setUp(self, mock_simpleDB): mock_simpleDB.return_value = None self.articleprovider = article(settings_mock)
def __init__(self, settings, logger, conn=None, token=None, activity_task=None): activity.activity.__init__(self, settings, logger, conn, token, activity_task) self.name = "PubRouterDeposit" self.version = "1" self.default_task_heartbeat_timeout = 30 self.default_task_schedule_to_close_timeout = 60 * 30 self.default_task_schedule_to_start_timeout = 30 self.default_task_start_to_close_timeout = 60 * 15 self.description = ("Download article XML from pub_router outbox, \ approve each for publication, and deposit files via FTP to pub router." ) # Create output directories self.date_stamp = self.set_datestamp() # Data provider where email body is saved self.db = dblib.SimpleDB(settings) # Instantiate a new article object to provide some helper functions self.article = articlelib.article(self.settings, self.get_tmp_dir()) # Bucket for outgoing files self.publish_bucket = settings.poa_packaging_bucket self.outbox_folder = None self.published_folder = None # Bucket settings for source files of FTPArticle workflows self.pmc_zip_bucket = settings.poa_packaging_bucket self.pmc_zip_folder = "pmc/zip/" # Bucket settings for source files of PMCDeposit workflows self.archive_bucket = self.settings.publishing_buckets_prefix + self.settings.archive_bucket # Track the success of some steps self.activity_status = None self.ftp_status = None self.outbox_status = None self.publish_status = None self.outbox_s3_key_names = None # Type of FTPArticle workflow to start, will be specified in data self.workflow = None # Track XML files selected self.article_xml_filenames = [] self.xml_file_to_doi_map = {} self.articles = [] #self.article_published_file_names = [] #self.article_not_published_file_names = [] self.admin_email_content = '' # journal self.journal = 'elife'