Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: inveniosoftware/invenio-accounts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e87a4468616cf395a8b944da859315b958eb4212
Choose a base ref
..
head repository: inveniosoftware/invenio-accounts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: aae2aca3fa9b0771dfb03d6649912005bf221a41
Choose a head ref
Showing with 8 additions and 14 deletions.
  1. +3 −9 invenio_accounts/datastore.py
  2. +5 −5 tests/test_invenio_accounts.py
12 changes: 3 additions & 9 deletions invenio_accounts/datastore.py
Original file line number Diff line number Diff line change
@@ -47,12 +47,6 @@ def update_role(self, role):
"""Merge roles."""
return self.db.session.merge(role)

def create_or_udpate_role(self, **kwargs):
"""Creates or updates a role with the provided parameters."""
_id = kwargs.get("id")
existing_role = self.role_model.query.filter_by(id=_id).one_or_none()
if existing_role:
updated_role = Role(**kwargs)
return self.update_role(updated_role)
else:
return self.create_role(**kwargs)
def find_role_by_id(self, role_od):
"""Merge roles."""
return self.role_model.query.filter_by(id=role_od).one_or_none()
10 changes: 5 additions & 5 deletions tests/test_invenio_accounts.py
Original file line number Diff line number Diff line change
@@ -139,19 +139,19 @@ def test_datastore_rolecreate(app):
assert 1 == Role.query.filter_by(name="superuser").count()


def test_datastore_create_or_update_role(app):
"""Test create and update role."""
def test_datastore_update_role(app):
"""Test update role."""
ds = app.extensions["invenio-accounts"].datastore

with app.app_context():
r1 = ds.create_or_udpate_role(id="1", name="superuser", description="1234")
r1 = ds.create_role(id="1", name="superuser", description="1234")
ds.commit()
r2 = ds.find_role("superuser")
assert r1 == r2
assert 1 == Role.query.filter_by(name="superuser").count()

r1 = ds.create_or_udpate_role(
id="1", name="megauser", description="updated description"
r1 = ds.update_role(
Role(id="1", name="megauser", description="updated description")
)
ds.commit()
r2 = ds.find_role("megauser")