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

fixtures: reset sequence to correct value after loading records #561

Merged
merged 1 commit into from
Oct 16, 2019
Merged
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
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