Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doajtest/fixtures/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def make_article_with_data(title=None, publisher_name=None, abstract=None, count
"language": ["EN", "FR"],
"country": "US"
},
"year": "1991",
"year": "2015",
"month": "January",
"start_page": "3",
"end_page": "21",
Expand Down
29 changes: 27 additions & 2 deletions doajtest/testbook/article_xml_upload/article_doaj_xml_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ tests:
- status is "complete"
- Outcome Status is "fail"



- title: Check Outcome Status of "Successfully upload a file containing a new article"
context:
role: admin
Expand All @@ -357,3 +355,30 @@ tests:
- Related background job is found
- status is "complete"
- Outcome Status is "success"

- title: Upload a file before OA start date of the Journal
context:
role: publisher
steps:
- step: Ensure that the publisher account owns a journal with Print ISSN "1111-1111"
and E-ISSN "2222-2222", and these are not attached to any other journals and
that this journal does not contain "Success" or "Update" articles from previous
tests. You can use the testdrive endpoint "publisher_with_journal" to create this
path: /testdrive/publisher_with_journal
- step: Update the Journal (if needed) to ensure the OA start date is as late as possible (the current year is the latest you
can set it to)
- step: Go to the "Upload Article XML" tab in the "Publisher Area"
- step: Select "Choose file" and select the test resource file "successful.xml"
resource: /xml_upload_test_package/DOAJ/successful.xml
- step: Click "Upload"
results:
- 'A flash message appears at the top of the screen indicating a successful upload:
File uploaded and waiting to be processed. Check back here for updates.(Dismiss)'
- Your file is shown in the "History of uploads" with status "pending"
- step: wait a short amount of time for the job to process, then reload the page
(do not re-submit the form data). If the job remains in "pending", reload the
page until the status changes.
results:
- Your file is shown in the "History of uploads" with status "processing failed"
and a entry in the "Notes" and reads as 'One or more rticles cannot be uploaded, as they have a publication date before the 'OA start date' of the Journal'. Check that the explanation link goes to
a suitable reason and resolution for the problem.
2 changes: 1 addition & 1 deletion doajtest/unit/resources/articles_metadata_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def update_article_doi(self, valid):
'abstract': 'This abstract has been edited',
'keywords': 'edited-1,edited-2, edited-3',
'publication_month': '10',
'publication_year': '1987',
'publication_year': '2013',
#'pissn': '1234-5678',
#'eissn': '9876-5432',
'volume': '1',
Expand Down
10 changes: 5 additions & 5 deletions doajtest/unit/resources/harvester_resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"journalIssueId": 111111,
"dateOfPublication": "2010 Apr",
"monthOfPublication": 1,
"yearOfPublication": 2010,
"yearOfPublication": 2013,
"printPublicationDate": "2010-01-01",
"journal": {
"title": "My Journal",
Expand All @@ -51,7 +51,7 @@
"nlmid": "123456789"
}
},
"pubYear": "2010",
"pubYear": "2013",
"pageInfo": "1",
"affiliation": "aga@cottagelabs.com",
"publicationStatus": "publish",
Expand Down Expand Up @@ -136,9 +136,9 @@
"issue": "1",
"volume": "1",
"journalIssueId": 111111,
"dateOfPublication": "2010 Apr",
"dateOfPublication": "2013 Apr",
"monthOfPublication": 1,
"yearOfPublication": 2010,
"yearOfPublication": 2013,
"printPublicationDate": "2010-01-01",
"journal": {
"title": "My Journal",
Expand All @@ -149,7 +149,7 @@
"nlmid": "123456789"
}
},
"pubYear": "2010",
"pubYear": "2013",
"pageInfo": "1",
"affiliation": "aga@cottagelabs.com",
"publicationStatus": "publish",
Expand Down
2 changes: 1 addition & 1 deletion doajtest/unit/test_crosswalks_article_ris.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_article2ris(self):
TY - JOUR
T1 - Article Title
AU - The Author
PY - 1991
PY - 2015
JF - The Title
PB - The Publisher
VL - 1
Expand Down
75 changes: 74 additions & 1 deletion doajtest/unit/test_tasks_ingestDOAJarticles.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the whole test suite and got a number of failures, not related to this file, I think there's a general problem with the fixtures for some of the tests:

FAILED test_bll_article_batch_create_article.py::TestBLLArticleBatchCreateArticle::test_01_batch_create_article_033_34 - portality.bll.exceptions.ArticleNotAcceptable: Article(s) 'Article Title' cannot be uploaded before OA start date of the Journal
FAILED test_bll_article_batch_create_article.py::TestBLLArticleBatchCreateArticle::test_01_batch_create_article_089_90 - portality.bll.exceptions.ArticleNotAcceptable: Article(s) 'Article Title' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_02_create_article_success - portality.api.common.Api400Error: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_08_update_article_success - portality.api.common.Api400Error: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_09_update_article_fail - portality.api.common.Api400Error: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_10_delete_article_success - portality.api.common.Api400Error: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_11_delete_article_fail - portality.api.common.Api400Error: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_12_too_many_keywords - portality.api.common.Api400Error: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_bulk_article_class.py::TestBulkArticle::test_01_create_articles_success - portality.api.common.Api400Error: Article(s) 'Article Title' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_14_test_via_endpoint - assert 400 == 201
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_15_no_redirects - assert 400 == 201
FAILED api_tests/test_api_bulk_article_class.py::TestBulkArticle::test_04_delete_article_success - portality.api.common.Api400Error: Article(s) 'Article Title' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_bulk_article_class.py::TestBulkArticle::test_05_delete_articles_fail - portality.api.common.Api400Error: Article(s) 'Article Title' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_article.py::TestCrudArticle::test_16_no_redirects - assert 400 == 201
FAILED test_bll_article_create_article.py::TestBLLArticleCreateArticle::test_01_create_article_0_1 - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_bll_article_create_article.py::TestBLLArticleCreateArticle::test_01_create_article_2_3 - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_bulk_article_class.py::TestBulkArticle::test_06_test_via_endpoint - TimeoutError: fail to meet the condition within the timeout period.
FAILED test_bll_article_create_article.py::TestBLLArticleCreateArticle::test_01_create_article_8_9 - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED application_processors/test_application_processor_emails.py::TestUpdateRequestReviewEmails::test_01_maned_review_emails - assert 1 == 3
FAILED api_tests/test_api_bulk_article_class.py::TestBulkArticle::test_07_v1_no_redirects - TimeoutError: fail to meet the condition within the timeout period.
FAILED test_paths.py::TestPaths::test_get_project_root - AssertionError: assert 'doaj3' == 'doaj'
FAILED test_create_article.py::TestCreateOrUpdateArticle::test_00_no_doi_and_url_changed - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_bulk_article_class.py::TestBulkArticle::test_08_v2_no_redirects - TimeoutError: fail to meet the condition within the timeout period.
FAILED test_update_article.py::TestCreateOrUpdateArticle::test_00_no_doi_and_url_changed - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_create_article.py::TestCreateOrUpdateArticle::test_01_new_doi_new_url - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_update_article.py::TestCreateOrUpdateArticle::test_01_new_doi_new_url - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_create_article.py::TestCreateOrUpdateArticle::test_04_old_doi_new_url - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_update_article.py::TestCreateOrUpdateArticle::test_04_old_doi_new_url - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_create_article.py::TestCreateOrUpdateArticle::test_05_new_doi_old_url - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_update_article.py::TestCreateOrUpdateArticle::test_05_new_doi_old_url - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_admin_edit_metadata.py::TestAdminEditMetadata::test_02_update_article_metadata_no_url_fulltext - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_admin_edit_metadata.py::TestAdminEditMetadata::test_03_update_fulltext_valid - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED test_admin_edit_metadata.py::TestAdminEditMetadata::test_05_update_doi_valid - portality.bll.exceptions.ArticleBeforeOAStartDate: Article(s) '{title}' cannot be uploaded before OA start date of the Journal
FAILED api_tests/test_api_crud_returnvalues.py::TestCrudReturnValues::test_03_articles_crud - AssertionError: 400
FAILED event_consumers/test_update_request_publisher_accepted_notify.py::TestUpdateRequestPublisherAcceptedNotify::test_should_consume - assert False
FAILED event_consumers/test_update_request_publisher_assigned_notify.py::TestApplicationPublisherAssignedNotify::test_should_consume - assert False
FAILED event_consumers/test_update_request_publisher_rejected_notify.py::TestUpdateRequestPublisherRejectedNotify::test_should_consume - assert False
FAILED event_consumers/test_update_request_publisher_submitted_notify.py::TestUpdateRequestPublisherSubmittedNotify::test_should_consume - AssertionError: assert False
FAILED test_tasks_harvest.py::TestHarvester::test_harvest - TimeoutError: fail to meet the condition within the timeout period.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from portality.crosswalks import article_doaj_xml
from portality.tasks import ingestarticles
from portality.ui.messages import Messages

from portality.lib import dates

class TestIngestArticlesDoajXML(DoajTestCase):

Expand Down Expand Up @@ -1048,3 +1048,76 @@ def test_61_journal_not_indoaj(self):

assert file_upload.status == "failed"
assert file_upload.error == Messages.EXCEPTION_ADDING_ARTICLE_TO_WITHDRAWN_JOURNAL

def test_62_article_before_oa_start(self):
journal = article_upload_tester.create_simple_journal("testowner", pissn="1234-5678", eissn="9876-5432")
journal.bibjson().oa_start = dates.now().year
helpers.save_all_block_last([ journal,
article_upload_tester.create_simple_publisher("testowner")
])

# make both handles, as we want as little gap as possible between requests in a moment
handle1 = DoajXmlArticleFixtureFactory.upload_2_issns_correct()

f1 = FileMockFactory(stream=handle1)

job1 = ingestarticles.IngestArticlesBackgroundTask.prepare("testowner", schema="doaj", upload_file=f1)
id1 = job1.params.get("ingest_articles__file_upload_id")
self.cleanup_ids.append(id1)

# because file upload gets created and saved by prepare
time.sleep(1)

task1 = ingestarticles.IngestArticlesBackgroundTask(job1)

task1.run()

# because file upload needs to be re-saved
time.sleep(1)

fu1 = models.FileUpload.pull(id1)

assert fu1.status == "failed", "received status: {}".format(fu1.status)
assert job1.outcome_status == "fail"

assert any('Articles before OA start date: Imaginaires autochtones contemporains. Introduction' in entry['message'] for entry in
job1.audit), "No message found with 'Articles before OA start date'"

# check that article not created
assert models.Article.count_by_issns(["1234-5678", "9876-5432"]) == 0

def test_63_article_after_oa_start(self):
journal = article_upload_tester.create_simple_journal("testowner", pissn="1234-5678", eissn="9876-5432")
journal.bibjson().oa_start = 2013
helpers.save_all_block_last([ journal,
article_upload_tester.create_simple_publisher("testowner")
])

# make both handles, as we want as little gap as possible between requests in a moment
handle1 = DoajXmlArticleFixtureFactory.upload_2_issns_correct()

f1 = FileMockFactory(stream=handle1)

job1 = ingestarticles.IngestArticlesBackgroundTask.prepare("testowner", schema="doaj", upload_file=f1)
id1 = job1.params.get("ingest_articles__file_upload_id")
self.cleanup_ids.append(id1)

# because file upload gets created and saved by prepare
time.sleep(1)

task1 = ingestarticles.IngestArticlesBackgroundTask(job1)

task1.run()

# because file upload needs to be re-saved
time.sleep(1)

fu1 = models.FileUpload.pull(id1)

assert fu1.status == "processed", "received status: {}".format(fu1.status)

assert not any('Articles before OA start date: Imaginaires autochtones contemporains. Introduction' in entry['message'] for entry in
job1.audit), "No message found with 'Articles before OA start date'"

# check that article not created
assert models.Article.count_by_issns(["1234-5678", "9876-5432"]) == 1
4 changes: 2 additions & 2 deletions doajtest/unit/test_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def test_02_toc_requirements(self):
# To build ToCs we need a volume, an issue, a year and a month.
assert a.data['bibjson']['journal']['volume'] == '1'
assert a.data['bibjson']['journal']['number'] == '99'
assert a.data['index']['date'] == "1991-01-01T00:00:00Z"
assert a.data['index']['date_toc_fv_month'] == a.data['index']['date'] == "1991-01-01T00:00:00Z"
assert a.data['index']['date'] == "2015-01-01T00:00:00Z"
assert a.data['index']['date_toc_fv_month'] == a.data['index']['date'] == "2015-01-01T00:00:00Z"

def test_03_toc_uses_both_issns_when_available(self):
_test_toc_uses_both_issns_when_available(self.app_test, 'doaj.toc')
Expand Down
4 changes: 2 additions & 2 deletions doajtest/xml_upload_test_package/DOAJ/successful.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<publisher>Codicille éditeur et CRILCQ</publisher>

<journalTitle>Successful</journalTitle>
<issn>1111-1111</issn>
<eissn>2222-2222</eissn>
<issn>2222-2222</issn>
<eissn>1111-1111</eissn>

<publicationDate>2013</publicationDate>
<volume/>
Expand Down
6 changes: 6 additions & 0 deletions portality/bll/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def __str__(self):
super(ArticleNotAcceptable, self).__str__()
return self.message

class ArticleBeforeOAStartDate(ArticleNotAcceptable):
"""
Exception to raise when the article is uploaded before OA start date of the Journal
"""
pass

class ArticleMergeConflict(Exception):
"""
Exception to raise when it's not clear which article to merge an update with
Expand Down
15 changes: 13 additions & 2 deletions portality/bll/services/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def batch_create_articles(self, articles, account, duplicate_check=True, merge_d
all_shared = set()
all_unowned = set()
all_unmatched = set()
all_before_oa_start_date = set()

# Hold on to the exception so we can raise it later
e_not_acceptable = None
Expand All @@ -70,6 +71,9 @@ def batch_create_articles(self, articles, account, duplicate_check=True, merge_d
dry_run=True)
except (exceptions.ArticleMergeConflict, exceptions.ConfigurationException):
raise exceptions.IngestException(message=Messages.EXCEPTION_ARTICLE_BATCH_CONFLICT)
except exceptions.ArticleBeforeOAStartDate as e:
result = {'fail': 1}
e_not_acceptable = e
except exceptions.ArticleNotAcceptable as e:
# The ArticleNotAcceptable exception is a superset of reasons we can't match a journal to this article
e_not_acceptable = e
Expand All @@ -84,7 +88,7 @@ def batch_create_articles(self, articles, account, duplicate_check=True, merge_d
all_unmatched.update(result.get("unmatched", set()))

report = {"success": success, "fail": fail, "update": update, "new": new, "shared": all_shared,
"unowned": all_unowned, "unmatched": all_unmatched}
"unowned": all_unowned, "unmatched": all_unmatched, "before_oa_start_date":all_before_oa_start_date}

# if there were no failures in the batch, then we can do the save
if fail == 0:
Expand Down Expand Up @@ -235,8 +239,15 @@ def create_article(self, article, account, duplicate_check=True, merge_duplicate
except (exceptions.DuplicateArticleException, exceptions.ArticleMergeConflict, exceptions.ConfigurationException) as e:
raise e

# Check if article is uploaded before OA start date of Journal and reject the article
journal = article.get_journal()
published_year = int(article.bibjson().year)
oa_start_date = journal.has_oa_start_date()
if oa_start_date and published_year < oa_start_date:
raise exceptions.ArticleBeforeOAStartDate(message=Messages.EXCEPTION_ARTICLE_BEFORE_OA_START_DATE)

if add_journal_info:
article.add_journal_metadata()
article.add_journal_metadata(j=journal)

# finally, save the new article
if not dry_run:
Expand Down
Loading