Skip to content

Commit

Permalink
fixtures: reset sequence to correct value after loading records
Browse files Browse the repository at this point in the history
* Closes rero#563

Co-Authored-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr authored and iGor milhit committed Oct 16, 2019
1 parent f9d91d2 commit fa62e43
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rero_ils/modules/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from .items.cli import create_items, reindex_items
from .loans.cli import create_loans
from .patrons.cli import import_users
from .providers import append_pids_to_table
from ..modules.providers import append_fixtures_new_identifiers

_datastore = LocalProxy(lambda: current_app.extensions['security'].datastore)

Expand Down Expand Up @@ -240,7 +240,7 @@ def create(infile, pid_type, schema, verbose, dbcommit, reindex, append):
if append:
pids = record_class.get_all_pids()
table = record_class.provider.identifier
append_pids_to_table(table, pids)
append_fixtures_new_identifiers(table, pids)


fixtures.add_command(create)
Expand Down
5 changes: 3 additions & 2 deletions rero_ils/modules/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
from invenio_pidstore.providers.base import BaseProvider


def append_pids_to_table(table, pids):
"""Insert pids into an indentifier table."""
def append_fixtures_new_identifiers(table, pids):
"""Insert pids into the indentifier table and update its sequence."""
for pid in pids:
data = table(recid=pid)
db.session.add(data)
db.session.commit()
table._set_sequence(int(max(pids))+1)


class Provider(BaseProvider):
Expand Down
15 changes: 13 additions & 2 deletions tests/ui/organisations/test_organisations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
from rero_ils.modules.organisations.api import Organisation
from rero_ils.modules.organisations.api import \
organisation_id_fetcher as fetcher
from rero_ils.modules.providers import append_fixtures_new_identifiers


def test_organisation_libararies(org_martigny, lib_martigny):
"""Test libraries retrival."""
assert list(org_martigny.get_libraries()) == [lib_martigny]


def test_organisation_create(app, db, org_martigny_data):
def test_organisation_create(app, db, org_martigny_data, org_sion_data):
"""Test organisation creation."""
org = Organisation.create(org_martigny_data, delete_pid=True)
org_martigny_data['pid'] = '1'
org = Organisation.create(org_martigny_data, dbcommit=True, reindex=True)
assert org == org_martigny_data
assert org.get('pid') == '1'

Expand All @@ -44,3 +46,12 @@ def test_organisation_create(app, db, org_martigny_data):
fetched_pid = fetcher(org.id, org)
assert fetched_pid.pid_value == '1'
assert fetched_pid.pid_type == 'org'

org_sion_data['pid'] = '2'
org = Organisation.create(
org_sion_data, dbcommit=True, reindex=True)
assert org.get('pid') == '2'

identifier = Organisation.provider.identifier
append_fixtures_new_identifiers(identifier, ['1', '2'])
assert identifier.next() == identifier.max() == 3

0 comments on commit fa62e43

Please sign in to comment.