Skip to content

Commit 97efed1

Browse files
committed
fix(tests): Various maintenance tweaks for tests; adding js tests to CI workflow
1 parent f2d3433 commit 97efed1

14 files changed

Lines changed: 951 additions & 3454 deletions

File tree

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ jobs:
143143
if: always()
144144
run: |
145145
touch .env
146-
docker compose --file docker-compose.yml --file docker-compose.dev.yml up -d
146+
docker compose --file docker-compose.yml up -d
147147
148148
- name: Destroy containers
149149
if: always()
150150
run: |
151151
touch .env
152-
docker compose --file docker-compose.yml --file docker-compose.dev.yml down
152+
docker compose --file docker-compose.yml down
153153
154154
- name: Prune Docker
155155
run: docker system prune -af

.github/workflows/tests.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ jobs:
9595
# - name: Run translations test
9696
# run: ./run-i18n-tests.sh
9797

98-
# - name: Install deps for frontend tests
99-
# working-directory: ./site/kcworks/assets/semantic-ui/js/kcworks
100-
# run: npm install
98+
- name: Install deps for frontend tests
99+
working-directory: .
100+
run: npm install
101101

102102
# - name: Install deps for frontend tests - translations
103103
# working-directory: ./translations/kcworks
104104
# run: npm install
105105

106-
# - name: Run frontend tests
107-
# working-directory: ./site/kcworks/assets/semantic-ui/js/kcworks
108-
# run: npm test
106+
- name: Run frontend tests
107+
working-directory: .
108+
run: |
109+
chmod +x run-js-tests.sh
110+
bash run-js-tests.sh

docs/source/setup/installation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ Do not use the `--recurse-submodules` option when cloning the repository or the
2020
### 2. Create your configuration files
2121

2222
- `cd knowledge-commons-works`
23-
- Create and configure the `.env` file in this folder as described {ref}`here <in_depth:add and configure an environment file>`
23+
- Create and configure the `.env` file in this folder as described {ref}`here <setting-up-configuration-files>`
2424
- Create the `.invenio.private` file with the following contents:
2525

2626
```shell
2727
[cli]
2828
services_setup = True
2929
instance_path = /opt/invenio/var/instance
3030
```
31+
3132
### 3. Start the docker-compose project
3233

3334
- `docker-compose --file docker-compose.yml up -d`

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
'^@translations/invenio_rdm_records/i18next$': '<rootDir>/site/kcworks/dependencies/invenio-rdm-records/invenio_rdm_records/assets/semantic-ui/translations/invenio_rdm_records/i18next.js',
1717
'^@custom-test-utils/(.*)$': '<rootDir>/tests/js/$1',
1818
'^@js/invenio_modular_deposit_form/(.*)$': '<rootDir>/site/kcworks/dependencies/invenio-modular-deposit-form/invenio_modular_deposit_form/assets/semantic-ui/js/invenio_modular_deposit_form/$1',
19+
'^@translations/(.*)$': '<rootDir>/assets/translations/$1',
1920
},
2021
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
2122
transform: {

run-tests.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ if [[ ${keep_services} -eq 0 ]]; then
4747
trap cleanup EXIT
4848
fi
4949

50-
# python -m check_manifest --no-build-isolation
51-
python -m setup extract_messages --output-file /dev/null
50+
# Extract and compile translations from python files
51+
uv run invenio-cli translations extract
52+
uv run invenio-cli translations update
53+
uv run invenio-cli translations compile
54+
55+
# Build the documentation
5256
uv run sphinx-build -b html docs/source/ docs/build/
5357

5458
# Start the services and get their environment variables

site/kcworks/services/records/permissions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from collections.abc import Sequence
1818
from functools import reduce
1919

20-
from flask import current_app
2120
from invenio_access.permissions import Permission, system_identity
2221
from invenio_administration.generators import Administration
2322
from invenio_communities.generators import (
@@ -78,10 +77,11 @@ def per_field_edit_permission_factory(
7877
if isinstance(list(roles)[0], str):
7978
try:
8079
assert all(r in community_role_generators.keys() for r in roles)
81-
except AssertionError:
82-
current_app.logger.error(
83-
f"Invalid roles: {roles}. Valid roles are: {community_role_generators.keys()}"
84-
)
80+
except AssertionError as e:
81+
raise PermissionError(
82+
f"Invalid roles: {roles}. Valid roles "
83+
f"are: {community_role_generators.keys()}"
84+
) from e
8585
role_generators.extend(
8686
[g for r, g in community_role_generators.items() if r in roles]
8787
)

site/kcworks/services/records/record_communities/community_change_permissions_component.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717

1818
from typing import Any
1919

20-
from flask import current_app
2120
from flask_principal import Identity
2221
from invenio_access.permissions import system_identity
2322
from invenio_communities.errors import SetDefaultCommunityError
24-
from invenio_communities.proxies import current_communities
25-
from invenio_rdm_records.proxies import (
26-
current_rdm_records,
27-
current_rdm_records_service,
28-
)
23+
from invenio_rdm_records.proxies import current_rdm_records_service
2924
from invenio_rdm_records.records.api import RDMRecord
3025
from invenio_records_resources.services.errors import PermissionDeniedError
3126
from invenio_records_resources.services.records.components.base import ServiceComponent
@@ -199,33 +194,12 @@ def set_default(
199194
)
200195
if published_version._record.parent.communities.default: # type: ignore
201196
previous_default_id = (
202-
published_version._record.parent.communities.default.id # type: ignore
197+
published_version._record.parent.communities.default.id
203198
)
204199
else:
205200
previous_default_id = None
206201

207202
if previous_default_id != default_community_id:
208-
handlers = (
209-
current_rdm_records.record_communities_resource.error_handlers.copy()
210-
)
211-
handlers.update(current_app.config.get("COMMUNITIES_ERROR_HANDLERS"))
212-
current_rdm_records.record_communities_resource.error_handlers = (
213-
handlers
214-
)
215-
current_app.logger.info("COMMUNITIES_ERROR_HANDLERS")
216-
current_app.logger.info(
217-
current_app.config.get("COMMUNITIES_ERROR_HANDLERS")
218-
)
219-
current_app.logger.info(
220-
current_rdm_records.record_communities_resource.error_handlers
221-
)
222-
current_community = current_communities.service.read(
223-
system_identity,
224-
id_=previous_default_id,
225-
).to_dict()
226-
current_community_title = current_community.get("metadata", {}).get(
227-
"title", ""
228-
) or current_community.get("slug")
229203
try:
230204
self._check_default_community_permission(
231205
identity,

site/kcworks/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def get_changed_fields(
192192
try:
193193
existing_value = (
194194
list(existing_data_val)[index]
195-
if isinstance(existing_data_val, (list, tuple, set))
195+
if isinstance(existing_data_val, list | tuple | set)
196196
else None
197197
)
198198
except IndexError:
@@ -246,7 +246,11 @@ def get_value_by_path(data: dict, path: str, separator: str = ".") -> Any:
246246
"""
247247
path_segments = path.split(separator)
248248
return reduce(
249-
lambda d, key: d.get(key) if isinstance(d, dict) else d[int(key)],
249+
lambda d, key: (
250+
d.get(key)
251+
if isinstance(d, dict)
252+
else (d[int(key)] if d is not None else None)
253+
),
250254
path_segments,
251255
data,
252256
)

tests/api/test_accounts.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import datetime
99
import json
1010
from collections.abc import Callable
11-
from pprint import pformat
1211
from types import SimpleNamespace
1312

1413
import pytest
@@ -189,8 +188,6 @@ def test_knowledgeCommons_account_get_user(
189188
case 2: The pre-existing KCWorks user has a different email as the IDP response
190189
case 3: The KCWorks user is already linked to an external ID
191190
"""
192-
app: Flask = running_app.app
193-
194191
if not already_linked:
195192
u: AugmentedUserFixture = user_factory(
196193
email=original_email,

tests/api/test_per_field_edit_permissions.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ def test_per_field_permissions_update_draft(
370370
),
371371
None,
372372
)
373+
running_app.app.logger.info(f"match: {match}")
374+
running_app.app.logger.info(f"error: {error}")
375+
running_app.app.logger.info(f"updated_draft: {updated_draft.get('errors')}")
373376
assert match is not None
374377
assert match == error
375378

@@ -412,31 +415,31 @@ def expected(self) -> dict: # noqa: D102
412415
"changed": {},
413416
"errors": [
414417
{
415-
"field": "access|embargo|reason",
418+
"field": "access.embargo.reason",
416419
"messages": [
417420
"You do not have permission to edit this field because the "
418421
"record is included in the test-community community. Please "
419422
"contact the community owner or manager for assistance."
420423
],
421424
},
422425
{
423-
"field": "access|embargo|active",
426+
"field": "access.embargo.active",
424427
"messages": [
425428
"You do not have permission to edit this field because the "
426429
"record is included in the test-community community. Please "
427430
"contact the community owner or manager for assistance."
428431
],
429432
},
430433
{
431-
"field": "access|files",
434+
"field": "access.files",
432435
"messages": [
433436
"You do not have permission to edit this field because the "
434437
"record is included in the test-community community. Please "
435438
"contact the community owner or manager for assistance."
436439
],
437440
},
438441
{
439-
"field": "access|embargo|until",
442+
"field": "access.embargo.until",
440443
"messages": [
441444
"You do not have permission to edit this field because the "
442445
"record is included in the test-community community. Please "
@@ -486,7 +489,7 @@ def expected(self) -> dict: # noqa: D102
486489
},
487490
"errors": [
488491
{
489-
"field": "metadata|title",
492+
"field": "metadata.title",
490493
"messages": [
491494
"You do not have permission to edit this field "
492495
"because the record is included in the test-community "
@@ -682,7 +685,7 @@ def expected(self) -> dict: # noqa: D102
682685
},
683686
"errors": [
684687
{
685-
"field": "metadata|funding|2|award|identifiers|0|identifier",
688+
"field": "metadata.funding.2.award.identifiers.0.identifier",
686689
"messages": [
687690
"You do not have permission to edit this field "
688691
"because the record is included in the test-community "
@@ -691,7 +694,7 @@ def expected(self) -> dict: # noqa: D102
691694
],
692695
},
693696
{
694-
"field": "metadata|funding|0|funder|id",
697+
"field": "metadata.funding.0.funder.id",
695698
"messages": [
696699
"You do not have permission to edit this field "
697700
"because the record is included in the test-community "
@@ -909,7 +912,7 @@ def expected(self) -> dict: # noqa: D102
909912
{
910913
"field": "parent.communities.default",
911914
"message": (
912-
"You do not have permission to remove this collection: "
915+
"You do not have permission to remove this work from "
913916
"XXXX. Please contact the collection owner or "
914917
"manager for assistance."
915918
),
@@ -954,14 +957,14 @@ def test_remove_from_community(
954957
identity, id_=record.id, data={"communities": [{"id": community.id}]}
955958
)
956959
assert processed == [
957-
{"community": p.replace("XXXX", community.title)}
960+
{"community": p.replace("XXXX", community.id)}
958961
for p in self.expected["processed"]
959962
]
960963
assert len(errors) == len(self.expected["errors"])
961964
if len(errors) > 0:
962965
assert errors[0]["message"] == self.expected["errors"][0][
963966
"message"
964-
].replace("XXXX", community.title)
967+
].replace("XXXX", community.to_dict()["metadata"]["title"])
965968
assert errors[0]["field"] == self.expected["errors"][0]["field"]
966969

967970
# Update result object

0 commit comments

Comments
 (0)