Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier for publishers to link to their articles in DOAJ #2279

Closed
wants to merge 5 commits into from
Closed
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
113 changes: 65 additions & 48 deletions doajtest/unit/test_toc.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
from doajtest.helpers import DoajTestCase
from doajtest.fixtures import ArticleFixtureFactory, JournalFixtureFactory
from doajtest.helpers import DoajTestCase
from portality import app as _app # noqa, make sure route is registered
from portality import models
from portality.util import url_for


def _test_toc_uses_both_issns_when_available(app_test, url_name):
j = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
pissn = j.bibjson().first_pissn
eissn = j.bibjson().first_eissn
j.set_last_manual_update()
j.save(blocking=True)
a = models.Article(**ArticleFixtureFactory.make_article_source(pissn=pissn, eissn=eissn, in_doaj=True))
a.save(blocking=True)
with app_test.test_client() as t_client:
response = t_client.get(url_for(url_name, identifier=j.bibjson().get_preferred_issn()))
assert response.status_code == 200
assert pissn in response.data.decode()
assert eissn in response.data.decode()


def _test_toc_correctly_uses_pissn(app_test, url_name):
j = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
pissn = j.bibjson().first_pissn
# remove eissn
del j.bibjson().eissn
j.set_last_manual_update()
j.save(blocking=True)
a = models.Article(**ArticleFixtureFactory.make_article_source(pissn=pissn, in_doaj=True))
a.save(blocking=True)
with app_test.test_client() as t_client:
response = t_client.get(url_for(url_name, identifier=j.bibjson().get_preferred_issn()))
assert response.status_code == 200
assert pissn in response.data.decode()


def _test_toc_correctly_uses_eissn(app_test, url_name):
j = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
eissn = j.bibjson().first_eissn
# remove pissn
del j.bibjson().pissn
j.set_last_manual_update()
j.save(blocking=True)
a = models.Article(**ArticleFixtureFactory.make_article_source(pissn=eissn, in_doaj=True))
a.save(blocking=True)
with app_test.test_client() as t_client:
response = t_client.get(url_for(url_name, identifier=j.bibjson().get_preferred_issn()))
assert response.status_code == 200
assert eissn in response.data.decode()


class TestTOC(DoajTestCase):

def setUp(self):
super(TestTOC, self).setUp()

def tearDown(self):
super(TestTOC, self).tearDown()

def test_01_article_index_date_parsing(self):
""" The ToC date histogram needs an accurate datestamp in the article's index """
a = models.Article(**ArticleFixtureFactory.make_article_source())
Expand Down Expand Up @@ -43,9 +84,9 @@ def test_01_article_index_date_parsing(self):
d = a.bibjson().get_publication_date()
assert d == '2012-03-01T00:00:00Z'

a.bibjson().year = '86' # beware: this test will give a false negative 70 years from
a.bibjson().month = '11' # the time of writing; this gives adequate warning (24 years)
d = a.bibjson().get_publication_date() # to fix hard-coding of centuries in get_publication_date().
a.bibjson().year = '86' # beware: this test will give a false negative 70 years from
a.bibjson().month = '11' # the time of writing; this gives adequate warning (24 years)
d = a.bibjson().get_publication_date() # to fix hard-coding of centuries in get_publication_date().
assert d == '1986-11-01T00:00:00Z'

# Check we can handle numeric months
Expand Down Expand Up @@ -90,45 +131,21 @@ def test_02_toc_requirements(self):
assert a.data['index']['date_toc_fv_month'] == a.data['index']['date'] == "1991-01-01T00:00:00Z"

def test_03_toc_uses_both_issns_when_available(self):
j = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
pissn = j.bibjson().first_pissn
eissn = j.bibjson().first_eissn
j.set_last_manual_update()
j.save(blocking=True)
a = models.Article(**ArticleFixtureFactory.make_article_source(pissn=pissn, eissn=eissn, in_doaj=True))
a.save(blocking=True)
with self.app_test.test_client() as t_client:
response = t_client.get('/toc/{}'.format(j.bibjson().get_preferred_issn()))
assert response.status_code == 200
assert pissn in response.data.decode()
assert eissn in response.data.decode()
_test_toc_uses_both_issns_when_available(self.app_test, 'doaj.toc')

def test_04_toc_correctly_uses_pissn(self):
_test_toc_correctly_uses_pissn(self.app_test, 'doaj.toc')

def test_05_toc_correctly_uses_eissn(self):
_test_toc_correctly_uses_eissn(self.app_test, 'doaj.toc')


class TestTOCArticles(DoajTestCase):
def test_03_toc_uses_both_issns_when_available(self):
_test_toc_uses_both_issns_when_available(self.app_test, 'doaj.toc_articles')

def test_04_toc_correctly_uses_pissn(self):
j = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
pissn = j.bibjson().first_pissn
# remove eissn
del j.bibjson().eissn

j.set_last_manual_update()
j.save(blocking=True)
a = models.Article(**ArticleFixtureFactory.make_article_source(pissn=pissn, in_doaj=True))
a.save(blocking=True)
with self.app_test.test_client() as t_client:
response = t_client.get('/toc/{}'.format(j.bibjson().get_preferred_issn()))
assert response.status_code == 200
assert pissn in response.data.decode()
_test_toc_correctly_uses_pissn(self.app_test, 'doaj.toc_articles')

def test_05_toc_correctly_uses_eissn(self):
j = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
eissn = j.bibjson().first_eissn
# remove pissn
del j.bibjson().pissn

j.set_last_manual_update()
j.save(blocking=True)
a = models.Article(**ArticleFixtureFactory.make_article_source(pissn=eissn, in_doaj=True))
a.save(blocking=True)
with self.app_test.test_client() as t_client:
response = t_client.get('/toc/{}'.format(j.bibjson().get_preferred_issn()))
assert response.status_code == 200
assert eissn in response.data.decode()
_test_toc_correctly_uses_eissn(self.app_test, 'doaj.toc_articles')
2 changes: 1 addition & 1 deletion portality/static/vendor/edges
Loading