Skip to content

Commit 3f87ed6

Browse files
committed
test: Keep only one conftest.py at the top-level
1 parent 577dea0 commit 3f87ed6

File tree

6 files changed

+71
-82
lines changed

6 files changed

+71
-82
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ jobs:
5757
pip install --upgrade pip
5858
pip install --use-deprecated=legacy-resolver ".[$EXTRAS]"
5959
pip freeze
60-
- name: Clean pycache
61-
run: |
62-
find . -type d -name "__pycache__" -exec rm -r {} +
63-
find . -type f -name "*.pyc" -delete
60+
# - name: Clean pycache
61+
# run: |
62+
# find . -type d -name "__pycache__" -exec rm -r {} +
63+
# find . -type f -name "*.pyc" -delete
6464
- name: Run tests
6565
run: ./run-tests.sh
6666

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Byte-compiled / optimized / DLL files
22
__pycache__/
33
*.py[cod]
4-
4+
*.pyc
5+
.pytest_cache
56
# Idea software family
67
.idea/
78

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ recursive-include tests *.html
3535
recursive-include tests *.json
3636
recursive-include tests *.py
3737
include .git-blame-ignore-revs
38+
recursive-include tests *.py
39+
tests/communities/conftest.py

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ install_requires =
3636
[options.extras_require]
3737
tests =
3838
pytest-black-ng>=0.4.1
39-
faker>=37.1.0
39+
Faker>=37.1.0
4040
invenio-app>=1.5.1,<2.0.0
4141
invenio-db[postgresql,mysql]>=1.3.1,<2.0.0
4242
pytest-invenio>=2.2.1,<3.0.0

tests/communities/conftest.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

tests/conftest.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
import pytest
1515
from flask_principal import AnonymousIdentity
16+
from flask_security import login_user
1617
from invenio_access.models import ActionRoles
1718
from invenio_access.permissions import any_user as any_user_need
1819
from invenio_access.permissions import superuser_access
1920
from invenio_accounts.models import Role
21+
from invenio_accounts.testutils import login_user_via_session
2022
from invenio_administration.permissions import administration_access_action
2123
from invenio_app.factory import create_api
2224
from invenio_notifications.backends import EmailNotificationBackend
2325
from invenio_notifications.services.builders import NotificationBuilder
26+
from invenio_records_resources.proxies import current_service_registry
2427
from invenio_records_resources.references.entity_resolvers import ServiceResultResolver
2528
from invenio_records_resources.services.custom_fields import TextCF
2629
from invenio_requests.proxies import current_events_service, current_requests_service
@@ -30,6 +33,7 @@
3033
UserPreferencesSchema,
3134
UserSchema,
3235
)
36+
from invenio_vocabularies.contrib.affiliations.api import Affiliation
3337
from invenio_vocabularies.proxies import current_service as vocabulary_service
3438
from invenio_vocabularies.records.api import Vocabulary
3539
from marshmallow import fields
@@ -572,3 +576,61 @@ def cli_invoke(command, *args, input=None):
572576
return base_app.test_cli_runner().invoke(command, args, input=input)
573577

574578
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

Comments
 (0)