Skip to content

Commit

Permalink
Merge branch 'release/2024-11-12_3647ris_3573article_autocheck_3838_n…
Browse files Browse the repository at this point in the history
…osuchapplication'
  • Loading branch information
Steven-Eardley committed Nov 12, 2024
2 parents 2392ec2 + bc293ff commit cc0f0ab
Show file tree
Hide file tree
Showing 29 changed files with 658 additions and 56 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
This repository provides the software which drives the DOAJ website and the DOAJ
directory.

## CI Status

**develop**   [![CircleCI](https://dl.circleci.com/status-badge/img/gh/DOAJ/doaj/tree/develop.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/DOAJ/doaj/tree/develop)

**master**   [![CircleCI](https://dl.circleci.com/status-badge/img/gh/DOAJ/doaj/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/DOAJ/doaj/tree/master)

## Reporting issues

Please feel free to use the issue tracker on https://github.com/DOAJ/doaj/issues for any bug
Expand Down
5 changes: 4 additions & 1 deletion doajtest/fixtures/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ def create_publisher_a():
return publisher


def create_maned_a():
def create_maned_a(save=False):
from portality import models
maned = models.Account(**AccountFixtureFactory.make_managing_editor_source())
maned.set_password("password")
if save:
maned.save(blocking=True)
return maned


Expand Down
2 changes: 1 addition & 1 deletion doajtest/fixtures/v2/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

SEAL_FORM_EXPANDED = {
"doaj_seal": False,
"doaj_seal": [],
}

JOURNAL_LIKE_BIBJSON = {
Expand Down
5 changes: 3 additions & 2 deletions doajtest/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class DoajTestCase(TestCase):
@classmethod
def create_app_patch(cls):
return {
'AUTOCHECK_INCOMING': False, # old test cases design and depend on work flow of autocheck disabled
"STORE_IMPL": "portality.store.StoreLocal",
"STORE_LOCAL_DIR": paths.rel2abs(__file__, "..", "tmp", "store", "main", cls.__name__.lower()),
"STORE_TMP_DIR": paths.rel2abs(__file__, "..", "tmp", "store", "tmp", cls.__name__.lower()),
Expand Down Expand Up @@ -436,9 +437,9 @@ def assert_expected_dict(test_case: TestCase, target, expected: dict):
test_case.assertDictEqual(actual, expected)


def login(app_client, username, password, follow_redirects=True):
def login(app_client, email, password, follow_redirects=True):
return app_client.post(url_for('account.login'),
data=dict(user=username, password=password),
data=dict(user=email, password=password),
follow_redirects=follow_redirects)


Expand Down
11 changes: 10 additions & 1 deletion doajtest/testbook/public_site/public_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,13 @@ tests:
- step: click spacebar to check the filter
results:
- filter is applied

- title: Export article in RIS format
context:
role: anonymous
steps:
- step: Go to the DOAJ search page at /search/articles
results:
- Only articles are shown in the results
- step: Click on 'Export RIS' of any article
results:
- A RIS file is downloaded
5 changes: 2 additions & 3 deletions doajtest/unit/api_tests/test_api_crud_returnvalues.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from doajtest import helpers
from doajtest.helpers import DoajTestCase, with_es
from portality import models
from doajtest.fixtures import ApplicationFixtureFactory, ArticleFixtureFactory, JournalFixtureFactory
Expand Down Expand Up @@ -205,9 +206,7 @@ def test_04_article_structure_exceptions(self):

@staticmethod
def login(app, username, password):
return app.post('/account/login',
data=dict(username=username, password=password),
follow_redirects=True)
return helpers.login(app, username, password)

@staticmethod
def logout(app):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_04_maned_review_doaj_seal(self):
)

# set the seal to False using the form
fc.form.doaj_seal.data = False
fc.form.doaj_seal.data = []

# run the crosswalk, don't test it at all in this test
fc.form2target()
Expand All @@ -162,7 +162,7 @@ def test_04_maned_review_doaj_seal(self):
fc.source.set_seal(True)
fc.source2form()

assert fc.form.doaj_seal.data is True
assert 'y' in fc.form.doaj_seal.data

def test_05_maned_review_continuations(self):
# construct it from form data (with a known source)
Expand Down
43 changes: 43 additions & 0 deletions doajtest/unit/test_crosswalks_article_ris.py
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()
66 changes: 66 additions & 0 deletions doajtest/unit/test_ris.py
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'],
}
37 changes: 37 additions & 0 deletions doajtest/unit/test_view_admin.py
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
28 changes: 28 additions & 0 deletions doajtest/unit/test_view_doajservices.py
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
21 changes: 21 additions & 0 deletions doajtest/unit/test_view_publisher.py
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
22 changes: 11 additions & 11 deletions docs/dictionary.md
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 |
50 changes: 50 additions & 0 deletions portality/crosswalks/article_ris.py
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
4 changes: 2 additions & 2 deletions portality/crosswalks/journal_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def form2admin(cls, form, obj):
obj.set_editor(editor)

if getattr(form, "doaj_seal", None):
obj.set_seal(form.doaj_seal.data)
obj.set_seal('y' in form.doaj_seal.data)

@classmethod
def bibjson2form(cls, bibjson, forminfo):
Expand Down Expand Up @@ -457,7 +457,7 @@ def admin2form(cls, obj, forminfo):
if obj.editor is not None:
forminfo['editor'] = obj.editor

forminfo['doaj_seal'] = obj.has_seal()
forminfo['doaj_seal'] = ['y'] if obj.has_seal() else []


class JournalFormXWalk(JournalGenericXWalk):
Expand Down
Loading

0 comments on commit cc0f0ab

Please sign in to comment.