Skip to content
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

[Django Upgrade] [ENG-3947] Move file metadata population to unit test fixtures #9994

Merged
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
11 changes: 11 additions & 0 deletions api_tests/files/views/test_file_metadata_record_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@
PreprintFactory,
)

from osf.migrations import ensure_datacite_file_schema


@pytest.fixture(autouse=True)
def datacite_file_schema():
return ensure_datacite_file_schema()


@pytest.fixture()
def user():
return AuthUserFactory()


@pytest.fixture()
def preprint(user):
return PreprintFactory(creator=user)


@pytest.fixture()
def preprint_record(user, preprint):
primary_file = preprint.primary_file
Expand Down Expand Up @@ -99,6 +109,7 @@ def test_preprint_file_metadata_record(self, app, user, preprint_record, unpubli
assert res.status_code == 200
assert res.json['data']['id'] == unpublished_preprint_record._id


@pytest.mark.django_db
class TestFileMetadataRecordUpdate:

Expand Down
8 changes: 8 additions & 0 deletions api_tests/files/views/test_file_metadata_record_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
ProjectFactory
)

from osf.migrations import ensure_datacite_file_schema


@pytest.fixture(autouse=True)
def datacite_file_schema():
return ensure_datacite_file_schema()


@pytest.mark.django_db
class TestFileMetadataRecordDownload:

Expand Down
7 changes: 7 additions & 0 deletions api_tests/schemas/views/test_file_metadata_schema_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
AuthUserFactory,
)

from osf.migrations import ensure_datacite_file_schema


@pytest.fixture(autouse=True)
def datacite_file_schema():
return ensure_datacite_file_schema()


@pytest.mark.django_db
class TestFileMetadataSchemaDetail:
Expand Down
1 change: 0 additions & 1 deletion osf/migrations/0136_add_datacite_file_metadata_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(add_datacite_schema, remove_datacite_schema)
]
4 changes: 1 addition & 3 deletions osf/migrations/0137_add_fm_record_to_osfstorage_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,4 @@ class Migration(migrations.Migration):
('osf', '0136_add_datacite_file_metadata_schema'),
]

operations = [
migrations.RunPython(add_records_to_files_sql, remove_records_from_files),
]
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
operations = []
16 changes: 16 additions & 0 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import json
import logging

from django.apps import apps
Expand Down Expand Up @@ -230,3 +231,18 @@ def ensure_default_storage_region():
'waterbutler_url': osf_settings.WATERBUTLER_URL
}
)


def ensure_datacite_file_schema():
''' Test use only '''
from osf.models import FileMetadataSchema
with open('osf/metadata/schemas/datacite.json') as f:
jsonschema = json.load(f)
_, created = FileMetadataSchema.objects.get_or_create(
_id='datacite',
schema_version=1,
defaults={
'name': 'datacite',
'schema': jsonschema
}
)
8 changes: 8 additions & 0 deletions osf_tests/test_file_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@
from website.settings import DOI_FORMAT, DATACITE_PREFIX
from website.project.licenses import set_license
from osf.models import FileMetadataSchema, NodeLicense, NodeLog
from osf.migrations import ensure_datacite_file_schema
from osf_tests.factories import ProjectFactory, SubjectFactory, AuthUserFactory
from osf.utils.permissions import READ
from api_tests.utils import create_test_file


@pytest.fixture(autouse=True)
def datacite_file_schema():
return ensure_datacite_file_schema()


@pytest.fixture()
def node():
return ProjectFactory()


@pytest.fixture()
def osf_file(node):
return create_test_file(target=node, user=node.creator)


def inject_placeholder_doi(json_data):
# the OSF cannot currently issue DOIs for a file, which is required for datacite schema validation.
# Manually add a placeholder in tests for validation until we handle this better.
Expand Down