|
13 | 13 |
|
14 | 14 | import pytest |
15 | 15 | from flask_principal import AnonymousIdentity |
| 16 | +from flask_security import login_user |
16 | 17 | from invenio_access.models import ActionRoles |
17 | 18 | from invenio_access.permissions import any_user as any_user_need |
18 | 19 | from invenio_access.permissions import superuser_access |
19 | 20 | from invenio_accounts.models import Role |
| 21 | +from invenio_accounts.testutils import login_user_via_session |
20 | 22 | from invenio_administration.permissions import administration_access_action |
21 | 23 | from invenio_app.factory import create_api |
22 | 24 | from invenio_notifications.backends import EmailNotificationBackend |
23 | 25 | from invenio_notifications.services.builders import NotificationBuilder |
| 26 | +from invenio_records_resources.proxies import current_service_registry |
24 | 27 | from invenio_records_resources.references.entity_resolvers import ServiceResultResolver |
25 | 28 | from invenio_records_resources.services.custom_fields import TextCF |
26 | 29 | from invenio_requests.proxies import current_events_service, current_requests_service |
|
30 | 33 | UserPreferencesSchema, |
31 | 34 | UserSchema, |
32 | 35 | ) |
| 36 | +from invenio_vocabularies.contrib.affiliations.api import Affiliation |
33 | 37 | from invenio_vocabularies.proxies import current_service as vocabulary_service |
34 | 38 | from invenio_vocabularies.records.api import Vocabulary |
35 | 39 | from marshmallow import fields |
@@ -572,3 +576,61 @@ def cli_invoke(command, *args, input=None): |
572 | 576 | return base_app.test_cli_runner().invoke(command, args, input=input) |
573 | 577 |
|
574 | 578 | return cli_invoke |
| 579 | + |
| 580 | + |
| 581 | +@pytest.fixture() |
| 582 | +def affiliation(app, db, superuser_identity): |
| 583 | + """Affiliation vocabulary record.""" |
| 584 | + aff = current_service_registry.get("affiliations").create( |
| 585 | + superuser_identity, |
| 586 | + { |
| 587 | + "name": "CERN", |
| 588 | + "id": "cern", |
| 589 | + "acronym": "CERN", |
| 590 | + "identifiers": [ |
| 591 | + { |
| 592 | + "scheme": "ror", |
| 593 | + "identifier": "01ggx4157", |
| 594 | + }, |
| 595 | + { |
| 596 | + "scheme": "isni", |
| 597 | + "identifier": "000000012156142X", |
| 598 | + }, |
| 599 | + ], |
| 600 | + }, |
| 601 | + ) |
| 602 | + |
| 603 | + Affiliation.index.refresh() |
| 604 | + |
| 605 | + return aff |
| 606 | + |
| 607 | + |
| 608 | +@pytest.fixture() |
| 609 | +def client_with_login(client, users): |
| 610 | + """Log in a user to the client.""" |
| 611 | + user = users[0] |
| 612 | + login_user(user, remember=True) |
| 613 | + login_user_via_session(client, email=user.email) |
| 614 | + return client |
| 615 | + |
| 616 | + |
| 617 | +@pytest.fixture(scope="module") |
| 618 | +def parent_community(community_service, owner, minimal_community, location): |
| 619 | + """A community.""" |
| 620 | + minimal_community["slug"] = "parent" |
| 621 | + minimal_community["title"] = "Parent Community" |
| 622 | + c = community_service.create(owner.identity, minimal_community) |
| 623 | + Community.index.refresh() |
| 624 | + owner.refresh() |
| 625 | + return c._record |
| 626 | + |
| 627 | + |
| 628 | +@pytest.fixture(scope="module") |
| 629 | +def child_community(community_service, owner, minimal_community, location): |
| 630 | + """A community.""" |
| 631 | + minimal_community["slug"] = "child" |
| 632 | + minimal_community["title"] = "Child Community" |
| 633 | + c = community_service.create(owner.identity, minimal_community) |
| 634 | + Community.index.refresh() |
| 635 | + owner.refresh() |
| 636 | + return c._record |
0 commit comments