-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/2024-11-12_3647ris_3573article_autocheck_3838_n…
…osuchapplication'
- Loading branch information
Showing
29 changed files
with
658 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
} | ||
|
||
SEAL_FORM_EXPANDED = { | ||
"doaj_seal": False, | ||
"doaj_seal": [], | ||
} | ||
|
||
JOURNAL_LIKE_BIBJSON = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import unittest | ||
|
||
from doajtest.fixtures import ArticleFixtureFactory | ||
from portality import models | ||
from portality.crosswalks.article_ris import ArticleRisXWalk | ||
|
||
|
||
class TestArticleRisXWalk(unittest.TestCase): | ||
def test_article2ris(self): | ||
article = ArticleFixtureFactory.make_article_source() | ||
article = models.Article(**article) | ||
article.bibjson().abstract = "abstract" | ||
ris = ArticleRisXWalk.article2ris(article) | ||
assert ris.type == 'JOUR' | ||
assert ris['T1'] == [article.data['bibjson']['title']] | ||
assert ris.to_text().split() == """ | ||
TY - JOUR | ||
T1 - Article Title | ||
AU - The Author | ||
PY - 1991 | ||
JF - The Title | ||
PB - The Publisher | ||
VL - 1 | ||
IS - 99 | ||
SP - 3 | ||
EP - 21 | ||
UR - http://www.example.com/article | ||
AB - abstract | ||
KW - word | ||
KW - key | ||
DO - 10.0000/SOME.IDENTIFIER | ||
LA - EN | ||
LA - FR | ||
ER - | ||
""".split() | ||
|
||
def test_article2ris__only_title(self): | ||
ris = ArticleRisXWalk.article2ris({"bibjson": {"title": "Article Title"}}) | ||
assert ris.to_text().split() == """ | ||
TY - JOUR | ||
T1 - Article Title | ||
ER - | ||
""".split() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from unittest import TestCase | ||
|
||
from portality.lib.ris import RisEntry | ||
|
||
|
||
class TestRisEntry(TestCase): | ||
|
||
def test_get_set_item(self): | ||
test_value = 'value_a' | ||
entry = RisEntry() | ||
entry['A1'] = test_value | ||
assert entry['A1'] == [test_value] | ||
|
||
def test_append(self): | ||
entry = RisEntry() | ||
entry.append('A1', '1') | ||
entry['A1'].append('2') | ||
assert entry['A1'] == ['1', '2'] | ||
|
||
entry['A1'] = '9' | ||
assert entry['A1'] == ['9'] | ||
|
||
def test_getitem__valid_undefined(self): | ||
entry = RisEntry() | ||
assert entry['A1'] == [] | ||
|
||
def test_setitem__raise_field_not_found(self): | ||
entry = RisEntry() | ||
with self.assertRaises(ValueError): | ||
entry['qoidjqowijdkncoiqw'] = 'value_a' | ||
|
||
def test_getitem__raise_field_not_found(self): | ||
entry = RisEntry() | ||
with self.assertRaises(ValueError): | ||
print(entry['qoidjqowijdkncoiqw']) | ||
|
||
def test_to_text(self): | ||
entry = RisEntry() | ||
entry['A1'] = 'value_a' | ||
entry['A2'] = 'value_b' | ||
entry['TY'] = 'JOUR' | ||
|
||
expected = """ | ||
TY - JOUR | ||
A1 - value_a | ||
A2 - value_b | ||
ER - | ||
""".strip() + ' \n' | ||
|
||
assert entry.to_text() == expected | ||
|
||
def test_from_text(self): | ||
expected = """ | ||
TY - JOUR | ||
A1 - value_a | ||
A2 - value_b | ||
ER - | ||
""".strip() + ' \n' | ||
|
||
entry = RisEntry.from_text(expected) | ||
assert entry.type == 'JOUR' | ||
assert dict(entry.data) == { | ||
'TY': ['JOUR'], | ||
'A1': ['value_a'], | ||
'A2': ['value_b'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
|
||
from doajtest import helpers | ||
from doajtest.fixtures import JournalFixtureFactory | ||
from doajtest.fixtures.accounts import create_maned_a | ||
from doajtest.helpers import DoajTestCase | ||
from portality import models | ||
from portality.util import url_for | ||
|
||
|
||
class TestViewAdmin(DoajTestCase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.acc = create_maned_a(save=True) | ||
|
||
def test_journal_article_info(self): | ||
journal = models.Journal( | ||
**JournalFixtureFactory.make_journal_source() | ||
) | ||
journal.save(blocking=True) | ||
models.Journal.refresh() | ||
|
||
with self.app_test.test_client() as client: | ||
resp = helpers.login(client, self.acc.email, 'password') | ||
assert resp.status_code == 200 | ||
|
||
resp = client.get(url_for("admin.journal_article_info", journal_id=journal.id)) | ||
assert resp.status_code == 200 | ||
assert json.loads(resp.data) == {'n_articles': 0} | ||
|
||
def test_journal_article_info__not_found(self): | ||
with self.app_test.test_client() as client: | ||
helpers.login(client, self.acc.email, 'password') | ||
|
||
resp = client.get(url_for("admin.journal_article_info", journal_id='aksjdlaksjdlkajsdlkajsdlk')) | ||
assert resp.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from doajtest.fixtures import ArticleFixtureFactory | ||
from doajtest.helpers import DoajTestCase | ||
from portality.crosswalks.article_ris import ArticleRisXWalk | ||
from portality.models import Article | ||
from portality.util import url_for | ||
|
||
|
||
class TestDoajservices(DoajTestCase): | ||
|
||
def test_export_article_ris(self): | ||
article = Article(**ArticleFixtureFactory.make_article_source()) | ||
article.save(blocking=True) | ||
Article.refresh() | ||
|
||
ris = ArticleRisXWalk.article2ris(article).to_text() | ||
|
||
with self.app_test.test_client() as t_client: | ||
url = url_for('doajservices.export_article_ris', article_id=article.id, fmt='ris') | ||
response = t_client.get(url) | ||
assert response.status_code == 200 | ||
assert response.get_data(as_text=True) == ris | ||
|
||
def test_export_article_ris__not_found(self): | ||
with self.app_test.test_client() as t_client: | ||
url = url_for('doajservices.export_article_ris', | ||
article_id='article_id_that_does_not_exist', fmt='ris') | ||
response = t_client.get(url) | ||
assert response.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from doajtest import helpers | ||
from doajtest.helpers import DoajTestCase | ||
from portality import models, constants | ||
from portality.util import url_for | ||
|
||
|
||
class TestViewPublisher(DoajTestCase): | ||
|
||
def test_delete_application__no_such_object(self): | ||
pwd = 'password' | ||
un = 'publisher_a' | ||
acc = models.Account.make_account(un + "@example.com", un, "Publisher " + un, [constants.ROLE_PUBLISHER]) | ||
acc.set_password(pwd) | ||
acc.save(blocking=True) | ||
|
||
with self.app_test.test_client() as t_client: | ||
resp = helpers.login(t_client, acc.email, pwd) | ||
assert resp.status_code == 200 | ||
|
||
resp = t_client.get(url_for("publisher.delete_application", application_id='no_such_id')) | ||
assert resp.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
| Short | Description | | ||
|---------|------------------------------| | ||
| bgjob | background job | | ||
| noti | notification | | ||
| noqa | NO-QA (NO Quality Assurance) | | ||
| inst | instance | | ||
| fmt | format | | ||
| exparam | extra parameter | | ||
| maned | Managing Editor | | ||
| gsheet | Google Sheet | | ||
| svc | service | | ||
| Short | Description | | ||
|----------|------------------------------| | ||
| bgjob | background job | | ||
| noti | notification | | ||
| noqa | NO-QA (NO Quality Assurance) | | ||
| inst | instance | | ||
| fmt | format | | ||
| exparam | extra parameter | | ||
| maned | Managing Editor | | ||
| gsheet | Google Sheet | | ||
| svc,serv | service | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Union | ||
|
||
from portality import models | ||
from portality.lib import jsonpath_utils | ||
from portality.lib.ris import RisEntry | ||
|
||
|
||
def extra_author_names(article) -> list: | ||
query = '$.bibjson.author[*].name' | ||
values = jsonpath_utils.find_values(query, article) | ||
return sorted(set(values)) | ||
|
||
|
||
RIS_ARTICLE_MAPPING = { | ||
'T1': '$.bibjson.title', | ||
'AU': extra_author_names, | ||
'PY': '$.bibjson.year', | ||
'JF': '$.bibjson.journal.title', | ||
'PB': '$.bibjson.journal.publisher', | ||
'VL': '$.bibjson.journal.volume', | ||
'IS': '$.bibjson.journal.number', | ||
'SP': '$.bibjson.start_page', | ||
'EP': '$.bibjson.end_page', | ||
'UR': '$.bibjson.link[*].url', | ||
'AB': '$.bibjson.abstract', | ||
'KW': '$.bibjson.keywords[*]', | ||
'DO': '$.bibjson.identifier[?(@.type == "doi")].id', | ||
'SN': '$.bibjson.journal.issns[*]', | ||
'LA': '$.bibjson.journal.language[*]', | ||
} | ||
|
||
|
||
class ArticleRisXWalk: | ||
|
||
@classmethod | ||
def article2ris(cls, article: Union[models.Article, dict]) -> RisEntry: | ||
if isinstance(article, models.Article): | ||
article = article.data | ||
|
||
entry = RisEntry(type_of_reference='JOUR') | ||
for tag, query in RIS_ARTICLE_MAPPING.items(): | ||
if callable(query): | ||
values = query(article) | ||
else: | ||
values = jsonpath_utils.find_values(query, article) | ||
|
||
for v in values: | ||
entry[tag].append(v) | ||
|
||
return entry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.