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 schema visibility/activeness update to pytest fixtures #10029

Conversation

cslzchen
Copy link
Collaborator

@cslzchen cslzchen commented Aug 18, 2022

Purpose

Move schema visibility/activeness update to pytest fixtures to fix the following errors, which was caused by a registration schema named "Election Research Preacceptance Competition" being visible/active while the tests expect it not to be. This fix is similar to what we did in #9994.

___ TestDraftRegistrationCreateWithNode.test_registration_supplement_errors ____
api_tests/nodes/views/test_node_draft_registration_list.py:453: in test_registration_supplement_errors
    name='Election Research Preacceptance Competition', active=False)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/manager.py:85: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/query.py:380: in get
    self.model._meta.object_name
E   osf.models.metaschema.DoesNotExist: RegistrationSchema matching query does not exist.

__ TestDraftRegistrationCreateWithoutNode.test_registration_supplement_errors __
api_tests/nodes/views/test_node_draft_registration_list.py:453: in test_registration_supplement_errors
    name='Election Research Preacceptance Competition', active=False)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/manager.py:85: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/query.py:380: in get
    self.model._meta.object_name
E   osf.models.metaschema.DoesNotExist: RegistrationSchema matching query does not exist.

_______ TestDraftRegistrationCreate.test_registration_supplement_errors ________
api_tests/nodes/views/test_node_draft_registration_list.py:453: in test_registration_supplement_errors
    name='Election Research Preacceptance Competition', active=False)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/manager.py:85: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/query.py:380: in get
    self.model._meta.object_name
E   osf.models.metaschema.DoesNotExist: RegistrationSchema matching query does not exist.

_________ TestRegistrationSchemaDetail.test_schemas_detail_visibility __________
api_tests/schemas/views/test_registration_schemas_detail.py:68: in test_schemas_detail_visibility
    name='Election Research Preacceptance Competition', active=False)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/manager.py:85: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/query.py:380: in get
    self.model._meta.object_name
E   osf.models.metaschema.DoesNotExist: RegistrationSchema matching query does not exist.

_______ TestDraftRegistrationCreate.test_registration_supplement_errors ________
api_tests/nodes/views/test_node_draft_registration_list.py:453: in test_registration_supplement_errors
    name='Election Research Preacceptance Competition', active=False)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/manager.py:85: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/django/db/models/query.py:380: in get
    self.model._meta.object_name
E   osf.models.metaschema.DoesNotExist: RegistrationSchema matching query does not exist.

Changes

  • Added a helper method ensure_invisible_and_inactive_schema() in osf/migrations/init.py to update invisible and inactive schemas.

  • The following fixtures is added to each tests file that fails. The fixture is not explicitly used but is called before tests are run to update the schema in the test database.

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

QA Notes

N/A

Documentation

N/A

Side Effects

N/A

Ticket

https://openscience.atlassian.net/browse/ENG-3947

@cslzchen cslzchen changed the title [Django Upgrade] [ENG-3947] Move schema visibility/activeness update to pytest fixtures. [Django Upgrade] [ENG-3947] Move schema visibility/activeness update to pytest fixtures Aug 18, 2022
@cslzchen cslzchen marked this pull request as ready for review August 18, 2022 17:57
@cslzchen cslzchen merged commit d15c88f into CenterForOpenScience:feature/django_upgrade Aug 18, 2022
mfraezz pushed a commit that referenced this pull request Oct 21, 2022
PRs:
* remove post-migrate signals from migration stream (#9964)
* move createcachetable to post migrate signal (#9944)
* [ENG-3836] Investigate waffle flags (#9950)
* [ENG-3865] Create Licenses using post-migrate signal (#9961)
* [ENG-3863] Move schema ensuring and schema blocks update to post-migrate signals (#9974)
* [ENG-3868] Move blocked email domains to post-migrate signal (#9958)
* [ENG-3866] Move citation style population out of migration stream (#9966)
* [ENG-3867] Create Storage Regions on post migration signal (#9965)
* [ENG-3836] Follow-up: Add PyYAML to Requirements (#9993)
* [ENG-3862] Move post-migrate signal out of migration stream for default providers (#9971)
* Remove unused password change view/route (#9985)
* Update import paths and fix deprecated modules for Django 3 (#9983)
* Update postgres backend and remove failover router for Django 3 (#10011)
* Move file metadata population to unit test fixtures (#9994)
* [Django Upgrade] Fix one sub-query slicing issue (#10012)
* [Django Upgrade] Upgrade django-elasticsearch-metrics (#10021)
* [Django Upgrade] Replace M2M direct assignment  (#10010)
* [Django Upgrade] Upgrade markdown and mdx_del_ins (#9984)
* [Django Upgrade] Move schema activeness/visibility update to pytest fixtures (#10029)

Commits:
* Remove osf migrations
* Remove addon migrations
* Init migrations - osf
* Init migrations - addons
* Fix migration for NotableEmailDomain
* Fix circular import with built-in admin migrations
* Add a RunSQL migration to update indexes
* Upgrade django to 3.2.15 (and related dependencies)
* Make fields defined on typedmodels subclasses nullable
* Add required on_delete=CASCADE (default) to FKs missing it
* Fix django CORS whitelist settings due to origin definition update
* Add/Enable missing templates and middlewares in api settings
* Comment out admin permissions that clash with built-in "view" ones
* Add migrations for django upgrade base fixes
* Fix system check warnings for django admin
* Fix django cache table creation
* Enable django.contrib.sessions.middleware.SessionMiddleware
* Use default truthy and falsy values from upgraded DRF 3.13.1
* Use JsonField from django.db.models and django.forms
* Fix session cookie encoding/decoding by using ensure_str()
* Use prefetch instead of Django include
* Fix CORS for ORIGINS_WHITELIST
* Rename auto generated migration for django3 upgrade fixes
* Remove QuickFile check from get_serializer_class for FileDetail view
* Add registration_schema to DraftRegistrationDetailSerializer
* Add id to DraftRegistrationDetailSerializer
* Fix middleware order and replace deprecated staticfiles with static
* Fix and rework from_db_value & to_python for EncryptedJSONField
* Fix admin login failure for django upgrade
* Wrap generated keen_read_key with ensure_str
* Clear cached storage region property when creating a new version
* Do not notify in set_password() when creating a test user
* Fix RegistrationFactory for django3 upgrade
* Remove unused update_version_metadata in file node and update tests
* Remove tests for django-include
* Remove EGAP backfill command and tests
* Set DEFAULT_AUTO_FIELD to django.db.models.AutoField (default value)
* Replace deprecated NullBooleanField + add migrations
* Replace deprecated url() with re_path() for api
* Replace deprecated url() with re_path() for admin
* Fix missing or insufficient permission test for admin preprints view
* Fix admin user view tests by using HTTP response headers object
* Fix duplicate view_node permissions in node and instn view tests
* Rework refresh_from_db() to reload GFKs
* Fix visible contributor query
* Fix handle_archive_fail and its tests
* Use a different schema to fix tests failure due to django3 upgrade
* Update URLs for URL Validation tests with Django 3
* Improve to_internal_value() in NodeRelationshipField
* Add alt fixtures to prevent both siblings & parent/child conflicts
* Fix linked_by_nodes in node related counts test
* Fix bugged NullBooleanField -> BooleanField migration
* Re-make migrations for django3 upgrade and merge them into one

Co-authored-by: Longze Chen <[email protected]>
Co-authored-by: John Tordoff <[email protected]>
Co-authored-by: Jon Walz <[email protected]>
@cslzchen cslzchen deleted the schema-update-inactive-invisible branch October 9, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant