forked from inveniosoftware/invenio-communities
-
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.
resources: [inveniosoftware#855] add POST request_membership
- Loading branch information
Showing
7 changed files
with
249 additions
and
6 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
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
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
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import pytest | ||
from invenio_access.permissions import system_identity | ||
from invenio_requests.records.api import RequestEvent | ||
from invenio_users_resources.proxies import current_users_service | ||
|
||
|
||
# | ||
|
@@ -134,7 +135,7 @@ def test_invite_deny(client, headers, community_id, new_user, new_user_data, db) | |
# | ||
# Update | ||
# | ||
def test_update(client, headers, community_id, owner, public_reader): | ||
def test_update(client, headers, community_id, owner, public_reader, db): | ||
"""Test update of members.""" | ||
client = owner.login(client) | ||
data = { | ||
|
@@ -357,3 +358,100 @@ def test_search_invitation( | |
# TODO: facet by role, facet by visibility, define sorts. | ||
# TODO: same user can be invited to two different communities | ||
# TODO: same user/group can be added to two different communities | ||
|
||
|
||
# | ||
# Membership request | ||
# | ||
|
||
# The `new_user`` module fixture leaks identity across tests, so a pure new user for | ||
# each following test is the way to go. | ||
@pytest.fixture() | ||
def create_user(UserFixture, app, db): | ||
"""Create user factory fixture.""" | ||
|
||
def _create_user(data): | ||
"""Create user.""" | ||
default_data = dict( | ||
email="[email protected]", | ||
password="user", | ||
username="user", | ||
user_profile={ | ||
"full_name": "Created User", | ||
"affiliations": "CERN", | ||
}, | ||
preferences={ | ||
"visibility": "public", | ||
"email_visibility": "restricted", | ||
"notifications": { | ||
"enabled": True, | ||
}, | ||
}, | ||
active=True, | ||
confirmed=True, | ||
) | ||
actual_data = dict(default_data, **data) | ||
u = UserFixture(**actual_data) | ||
u.create(app, db) | ||
current_users_service.indexer.process_bulk_queue() | ||
current_users_service.record_cls.index.refresh() | ||
db.session.commit() | ||
return u | ||
|
||
return _create_user | ||
|
||
|
||
def test_post_membership_requests(app, client, headers, community_id, create_user, db): | ||
user = create_user({"email": "[email protected]", "username": "user_foo"}) | ||
client = user.login(client) | ||
|
||
# Post membership request | ||
r = client.post( | ||
f"/communities/{community_id}/membership-requests", | ||
headers=headers, | ||
json={"message": "Can I join the club?"}, | ||
) | ||
assert 201 == r.status_code | ||
|
||
RequestEvent.index.refresh() | ||
|
||
# Get links to check | ||
url_of_request = r.json["links"]["self"].replace(app.config["SITE_API_URL"], "") | ||
url_of_timeline = r.json["links"]["timeline"].replace( | ||
app.config["SITE_API_URL"], | ||
"", | ||
) | ||
|
||
# Check the request | ||
r = client.get(url_of_request, headers=headers) | ||
assert 200 == r.status_code | ||
assert 'Request to join "My Community"' in r.json["title"] | ||
|
||
# Check the timeline | ||
r = client.get(url_of_timeline, headers=headers) | ||
assert 200 == r.status_code | ||
assert 1 == r.json["hits"]["total"] | ||
msg = r.json["hits"]["hits"][0]["payload"]["content"] | ||
assert 'Can I join the club?' == msg | ||
|
||
|
||
def test_put_membership_requests(client, headers, community_id, owner, new_user_data, db): | ||
# update membership request | ||
assert False | ||
|
||
|
||
def test_error_handling_for_membership_requests(client, headers, community_id, owner, new_user_data, db): | ||
# error handling registered | ||
# - permission handling registered | ||
# - duplicate handling registered | ||
assert False | ||
|
||
|
||
# is cancelling request purview of this? | ||
|
||
# TODO: search membership requests | ||
# def test_get_membership_requests(client): | ||
# RequestEvent.index.refresh() | ||
# r = client.get(f"/communities/{community_id}/membership-requests", headers=headers) | ||
# assert r.status_code == 200 | ||
# request_id = r.json["hits"]["hits"][0]["request"]["id"] |