Skip to content

Commit

Permalink
[Django Upgrade] Move schema activeness/visibility update to pytest f…
Browse files Browse the repository at this point in the history
…ixtures (#10029)
  • Loading branch information
cslzchen committed Oct 20, 2022
1 parent 7a67198 commit 9977a37
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
from api.base.settings.defaults import API_BASE

from osf.migrations import ensure_invisible_and_inactive_schema
from osf.models import DraftRegistration, NodeLicense, RegistrationProvider, Institution
from osf_tests.factories import (
RegistrationFactory,
Expand All @@ -20,6 +21,12 @@

from website import mails, settings


@pytest.fixture(autouse=True)
def invisible_and_inactive_schema():
return ensure_invisible_and_inactive_schema()


@pytest.mark.django_db
class TestDraftRegistrationListNewWorkflow(TestDraftRegistrationList):
@pytest.fixture()
Expand Down
7 changes: 7 additions & 0 deletions api_tests/nodes/views/test_node_draft_registration_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from api.base.settings.defaults import API_BASE
from framework.auth.core import Auth
from osf.migrations import ensure_invisible_and_inactive_schema
from osf.models import RegistrationSchema, RegistrationProvider
from osf_tests.factories import (
ProjectFactory,
Expand All @@ -20,6 +21,12 @@
OPEN_ENDED_SCHEMA_VERSION = 3
SCHEMA_VERSION = 2


@pytest.fixture(autouse=True)
def invisible_and_inactive_schema():
return ensure_invisible_and_inactive_schema()


@pytest.mark.django_db
class DraftRegistrationTestCase:

Expand Down
8 changes: 8 additions & 0 deletions api_tests/schemas/views/test_registration_schemas_detail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from api.base.settings.defaults import API_BASE
from osf.migrations import ensure_invisible_and_inactive_schema
from osf.models import RegistrationSchema
from osf_tests.factories import (
AuthUserFactory,
Expand All @@ -10,10 +11,12 @@

SCHEMA_VERSION = 2


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


@pytest.fixture()
def schema():
return RegistrationSchema.objects.filter(
Expand All @@ -22,6 +25,11 @@ def schema():
).first()


@pytest.fixture(autouse=True)
def invisible_and_inactive_schema():
return ensure_invisible_and_inactive_schema()


class TestDeprecatedMetaSchemaDetail:
def test_deprecated_metaschemas_routes(self, app, user, schema):
# test base /metaschemas/ GET with min version
Expand Down
17 changes: 16 additions & 1 deletion osf/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def ensure_default_storage_region():


def ensure_datacite_file_schema():
''' Test use only '''
""" Test use only """
from osf.models import FileMetadataSchema
with open('osf/metadata/schemas/datacite.json') as f:
jsonschema = json.load(f)
Expand All @@ -246,3 +246,18 @@ def ensure_datacite_file_schema():
'schema': jsonschema
}
)


def ensure_invisible_and_inactive_schema():
""" Test use only """
from osf.models import RegistrationSchema
v2_inactive_schema = [
'EGAP Project',
'OSF Preregistration',
'Confirmatory - General',
'RIDIE Registration - Study Complete',
'RIDIE Registration - Study Initiation',
]
v2_inactive_schema = v2_inactive_schema + ['Election Research Preacceptance Competition']
RegistrationSchema.objects.filter(name__in=v2_inactive_schema).update(visible=False)
RegistrationSchema.objects.filter(name__in=v2_inactive_schema).update(active=False)

0 comments on commit 9977a37

Please sign in to comment.