Skip to content

Commit

Permalink
new url for articles
Browse files Browse the repository at this point in the history
  • Loading branch information
philipkcl committed Aug 2, 2023
1 parent ec2d037 commit ea64816
Show file tree
Hide file tree
Showing 5 changed files with 659 additions and 554 deletions.
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 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 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):
toc_correctly_uses_pissn(self.app_test, 'doaj.toc')

def test_05_toc_correctly_uses_eissn(self):
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()
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()
toc_correctly_uses_eissn(self.app_test, 'doaj.toc_articles')
Loading

0 comments on commit ea64816

Please sign in to comment.