Skip to content

Commit

Permalink
test: fix run-test and setup
Browse files Browse the repository at this point in the history
* Fixes problem with ui/documents/test_documents_api.py not raising
  exceptions. closes rero#1000
* Changes setup back to not run the ebooks harvesting for normal setup.
* Corrects unused imports in scripts/__init__.py

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep and rerowep committed May 19, 2020
1 parent 2f4ebd8 commit fd9f5cb
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 51 deletions.
85 changes: 43 additions & 42 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ polib = "*"
pycountry = ">=19.7.15"
xmltodict = "*"
redisbeat = "*"
jsonpickle = "*"
# TODO: to be removed when the thumbnail will be refactored
angular-gettext-babel= ">=0.1"

Expand Down Expand Up @@ -94,7 +95,6 @@ docutils = "*"
autoflake = ">=1.3.1"
transifex-client = ">=0.12.5"
appnope = { version = "*", optional = true }
jsonpickle = "*"

[tool.poetry.scripts]
bootstrap = "scripts:run('./scripts/bootstrap')"
Expand Down
13 changes: 9 additions & 4 deletions rero_ils/modules/documents/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,17 @@ def dumps(self, **kwargs):

def index_persons(self, bulk=False):
"""Index all attached persons."""
from ..persons.api import Person
persons_ids = []
for author in self.get('authors', []):
person = None
ref = author.get('$ref')
if ref:
from ..persons.api import Person
person = Person.get_record_by_ref(ref)
pid = author.get('pid')
if pid:
person = Person.get_record_by_pid(pid)
if person:
if bulk:
persons_ids.append(person.id)
else:
Expand All @@ -213,9 +218,9 @@ def replace_refs(self):
for idx, author in enumerate(authors):
ref = author.get('$ref')
if ref:
pers = Person.get_record_by_ref(ref)
if pers:
authors[idx] = pers
person = Person.get_record_by_ref(ref)
if person:
authors[idx] = person
return super(Document, self).replace_refs()


Expand Down
2 changes: 1 addition & 1 deletion scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""Poetry script utils."""

import os
import subprocess
# import subprocess
import sys

# def __getattr__(name): # python 3.7+, otherwise define each script manually
Expand Down
8 changes: 5 additions & 3 deletions scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ celery purge -A rero_ils.celery -f
# Clean redis
info_msg "Clean redis"
eval "${PREFIX} invenio shell --no-term-title -c \"import redis; redis.StrictRedis.from_url(app.config['CACHE_REDIS_URL']).flushall(); print('Cache cleared')\""
eval ${PREFIX} pipenv run invenio scheduler init -r
eval ${PREFIX} invenio scheduler init -r

eval ${PREFIX} invenio db destroy --yes-i-know
eval ${PREFIX} invenio db init create
Expand Down Expand Up @@ -370,8 +370,10 @@ then
eval ${PREFIX} invenio oaiharvester harvest -n ebooks -q -k
else
eval ${PREFIX} invenio scheduler enable_tasks -n bulk-indexer -n notification-creation -n accounts -n clear_and_renew_subscriptions -v
info_msg "Start OAI harvesting 100"
eval ${PREFIX} invenio oaiharvester harvest -n ebooks -a max=100 -q
info_msg "For ebooks harvesting run:"
msg "\tinvenio oaiharvester harvest -n ebooks -a max=100 -q"
# info_msg "Start OAI harvesting 100"
# eval ${PREFIX} invenio oaiharvester harvest -n ebooks -a max=100 -q
fi

if ${ES_MAPPING}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/documents/test_documents_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def test_document_can_delete_with_loans(

def test_document_person_resolve_exception(es_clear, db, document_data_ref):
"""Test document person resolve."""
document_data_ref['authors'] = [{
'$ref': 'https://mef.rero.ch/api/rero/XXXXXX',
'type': 'person'
}],
with pytest.raises(Exception):
Document.create(
data=document_data_ref,
Expand Down

0 comments on commit fd9f5cb

Please sign in to comment.