-
Notifications
You must be signed in to change notification settings - Fork 10
feat(rdm.migration): Configurable auto-adding secondary community #544
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
Open
sakshamarora1
wants to merge
1
commit into
CERNDocumentServer:master
Choose a base branch
from
sakshamarora1:feat/add_publications_to_cern_research
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.
Open
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,145 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2026 CERN. | ||
| # | ||
| # CDS-RDM is free software; you can redistribute it and/or modify it under | ||
| # the terms of the MIT License; see LICENSE file for more details. | ||
|
|
||
| """Tests for auto-inclusion in the CERN Research community.""" | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from cds_migrator_kit.errors import MissingConfiguration | ||
| from cds_migrator_kit.rdm.records.transform.config import CDS_CERN_SCIENTIFIC_RESOURCE_TYPES | ||
| from cds_migrator_kit.rdm.records.transform.transform import CDSToRDMRecordTransform | ||
|
|
||
|
|
||
| def _test_record( | ||
| access="public", | ||
| resource_type="publication-preprint", | ||
| communities=[], | ||
| recid="123456", | ||
| ): | ||
| """Build a minimal CDSToRDMRecordEntry.transform() output for community tests.""" | ||
| metadata = { | ||
| "title": "Test record", | ||
| "publication_date": "2020-01-01", | ||
| } | ||
| if resource_type is not None: | ||
| metadata["resource_type"] = {"id": resource_type} | ||
|
|
||
| return { | ||
| "recid": recid, | ||
| "access": access, | ||
| "communities": communities, | ||
| "json": { | ||
| "files": {"enabled": False}, | ||
| "metadata": metadata, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def transform(tmp_path, community): | ||
| """Transform instance with a collection community configured.""" | ||
| return CDSToRDMRecordTransform( | ||
| files_dump_dir=tmp_path, | ||
| missing_users=tmp_path, | ||
| communities_ids=[str(community.id)], | ||
| migration_logger=MagicMock(), | ||
| ) | ||
|
|
||
|
|
||
| class TestCommunitiesIds: | ||
| """Test CDSToRDMRecordTransform._communities_ids().""" | ||
|
|
||
| def test_adds_scientific_community_for_public_research_test_record( | ||
| self, transform, community, cern_scientific_community | ||
| ): | ||
| """Public research records are included in the CERN Scientific community.""" | ||
| result = transform._communities_ids({}, _test_record()) | ||
|
|
||
| assert result == { | ||
| "ids": [str(community.id), str(cern_scientific_community.id)], | ||
| "default": str(community.id), | ||
| } | ||
|
|
||
| def test_keep_collection_community_as_default( | ||
| self, transform, community, cern_scientific_community | ||
| ): | ||
| """Collection community remains the default when CERN Scientific community is added.""" | ||
| result = transform._communities_ids( | ||
| {}, | ||
| _test_record(communities=["test-community"]), | ||
| ) | ||
|
|
||
| assert result["default"] == str(community.id) | ||
| assert result["ids"] == [ | ||
| str(community.id), | ||
| "test-community", | ||
| str(cern_scientific_community.id), | ||
| ] | ||
|
|
||
| @pytest.mark.parametrize("resource_type", CDS_CERN_SCIENTIFIC_RESOURCE_TYPES) | ||
| def test_research_resource_types( | ||
| self, transform, cern_scientific_community, resource_type | ||
| ): | ||
| """All configured public research resource types trigger inclusion.""" | ||
| result = transform._communities_ids( | ||
| {}, _test_record(resource_type=resource_type) | ||
| ) | ||
|
|
||
| assert str(cern_scientific_community.id) in result["ids"] | ||
| assert cern_scientific_community.id != result["default"] | ||
|
|
||
| def test_skip_restricted_test_record( | ||
| self, transform, community, cern_scientific_community | ||
| ): | ||
| """Restricted records are not included in the CERN Research community.""" | ||
| result = transform._communities_ids({}, _test_record(access="restricted")) | ||
|
|
||
| assert result == { | ||
| "ids": [str(community.id)], | ||
| "default": str(community.id), | ||
| } | ||
|
|
||
| def test_skip_non_research_resource_type( | ||
| self, transform, community, cern_scientific_community | ||
| ): | ||
| """Non-research resource types are not included in the CERN Scientific community.""" | ||
| result = transform._communities_ids({}, _test_record(resource_type="other")) | ||
|
|
||
| assert result == { | ||
| "ids": [str(community.id)], | ||
| "default": str(community.id), | ||
| } | ||
|
|
||
| def test_skip_when_stream_is_restricted( | ||
| self, tmp_path, community, cern_scientific_community | ||
| ): | ||
| """Records on restricted migration streams are not included in the CERN Scientific community.""" | ||
| transform = CDSToRDMRecordTransform( | ||
| files_dump_dir=tmp_path, | ||
| missing_users=tmp_path, | ||
| communities_ids=[str(community.id)], | ||
| restricted=True, | ||
| migration_logger=MagicMock(), | ||
| ) | ||
|
|
||
| result = transform._communities_ids({}, _test_record()) | ||
|
|
||
| assert result == { | ||
| "ids": [str(community.id)], | ||
| "default": str(community.id), | ||
| } | ||
|
|
||
| def test_raise_when_cern_scientific_community_not_configured( | ||
| self, test_app, transform, community | ||
| ): | ||
| """No CERN Scientific community is added when config is unset.""" | ||
| test_app.config["CDS_CERN_SCIENTIFIC_COMMUNITY_ID"] = None | ||
|
|
||
| with pytest.raises(MissingConfiguration): | ||
| transform._communities_ids({}, _test_record()) |
Oops, something went wrong.
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.
can you add a failsafe like in the other PRs to check if the variable is set? does it fail silently now? maybe it makes sense to add this case to tests