-
Notifications
You must be signed in to change notification settings - Fork 72
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
tests: highlight problem with multiple communities creation #445
Draft
fenekku
wants to merge
1
commit into
inveniosoftware:master
Choose a base branch
from
fenekku:multiple_community_creation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2016-2021 CERN. | ||
# Copyright (C) 2022 Northwestern University. | ||
# Invenio is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Community resources tests.""" | ||
|
||
import pytest | ||
|
||
from flask_principal import AnonymousIdentity, Identity, Need, UserNeed | ||
from invenio_accounts.testutils import create_test_user | ||
from invenio_communities import current_communities | ||
|
||
@pytest.fixture(scope="module") | ||
def community_owner(app): | ||
"""Community owner user.""" | ||
return create_test_user('[email protected]') | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def community_owner_identity(community_owner): | ||
"""Simple identity fixture.""" | ||
owner_id = community_owner.id | ||
i = Identity(owner_id) | ||
i.provides.add(UserNeed(owner_id)) | ||
i.provides.add(Need(method="system_role", value="any_user")) | ||
i.provides.add(Need(method="system_role", value="authenticated_user")) | ||
return i | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def community_service(app, location): | ||
"""Community service. | ||
|
||
Snuck in the location fixture, because needed on community creation | ||
i.e. almost every time this service is used. | ||
""" | ||
return current_communities.service | ||
|
||
|
||
@pytest.fixture() | ||
def number_errors(community_service, community_owner_identity): | ||
"""Number error fixture.""" | ||
def _number_errors(communities): | ||
"""Return number of errors creating communities.""" | ||
errors = 0 | ||
for input_community in communities: | ||
try: | ||
community_service.create( | ||
community_owner_identity, data=input_community | ||
) | ||
except: | ||
errors += 1 | ||
return errors | ||
|
||
return _number_errors | ||
|
||
|
||
@pytest.fixture() | ||
def invalid_community_input(): | ||
"""Valid community inpute fixture 2.""" | ||
return { | ||
"access": { | ||
"visibility": "restricted", | ||
"member_policy": "closed", | ||
"record_policy": "closed", | ||
}, | ||
"id": "id-with-&", | ||
"metadata": { | ||
"title": "Invalid & invalid", | ||
"type": "topic" | ||
} | ||
} | ||
|
||
@pytest.fixture() | ||
def valid_community_input_1(): | ||
"""Valid community inpute fixture 1.""" | ||
return { | ||
"access": { | ||
"visibility": "public", | ||
"member_policy": "open", | ||
"record_policy": "open", | ||
}, | ||
"id": "good-community-1", | ||
"metadata": { | ||
"title": "Good community 1", | ||
"type": "project" | ||
} | ||
} | ||
|
||
|
||
@pytest.fixture() | ||
def valid_community_input_2(): | ||
"""Valid community inpute fixture 2.""" | ||
return { | ||
"access": { | ||
"visibility": "public", | ||
"member_policy": "open", | ||
"record_policy": "open", | ||
}, | ||
"id": "good-community-2", | ||
"metadata": { | ||
"title": "Good community 2", | ||
"type": "project" | ||
} | ||
} | ||
|
||
|
||
def test_create_multiple_communities_order_1( | ||
app, location, | ||
invalid_community_input, valid_community_input_1, | ||
valid_community_input_2, number_errors): | ||
"""Problematic case.""" | ||
|
||
communities = [ | ||
valid_community_input_1, | ||
invalid_community_input, | ||
valid_community_input_2 | ||
] | ||
|
||
assert 1 == number_errors(communities) | ||
|
||
|
||
def test_create_multiple_communities_order_2( | ||
app, location, | ||
invalid_community_input, valid_community_input_1, | ||
valid_community_input_2, number_errors): | ||
"""Problematic case.""" | ||
|
||
communities = [ | ||
invalid_community_input, | ||
valid_community_input_1, | ||
valid_community_input_2 | ||
] | ||
|
||
# Expect the same results as above but it doesn't happen! | ||
assert 1 == number_errors(communities) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. number errors is 2. See #446 for relevant stack trace |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good.