-
Notifications
You must be signed in to change notification settings - Fork 2
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
current user refresh #115
Merged
Alzpeta
merged 15 commits into
main
from
alzbetapokorna/be-193-fix-current_user-not-in-sync-on-first-build
Jan 12, 2024
Merged
current user refresh #115
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6687122
current user refresh
Alzpeta bdc68e8
template context update
Alzpeta 4313650
tests
Alzpeta 47fa116
run tests file
Alzpeta 8379a7b
current user refresh
Alzpeta 778de6e
template context update
Alzpeta d67a1f1
tests
Alzpeta 046cf15
run tests file
Alzpeta 2b6e3f8
tests
Alzpeta 6b7fcdb
Merge branch 'alzbetapokorna/be-193-fix-current_user-not-in-sync-on-f…
Alzpeta 07da8d7
format
Alzpeta 02bd5f8
tests
Alzpeta 5728fcb
Merge branch 'main' of https://github.com/oarepo/oarepo-ui into alzbe…
Alzpeta a62cb2b
test refactor
Alzpeta 78266e3
version
Alzpeta 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
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 |
---|---|---|
|
@@ -6,11 +6,18 @@ | |
from flask_security import login_user | ||
from flask_security.utils import hash_password | ||
from invenio_access import ActionUsers, current_access | ||
from invenio_access.permissions import system_identity | ||
from invenio_access.models import ActionRoles | ||
from invenio_access.permissions import superuser_access, system_identity | ||
from invenio_accounts.models import Role | ||
from invenio_accounts.testutils import login_user_via_session | ||
from invenio_app.factory import create_app as _create_app | ||
|
||
from tests.model import ModelUIResource, ModelUIResourceConfig, TitlePageUIResource, TitlePageUIResourceConfig | ||
from tests.model import ( | ||
ModelUIResource, | ||
ModelUIResourceConfig, | ||
TitlePageUIResource, | ||
TitlePageUIResourceConfig, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
|
@@ -72,7 +79,9 @@ def record_ui_resource(app, record_ui_resource_config, record_service): | |
|
||
|
||
@pytest.fixture(scope="module") | ||
def titlepage_ui_resource(app, ): | ||
def titlepage_ui_resource( | ||
app, | ||
): | ||
ui_resource = TitlePageUIResource(TitlePageUIResourceConfig()) | ||
app.register_blueprint( | ||
ui_resource.as_blueprint(template_folder=Path(__file__).parent / "templates") | ||
|
@@ -91,6 +100,39 @@ def fake_manifest(app): | |
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def users(app): | ||
"""Create example users.""" | ||
# This is a convenient way to get a handle on db that, as opposed to the | ||
# fixture, won't cause a DB rollback after the test is run in order | ||
# to help with test performance (creating users is a module -if not higher- | ||
# concern) | ||
from invenio_db import db | ||
|
||
with db.session.begin_nested(): | ||
datastore = app.extensions["security"].datastore | ||
|
||
su_role = Role(name="superuser-access") | ||
db.session.add(su_role) | ||
|
||
su_action_role = ActionRoles.create(action=superuser_access, role=su_role) | ||
db.session.add(su_action_role) | ||
|
||
user1 = datastore.create_user( | ||
email="[email protected]", password=hash_password("password"), active=True | ||
|
||
) | ||
user2 = datastore.create_user( | ||
email="[email protected]", password=hash_password("password"), active=True | ||
|
||
) | ||
admin = datastore.create_user( | ||
email="[email protected]", password=hash_password("password"), active=True | ||
|
||
) | ||
admin.roles.append(su_role) | ||
|
||
db.session.commit() | ||
return [user1, user2, admin] | ||
|
||
|
||
@pytest.fixture | ||
def simple_record(app, db, search_clear, record_service): | ||
from .model import ModelRecord | ||
|
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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import json | ||
|
||
|
||
def test_template_page( | ||
app, titlepage_ui_resource, client, fake_manifest | ||
): | ||
def test_template_page(app, titlepage_ui_resource, client, fake_manifest): | ||
with client.get("/") as c: | ||
assert c.status_code == 200 | ||
data = json.loads(c.text) | ||
assert 'ok' in data | ||
assert "ok" in data |
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,7 @@ | ||
import json | ||
|
||
from invenio_access.permissions import system_identity | ||
from invenio_accounts.testutils import login_user_via_session | ||
|
||
|
||
def test_ui_resource_create_new(app, record_ui_resource, record_service): | ||
|
@@ -13,7 +14,7 @@ def test_ui_resource_form_config(app, record_ui_resource): | |
|
||
|
||
def test_permissions_on_detail( | ||
app, record_ui_resource, simple_record, client, fake_manifest | ||
app, record_ui_resource, simple_record, client, fake_manifest, users | ||
): | ||
with client.get(f"/simple-model/{simple_record.id}") as c: | ||
assert c.status_code == 200 | ||
|
@@ -39,6 +40,21 @@ def test_permissions_on_detail( | |
} | ||
|
||
|
||
def test_current_user( | ||
app, record_ui_resource, simple_record, client, fake_manifest, users | ||
): | ||
with client.get(f"/simple-model/{simple_record.id}") as c: | ||
print(c.text) | ||
data = json.loads(c.text) | ||
assert "<flask_security.core.AnonymousUser" in data["current_user"] | ||
|
||
login_user_via_session(client, email=users[0].email) | ||
|
||
with client.get(f"/simple-model/{simple_record.id}") as c: | ||
data = json.loads(c.text) | ||
assert "User <id=1, [email protected]>" in data["current_user"] | ||
|
||
|
||
def test_filter_on_detail( | ||
app, record_ui_resource, simple_record, client, fake_manifest | ||
): | ||
|
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.
Do we have to overwrite the constructor? It seems that the only line modified is 51 and that is done to pass the current_app.
The app is used on 101:
if name in self.jinja_env.app.template_context_processors
can it be changed to
if name in current_app.template_context_processors
?Also, we need tests for this functionality (register test blueprint with context processor and make sure it gets called)