Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 146 additions & 1 deletion .github/scripts/setup_test_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os
from django.utils import timezone
from osf.models import OSFUser, Node, Institution
from framework.auth import Auth
from osf.models import OSFUser, Node, Institution, CollectionProvider, Collection, RegistrationProvider, RegistrationSchema, PreprintProvider, Preprint
from osf.models.registrations import DraftRegistration
from website import settings

WIKI_ENABLED = os.environ.get('WIKI_ENABLED', 'false').lower() == 'true'
INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED = os.environ.get('INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED', 'false').lower() == 'true'
MAPCORE_GROUP_ENABLED = os.environ.get('MAPCORE_GROUP_ENABLED', 'false').lower() == 'true'

INSTITUTION_NAME = 'Virginia Tech [Test]'
Expand Down Expand Up @@ -79,6 +83,17 @@
'password': 'testpass666',
'skip_project': True,
},
{
'username': '[email protected]',
'fullname': 'Test User 7',
'given_name': 'Test',
'family_name': 'User 7',
'given_name_ja': 'テスト',
'family_name_ja': 'ユーザー7',
'password': 'testpass123',
'is_superuser': True,
'skip_project': True,
},
]

def create_rdmuserkey(user):
Expand Down Expand Up @@ -288,3 +303,133 @@ def create_rdmuserkey(user):
print(f"Affiliated {user.username} with {inst.name}")
else:
print(f"User {user.username} already affiliated with {inst.name}")

# Create provider/registration/preprint/collection data for institutional admin authorization CI tests
# Only executed when running the "admin" test group (INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED=true)
if INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED:
user = OSFUser.objects.filter(username='[email protected]').first()
if user is None:
raise RuntimeError('Provider setup failed: user not found: [email protected]')

print(f"[email protected]: {user._id}")

project = user.nodes.filter(category='project', is_deleted=False).first()
if project is None:
raise RuntimeError('Provider setup failed: project of user not found: [email protected]')

# Create registration provider and link to a registration
REGISTRATION_PROVIDER_ID = 'osf'
REGISTRATION_PROVIDER_NAME = 'OSF Registries'

if not RegistrationProvider.objects.filter(_id=REGISTRATION_PROVIDER_ID).exists():
reg_provider = RegistrationProvider(
_id=REGISTRATION_PROVIDER_ID,
name=REGISTRATION_PROVIDER_NAME,
)
reg_provider._creator = user
reg_provider.save()
print(f"Created RegistrationProvider: {REGISTRATION_PROVIDER_ID}")
else:
reg_provider = RegistrationProvider.objects.get(_id=REGISTRATION_PROVIDER_ID)
print(f"RegistrationProvider already exists: {REGISTRATION_PROVIDER_ID}")

if reg_provider.registrations.count() == 0:
schema = RegistrationSchema.objects.filter(active=True).first()
if schema is None:
schema, created = RegistrationSchema.objects.get_or_create(
name='Test Schema',
schema_version=1,
defaults={
'schema': {'pages': [], 'name': 'Test Schema'},
'active': True,
}
)
if created:
print(f"Created RegistrationSchema: {schema.name} v{schema.schema_version}")
else:
schema.active = True
schema.save()
print(f"Activated existing RegistrationSchema: {schema.name} v{schema.schema_version}")
if not reg_provider.schemas.filter(id=schema.id).exists():
reg_provider.schemas.add(schema)
print(f"Linked schema '{schema.name}' to provider '{REGISTRATION_PROVIDER_ID}'")
auth = Auth(user=user)
original_archiver_setting = settings.ENABLE_ARCHIVER
settings.ENABLE_ARCHIVER = False
try:
draft = DraftRegistration.create_from_node(
user=user,
schema=schema,
node=project,
provider=reg_provider,
)
registration = draft.register(auth=auth, save=True)
print(f"Created Registration: {registration._id} linked to provider: {REGISTRATION_PROVIDER_ID}")
finally:
settings.ENABLE_ARCHIVER = original_archiver_setting
else:
print(f"Registration already linked to provider: {REGISTRATION_PROVIDER_ID}")

# Create preprint provider and link to a preprint
PREPRINT_PROVIDER_ID = 'osf'
PREPRINT_PROVIDER_NAME = 'Open Science Framework'

if not PreprintProvider.objects.filter(_id=PREPRINT_PROVIDER_ID).exists():
preprint_provider = PreprintProvider(
_id=PREPRINT_PROVIDER_ID,
name=PREPRINT_PROVIDER_NAME,
)
preprint_provider._creator = user
preprint_provider.save()
print(f"Created PreprintProvider: {PREPRINT_PROVIDER_ID}")
else:
preprint_provider = PreprintProvider.objects.get(_id=PREPRINT_PROVIDER_ID)
print(f"PreprintProvider already exists: {PREPRINT_PROVIDER_ID}")

if preprint_provider.preprints.count() == 0:
preprint = Preprint(
provider=preprint_provider,
title='Test Preprint',
creator=user,
description='Test preprint for setup',
is_public=True,
)
preprint.save()
print(f"Created Preprint: {preprint._id} linked to provider: {PREPRINT_PROVIDER_ID}")
else:
print(f"Preprint already linked to provider: {PREPRINT_PROVIDER_ID}")

# Create collection provider and add a project submission
COLLECTION_PROVIDER_ID = 'idtest'
COLLECTION_PROVIDER_NAME = 'OSF Collection'
if not CollectionProvider.objects.filter(_id=COLLECTION_PROVIDER_ID).exists():
provider = CollectionProvider(
_id=COLLECTION_PROVIDER_ID,
name=COLLECTION_PROVIDER_NAME,
)
provider._creator = user
provider.save()
print(f"Created CollectionProvider: {COLLECTION_PROVIDER_ID}")
else:
provider = CollectionProvider.objects.get(_id=COLLECTION_PROVIDER_ID)
print(f"CollectionProvider already exists: {COLLECTION_PROVIDER_ID}")

if not provider.primary_collection:
print(f"primary_collection not found for {COLLECTION_PROVIDER_ID}, creating manually...")
c = Collection(
title=f"{provider.name}'s Collection",
creator=user,
provider=provider,
is_promoted=True,
is_public=True,
)
c.save()
provider.primary_collection = c
provider.save()
print(f"Created primary_collection for {COLLECTION_PROVIDER_ID}")

if not provider.primary_collection.collectionsubmission_set.filter(guid=project.guids.first()).exists():
provider.primary_collection.collect_object(project, user)
print(f"Added project {project._id} to collection {COLLECTION_PROVIDER_ID}")
else:
print(f"Project {project._id} already in collection {COLLECTION_PROVIDER_ID}")
64 changes: 61 additions & 3 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-metadata
display_name: "User Tests (Metadata)"
Expand All @@ -211,6 +212,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: admin
display_name: "Admin Tests"
Expand All @@ -225,6 +227,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
exclude_notebooks: |
テスト手順-管理者機能-ログイン可否設定.ipynb
Expand Down Expand Up @@ -269,6 +272,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: migration-from-20250906-weko
display_name: "Migration Test from 20250906 (WEKO)"
Expand Down Expand Up @@ -297,6 +301,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-minio
display_name: "User Tests (MinIO)"
Expand All @@ -314,6 +319,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: admin-minio
display_name: "Admin Tests (MinIO)"
Expand All @@ -330,6 +336,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-weko-direct
display_name: "User Tests (WEKO Direct)"
Expand All @@ -346,6 +353,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-weko-workflow
display_name: "User Tests (WEKO Workflow)"
Expand All @@ -362,6 +370,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-jupyterhub
display_name: "User Tests (JupyterHub)"
Expand All @@ -377,6 +386,7 @@ jobs:
jupyterhub_enabled: true
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-workflow-roles
display_name: "User Tests (Flowable Roles)"
Expand All @@ -393,6 +403,7 @@ jobs:
flowable_enabled: true
workflow_test_mode: roles
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-workflow-forms
display_name: "User Tests (Flowable Forms)"
Expand All @@ -409,6 +420,7 @@ jobs:
flowable_enabled: true
workflow_test_mode: forms
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-workflow-batch
display_name: "User Tests (Flowable Batch)"
Expand All @@ -426,6 +438,7 @@ jobs:
workflow_test_mode: batch
workflow_batch_project_count: 50
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-wiki
display_name: "User Tests (Wiki)"
Expand All @@ -441,6 +454,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: true
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-metadata-mibyo-db
display_name: "User Tests (Mibyo DB)"
Expand All @@ -457,6 +471,7 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: false
- name: user-mapcore-group
display_name: "User Tests (Mapcore Group)"
Expand All @@ -472,7 +487,25 @@ jobs:
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: false
mapcore_group_enabled: true
- name: admin-institutional-admin-authorization
display_name: "Admin Tests (Institutional Admin Authorization)"
include_admin: true
skip_admin: true
skip_metadata: true
skip_default_storage: true
skip_login: true
skip_130mb_upload: true
minio_enabled: false
s3compatsigv4_institutional_storage: false
weko_enabled: false
mibyo_db_enabled: false
jupyterhub_enabled: false
flowable_enabled: false
wiki_enabled: false
institutional_admin_authorization_enabled: true
mapcore_group_enabled: false
name: E2E ${{ matrix.test-group.display_name }}
env:
MINIO_ENABLED: ${{ matrix.test-group.minio_enabled == true && 'true' || 'false' }}
Expand All @@ -483,6 +516,7 @@ jobs:
FLOWABLE_ENABLED: ${{ matrix.test-group.flowable_enabled == true && 'true' || 'false' }}
MIBYO_DB_ENABLED: ${{ matrix.test-group.mibyo_db_enabled == true && 'true' || 'false' }}
WIKI_ENABLED: ${{ (matrix.test-group.wiki_enabled == true || github.event.inputs.enable_wiki == 'true') && 'true' || 'false' }}
INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED: ${{ matrix.test-group.institutional_admin_authorization_enabled == true && 'true' || 'false' }}
MAPCORE_GROUP_ENABLED: ${{ matrix.test-group.mapcore_group_enabled == true && 'true' || 'false' }}
MINIO_ROOT_USER: e2eadmin
MINIO_ROOT_PASSWORD: e2epassword123
Expand Down Expand Up @@ -817,7 +851,7 @@ jobs:
docker cp ${{ github.workspace }}/e2e-tests/.github/scripts/setup_test_data.py "$(docker-compose ps -q web)":/tmp/setup_test_data.py

# Create test data that will be migrated
docker-compose exec -T -e WIKI_ENABLED="${WIKI_ENABLED}" -e MAPCORE_GROUP_ENABLED="${MAPCORE_GROUP_ENABLED}" web bash -c "python3 manage.py shell < /tmp/setup_test_data.py"
docker-compose exec -T -e WIKI_ENABLED="${WIKI_ENABLED}" -e MAPCORE_GROUP_ENABLED="${MAPCORE_GROUP_ENABLED}" -e INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED="${INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED}" web bash -c "python3 manage.py shell < /tmp/setup_test_data.py"

echo "Migration source test data created"

Expand Down Expand Up @@ -1361,7 +1395,7 @@ jobs:
docker cp ${{ github.workspace }}/e2e-tests/.github/scripts/setup_test_data.py "$(docker-compose ps -q web)":/tmp/setup_test_data.py

# Execute the script and capture project IDs
docker-compose exec -T -e WIKI_ENABLED="${WIKI_ENABLED}" -e MAPCORE_GROUP_ENABLED="${MAPCORE_GROUP_ENABLED}" web bash -c "python3 manage.py shell < /tmp/setup_test_data.py" | tee /tmp/setup_output.txt
docker-compose exec -T -e WIKI_ENABLED="${WIKI_ENABLED}" -e MAPCORE_GROUP_ENABLED="${MAPCORE_GROUP_ENABLED}" -e INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED="${INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED}" web bash -c "python3 manage.py shell < /tmp/setup_test_data.py" | tee /tmp/setup_output.txt

# Extract project IDs and names from output
PROJECT_ID_1=$(grep "[email protected]:" /tmp/setup_output.txt | cut -d' ' -f2)
Expand All @@ -1376,7 +1410,7 @@ jobs:
echo "PROJECT_ID_2: ${PROJECT_ID_2}"
exit 1
fi

# Export for later steps
echo "PROJECT_ID_1=${PROJECT_ID_1}" >> $GITHUB_ENV
echo "PROJECT_ID_2=${PROJECT_ID_2}" >> $GITHUB_ENV
Expand All @@ -1387,6 +1421,16 @@ jobs:
echo " testuser1: ${PROJECT_ID_1} - ${PROJECT_NAME_1}"
echo " testuser2: ${PROJECT_ID_2} - ${PROJECT_NAME_2}"

# Extract user guid from output (only printed when INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED=true)
if [ "${INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED}" = "true" ]; then
USER_GUID=$(grep "[email protected]:" /tmp/setup_output.txt | cut -d' ' -f2)
if [ -z "${USER_GUID}" ]; then
echo "Error: Failed to fetch user GUID for [email protected]" >&2
exit 1
fi
echo "USER_GUID=${USER_GUID}" >> $GITHUB_ENV
fi

- name: Register e-Rad data
working-directory: RDM-osf.io
run: |
Expand Down Expand Up @@ -1419,6 +1463,8 @@ jobs:
idp_name_integrated_admin: 'FakeCAS'
idp_username_integrated_admin: '[email protected]'
idp_password_integrated_admin: 'testpass123'
idp_username_integrated_admin_2: '[email protected]'
idp_password_integrated_admin_2: 'testpass123'
idp_name_institutional_admin: 'FakeCAS'
idp_username_institutional_admin: '[email protected]'
idp_password_institutional_admin: 'testpass789'
Expand Down Expand Up @@ -1476,10 +1522,22 @@ jobs:
mibyo_db_enabled: ${{ matrix.test-group.mibyo_db_enabled == true }}
enable_1gb_file_upload: false
skip_autofill: ${{ matrix.test-group.skip_autofill == true }}
institutional_admin_authorization_enabled: ${{ matrix.test-group.institutional_admin_authorization_enabled == true }}
storages_oauth: []
mapcore_group_enabled: ${{ matrix.test-group.mapcore_group_enabled == true }}
EOF

if [ "${INSTITUTIONAL_ADMIN_AUTHORIZATION_ENABLED}" = "true" ]; then
cat >> base_ci.config.yaml <<'EOF'
user_guid: '${{ env.USER_GUID }}'
user_name: '[email protected]'
integrated_admin_user_name: '[email protected]'
registration_provider_name: 'OSF Registries'
preprint_provider_name: 'Open Science Framework'
collection_provider_name: 'OSF Collection'
EOF
fi

args=(ci.config.yaml base_ci.config.yaml)
if [ "${MINIO_ENABLED}" = "true" ]; then
args+=(--minio)
Expand Down
Loading
Loading