Skip to content

Commit

Permalink
global: test coverage and docs for non modules
Browse files Browse the repository at this point in the history
* BETTER increase test coverage and add docs for non modules.

Signed-off-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed May 14, 2019
1 parent 84e2b87 commit 1b0651b
Show file tree
Hide file tree
Showing 31 changed files with 61 additions and 46 deletions.
4 changes: 2 additions & 2 deletions rero_ils/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def resource_can_create(record_type):
adm = current_app.extensions['invenio-admin'].admin

def get_admin_view(record_type, menus):
"""."""
"""Get admin view."""
for v in menus:
if v.is_category():
returned_view = get_admin_view(record_type, v.get_children())
Expand All @@ -93,5 +93,5 @@ def admin_menu_is_visible(admin_menu):


def text_to_id(text):
"""."""
"""Text to id."""
return re.sub(r'\W', '', text)
8 changes: 4 additions & 4 deletions rero_ils/modules/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PidChange(Exception):


class IlsRecordsSearch(RecordsSearch):
"""."""
"""Search Class for ils."""

class Meta:
"""Search only on item index."""
Expand All @@ -74,15 +74,15 @@ class Meta:

@classmethod
def flush(cls):
"""."""
"""Flush index."""
current_search.flush_and_refresh(cls.Meta.index)


class IlsRecordIndexer(RecordIndexer):
"""."""
"""Indexing class for ils."""

def index(self, record):
"""."""
"""Indexing a record."""
return_value = super(IlsRecordIndexer, self).index(record)
index_name, doc_type = current_record_to_index(record)
current_search.flush_and_refresh(index_name)
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/circ_policies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def check_permission(fn):
"""Decorate to check permission access."""
@wraps(fn)
def decorated_view(*args, **kwargs):
"""."""
"""Decorated view."""
login_and_librarian()
return fn(*args, **kwargs)
return decorated_view
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/documents/jsonresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@jsonresolver.route('/api/documents/<pid>', host='ils.rero.ch')
def document_resolver(pid):
"""."""
"""Document resolver."""
persistent_id = PersistentIdentifier.get('doc', pid)
if persistent_id.status == PIDStatus.REGISTERED:
return dict(pid=persistent_id.pid_value)
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/documents/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""."""
"""Signals connector for Document."""

from flask import current_app
from invenio_indexer.api import RecordIndexer
Expand Down
6 changes: 3 additions & 3 deletions rero_ils/modules/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ def doc_item_view_method(pid, record, template=None, **kwargs):


def check_permission(fn):
"""."""
"""Check user permission."""
@wraps(fn)
def decorated_view(*args, **kwargs):
"""."""
"""Decorated view."""
login_and_librarian()
return fn(*args, **kwargs)
return decorated_view


@api_blueprint.route('/cover/<isbn>')
def cover(isbn):
"""."""
"""Document cover service."""
cover_service = current_app.config.get('RERO_ILS_THUMBNAIL_SERVICE_URL')
url = cover_service + '?height=60px&jsonpCallbackParam=callback'\
'&type=isbn&width=60px&callback=thumb&value=' + isbn
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/item_types/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def check_permission(fn):
"""Decorate to check permission access."""
@wraps(fn)
def decorated_view(*args, **kwargs):
"""."""
"""Decorated view."""
login_and_librarian()
return fn(*args, **kwargs)
return decorated_view
Expand Down
6 changes: 3 additions & 3 deletions rero_ils/modules/items/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ class StreamArray(list):
"""Converts a generator into a list to be json serialisable."""

def __init__(self, generator):
"""."""
"""Streamarray init."""
self.generator = generator
self._len = 1

def __iter__(self):
"""."""
"""Iterator."""
self._len = 0
for item in self.generator:
yield item
self._len += 1

def __len__(self):
"""."""
"""Record length."""
return self._len


Expand Down
4 changes: 2 additions & 2 deletions rero_ils/modules/loans/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Loan(IlsRecord):
_schema = "loans/loan-ils-v0.0.1.json"

def __init__(self, data, model=None):
"""."""
"""Loan init."""
self["state"] = current_app.config["CIRCULATION_LOAN_INITIAL_STATE"]
super(Loan, self).__init__(data, model)

Expand Down Expand Up @@ -99,7 +99,7 @@ def is_active(self):
return False

def dumps_for_circulation(self):
"""."""
"""Loan dump for circulation."""
loan = self.replace_refs()
data = loan.dumps()

Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/loans/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def create_request(barcode, transaction_type, loanable_items):


def get_loanable_items(patron_type_pid):
"""."""
"""Reutrns list of loanable items."""
loanable_items = ItemsSearch()\
.filter('term', status=ItemStatus.ON_SHELF).source(['pid']).scan()
for loanable_item in loanable_items:
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/loans/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""."""
"""Signals connector for Loans."""

from invenio_circulation.proxies import current_circulation

Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/patron_types/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def check_permission(fn):
"""Decorate to check permission access."""
@wraps(fn)
def decorated_view(*args, **kwargs):
"""."""
"""Decorated view."""
login_and_librarian()
return fn(*args, **kwargs)
return decorated_view
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/patrons/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Record module listener."""
"""Signals connector for patron."""

from flask_babelex import gettext as _

Expand Down
4 changes: 2 additions & 2 deletions rero_ils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


def login_and_librarian():
"""."""
"""Librarian is logged in."""
if not current_user.is_authenticated:
abort(401)
if not librarian_permission.can():
Expand Down Expand Up @@ -73,7 +73,7 @@ def librarian_delete_permission_factory(record, *args, **kwargs):


def admin_permission_factory(admin_view):
"""."""
"""Admin permission factory."""
class FreeAccess(object):
def can(self):
return True
Expand Down
4 changes: 2 additions & 2 deletions rero_ils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def nl2br(string):


def prepare_jsonschema(schema):
"""."""
"""Json schema prep."""
schema = copy.deepcopy(schema)
if schema.get('$schema'):
del schema['$schema']
Expand All @@ -204,7 +204,7 @@ def prepare_jsonschema(schema):


def prepare_form_option(form_option):
"""."""
"""Option prep."""
form_option = copy.deepcopy(form_option)
keys = current_app.config['RERO_ILS_BABEL_TRANSLATE_JSON_KEYS']
return translate(form_option, keys=keys)
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_documents_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_documents_post_put_delete(client, document_data,
@mock.patch('rero_ils.modules.documents.views.login_and_librarian',
mock.MagicMock())
def test_documents_import_bnf_ean(client):
"""."""
"""Test document import from bnf."""
res = client.get(url_for('api_documents.import_bnf_ean', ean='123'))
assert res.status_code == 404
data = get_json(res)
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def ils_record_2():

@pytest.fixture(scope='module')
def es_default_index(es):
"""."""
"""ES default index."""
current_search_client.indices.create(
index='records-record-v1.0.0',
body={},
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/documents/test_documents_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_document_create(db, document_data_tmp):

def test_document_es_mapping(db, org_martigny,
document_data_tmp, item_lib_martigny):
"""."""
"""Test document elasticsearch mapping."""
search = DocumentsSearch()
mapping = get_mapping(search.Meta.index)
assert mapping
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/documents/test_documents_jsonresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


def test_documents_jsonresolver(document):
"""."""
"""Test document resolver."""
rec = Record.create({
'document': {'$ref': 'https://ils.rero.ch/api/documents/doc1'}
})
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/documents/test_documents_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def test_documents_detailed_view(client, loc_public_martigny, document):
"""."""
"""Test document detailed view."""
# check redirection
res = client.get(url_for('invenio_records_ui.doc', pid_value='doc1'))
assert res.status_code == 200
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/items/test_items_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_item_create(db, es_clear, item_lib_martigny_data_tmp):

def test_item_es_mapping(es_clear, db, document, loc_public_martigny,
item_lib_martigny_data_tmp):
"""."""
"""Test item elasticsearch mapping."""
search = ItemsSearch()
mapping = get_mapping(search.Meta.index)
assert mapping
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/loans/test_loans_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_loans_create(db, loan_data_tmp):

def test_loan_es_mapping(es_clear, db, loan_data_tmp, item_lib_martigny,
loc_public_fully, lib_fully):
"""."""
"""Test loans elasticsearch mapping."""
search = current_circulation.loan_search
mapping = get_mapping(search.Meta.index)
assert mapping == get_mapping(search.Meta.index)
2 changes: 1 addition & 1 deletion tests/ui/mef_persons/test_mef_persons_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_mef_person_create(db, mef_person_data_tmp):


def test_mef_person_es_mapping(es_clear, db, mef_person_data_tmp):
"""."""
"""Test mef elasticsearch mapping."""
search = MefPersonsSearch()
mapping = get_mapping(search.Meta.index)
assert mapping
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/mef_persons/test_mef_persons_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@mock.patch('requests.get')
def test_mef_persons_detailed_view(mock_get, client, mef_person_data):
"""."""
"""Test mef detailed view."""
json_data = {'metadata': mef_person_data}
mock_get.return_value = mock_response(json_data=json_data)
# check redirection
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/patron_types/test_patron_types_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_patron_type_create(db, patron_type_children_martigny_data):

def test_patron_type_es_mapping(es_clear, db, org_martigny,
patron_type_children_martigny_data):
"""."""
"""Test patron types es mapping."""
search = PatronTypesSearch()
mapping = get_mapping(search.Meta.index)
assert mapping
Expand All @@ -64,7 +64,7 @@ def test_patron_type_es_mapping(es_clear, db, org_martigny,

def test_patron_type_exist_name_and_organisation_pid(
patron_type_children_martigny):
"""."""
"""Test patron type name uniquness."""
ptty = patron_type_children_martigny.replace_refs()
assert PatronType.exist_name_and_organisation_pid(
ptty.get('name'), ptty.get('organisation', {}).get('pid'))
Expand All @@ -73,6 +73,6 @@ def test_patron_type_exist_name_and_organisation_pid(


def test_patron_type_can_delete(patron_type_children_martigny):
"""Test can delete"""
"""Test can delete a patron type."""
assert patron_type_children_martigny.get_links_to_me() == {}
assert patron_type_children_martigny.can_delete
2 changes: 1 addition & 1 deletion tests/ui/patron_types/test_patron_types_jsonresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


def test_patron_types_jsonresolver(app, patron_type_tmp):
"""."""
"""Test patron type resolver."""
rec = Record.create({
'patron_type': {'$ref': 'https://ils.rero.ch/api/patron_types/1'}
})
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/patrons/test_patrons_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_patron_create(app, roles, librarian_martigny_data_tmp,

def test_patron_es_mapping(
roles, es_clear, lib_martigny, librarian_martigny_data_tmp):
"""."""
"""Test patron elasticsearch mapping."""
search = PatronsSearch()
mapping = get_mapping(search.Meta.index)
assert mapping == get_mapping(search.Meta.index)
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Utils tests."""
"""API tests for non modules."""


from functools import partial
Expand Down Expand Up @@ -157,6 +157,7 @@ def test_ilsrecord(app, es_default_index, ils_record, ils_record_2):

del record['name']
record = record.replace(record, dbcommit=True)
assert record.get_links_to_me() == {}
assert not record.get('name')

with pytest.raises(IlsRecordError.PidMissing):
Expand Down Expand Up @@ -185,12 +186,15 @@ def test_ilsrecord(app, es_default_index, ils_record, ils_record_2):
record = RecordTest.get_record_by_pid('ilsrecord_pid')
record.delete(delindex=True)
assert len(RecordTest.get_all_pids()) == 2
assert len(RecordTest.get_all_ids()) == 2
record = RecordTest.get_record_by_pid('ilsrecord_pid_2')
record.delete(delindex=True)
assert len(RecordTest.get_all_pids()) == 1
assert len(RecordTest.get_all_ids()) == 1
record = RecordTest.get_record_by_pid('1')
record.delete(delindex=True)
assert len(RecordTest.get_all_pids()) == 0
assert len(RecordTest.get_all_ids()) == 0

"""Test IlsRecord es search."""
search_all = list(
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_nl2br():


def test_schemaform(client):
"""."""
"""Test schema form."""
result = client.get(url_for(
'rero_ils.schemaform', document_type="documents"))
assert result.status_code == 200
Expand Down
Loading

0 comments on commit 1b0651b

Please sign in to comment.