-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from oarepo/miroslavsimek/be-570-incorrectly-g…
…enerated-query_filter-for fix: community roles generate incorrect query_filter
- Loading branch information
Showing
8 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[metadata] | ||
name = oarepo-communities | ||
version = 5.1.0 | ||
version = 5.1.1 | ||
description = | ||
authors = Ronald Krist <[email protected]> | ||
readme = README.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def sample_record_with_community_data(communities): | ||
community_aaa = str(communities['aaa'].id) | ||
community_bbb = str(communities['bbb'].id) | ||
return { | ||
'parent': { | ||
'communities': { | ||
'ids': { | ||
community_aaa, community_bbb | ||
}, | ||
'default': community_aaa | ||
} | ||
} | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def as_comparable_dict(): | ||
def _as_comparable(d): | ||
if isinstance(d, dict): | ||
return {k: _as_comparable(v) for k, v in sorted(d.items())} | ||
if isinstance(d, (list, tuple)): | ||
return set(_as_comparable(v) for v in d) | ||
return d | ||
|
||
return _as_comparable |
32 changes: 32 additions & 0 deletions
32
tests/test_communities/permissions/test_community_members.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from invenio_communities.generators import CommunityRoleNeed | ||
|
||
from oarepo_communities.services.permissions.generators import CommunityMembers | ||
|
||
|
||
def test_community_members_needs(app, db, sample_record_with_community_data, communities): | ||
members = CommunityMembers() | ||
assert set(members.needs(data=sample_record_with_community_data)) == { | ||
CommunityRoleNeed(str(communities['aaa'].id), 'owner'), | ||
CommunityRoleNeed(str(communities['bbb'].id), 'owner'), | ||
CommunityRoleNeed(str(communities['aaa'].id), 'manager'), | ||
CommunityRoleNeed(str(communities['bbb'].id), 'manager'), | ||
CommunityRoleNeed(str(communities['aaa'].id), 'curator'), | ||
CommunityRoleNeed(str(communities['bbb'].id), 'curator'), | ||
CommunityRoleNeed(str(communities['aaa'].id), 'reader'), | ||
CommunityRoleNeed(str(communities['bbb'].id), 'reader'), | ||
} | ||
|
||
def test_community_members_excludes(app, db, sample_record_with_community_data, communities): | ||
members = CommunityMembers() | ||
assert not set(members.excludes(data=sample_record_with_community_data)) | ||
|
||
def test_community_members_query_filter(app, db, sample_record_with_community_data, communities, community_owner, as_comparable_dict): | ||
members = CommunityMembers() | ||
assert as_comparable_dict(members.query_filter(identity=community_owner.identity).to_dict()) == as_comparable_dict({ | ||
'terms': { | ||
'parent.communities.ids': [ | ||
str(communities['aaa'].id), | ||
str(communities['bbb'].id) | ||
] | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from invenio_communities.generators import CommunityRoleNeed | ||
|
||
from oarepo_communities.services.permissions.generators import CommunityRole | ||
|
||
|
||
def test_community_role_needs(app, db, sample_record_with_community_data, communities): | ||
role = CommunityRole("owner") | ||
assert set(role.needs(data=sample_record_with_community_data)) == { | ||
CommunityRoleNeed(str(communities['aaa'].id), 'owner'), | ||
CommunityRoleNeed(str(communities['bbb'].id), 'owner'), | ||
} | ||
|
||
def test_community_role_excludes(app, db, sample_record_with_community_data, communities): | ||
role = CommunityRole("owner") | ||
assert not set(role.excludes(data=sample_record_with_community_data)) | ||
|
||
def test_community_role_query_filter(app, db, sample_record_with_community_data, communities, community_owner, as_comparable_dict): | ||
role = CommunityRole("owner") | ||
assert as_comparable_dict(role.query_filter(identity=community_owner.identity).to_dict()) == as_comparable_dict({ | ||
'terms': { | ||
'parent.communities.ids': [ | ||
str(communities['aaa'].id), | ||
str(communities['bbb'].id) | ||
] | ||
} | ||
}) |
28 changes: 28 additions & 0 deletions
28
tests/test_communities/permissions/test_default_community_members.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from invenio_communities.generators import CommunityRoleNeed | ||
|
||
from oarepo_communities.services.permissions.generators import DefaultCommunityMembers | ||
|
||
|
||
def test_community_members_needs(app, db, sample_record_with_community_data, communities): | ||
members = DefaultCommunityMembers() | ||
assert set(members.needs(data=sample_record_with_community_data)) == { | ||
CommunityRoleNeed(str(communities['aaa'].id), 'owner'), | ||
CommunityRoleNeed(str(communities['aaa'].id), 'manager'), | ||
CommunityRoleNeed(str(communities['aaa'].id), 'curator'), | ||
CommunityRoleNeed(str(communities['aaa'].id), 'reader'), | ||
} | ||
|
||
def test_community_members_excludes(app, db, sample_record_with_community_data, communities): | ||
members = DefaultCommunityMembers() | ||
assert not set(members.excludes(data=sample_record_with_community_data)) | ||
|
||
def test_community_members_query_filter(app, db, sample_record_with_community_data, communities, community_owner, as_comparable_dict): | ||
members = DefaultCommunityMembers() | ||
assert as_comparable_dict(members.query_filter(identity=community_owner.identity).to_dict()) == as_comparable_dict({ | ||
'terms': { | ||
'parent.communities.default': [ | ||
str(communities['aaa'].id), | ||
str(communities['bbb'].id) | ||
] | ||
} | ||
}) |
25 changes: 25 additions & 0 deletions
25
tests/test_communities/permissions/test_default_community_role.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from invenio_communities.generators import CommunityRoleNeed | ||
|
||
from oarepo_communities.services.permissions.generators import CommunityRole, DefaultCommunityRole | ||
|
||
|
||
def test_default_community_role_needs(app, db, sample_record_with_community_data, communities): | ||
role = DefaultCommunityRole("owner") | ||
assert set(role.needs(data=sample_record_with_community_data)) == { | ||
CommunityRoleNeed(str(communities['aaa'].id), 'owner'), | ||
} | ||
|
||
def test_default_community_role_excludes(app, db, sample_record_with_community_data, communities): | ||
role = DefaultCommunityRole("owner") | ||
assert not set(role.excludes(data=sample_record_with_community_data)) | ||
|
||
def test_default_community_role_query_filter(app, db, sample_record_with_community_data, communities, community_owner, as_comparable_dict): | ||
role = DefaultCommunityRole("owner") | ||
assert as_comparable_dict(role.query_filter(identity=community_owner.identity).to_dict()) == as_comparable_dict({ | ||
'terms': { | ||
'parent.communities.default': [ | ||
str(communities['aaa'].id), | ||
str(communities['bbb'].id) | ||
] | ||
} | ||
}) |