# Path: osf_tests/factories.py
# def get_default_metaschema():
#     """This needs to be a method so it gets called after the test database is set up"""
#     return models.RegistrationSchema.objects.first()
# 
# class DraftRegistrationFactory(DjangoModelFactory):
#     class Meta:
#         model = models.DraftRegistration
# 
#     @classmethod
#     def _create(cls, *args, **kwargs):
#         title = kwargs.pop('title', None)
#         initiator = kwargs.get('initiator', None)
#         description = kwargs.pop('description', None)
#         branched_from = kwargs.get('branched_from', None)
#         registration_schema = kwargs.get('registration_schema')
#         registration_metadata = kwargs.get('registration_metadata')
#         provider = kwargs.get('provider')
#         branched_from_creator = branched_from.creator if branched_from else None
#         initiator = initiator or branched_from_creator or kwargs.get('user', None) or kwargs.get('creator', None) or UserFactory()
#         registration_schema = registration_schema or get_default_metaschema()
#         registration_metadata = registration_metadata or {}
#         provider = provider or models.RegistrationProvider.get_default()
#         provider.schemas.add(registration_schema)
#         draft = models.DraftRegistration.create_from_node(
#             node=branched_from,
#             user=initiator,
#             schema=registration_schema,
#             data=registration_metadata,
#             provider=provider,
#         )
#         if title:
#             draft.title = title
#         if description:
#             draft.description = description
#         draft.registration_responses = draft.flatten_registration_metadata()
#         draft.save()
#         return draft


import mock
import pytest
from addons.wiki.models import WikiVersion
from django.core.exceptions import ValidationError
from django.utils import timezone
from framework.auth.core import Auth
from framework.exceptions import PermissionsError
from nose.tools import assert_raises
from osf.models import Node, Registration, Sanction, RegistrationSchema, NodeLog
from addons.wiki.models import WikiPage
from osf.utils.permissions import ADMIN
from osf.registrations.utils import get_registration_provider_submissions_url
from website import settings
from . import factories
from .utils import assert_datetime_equal, mock_archive
from osf_tests.factories import get_default_metaschema, DraftRegistrationFactory
from addons.wiki.tests.factories import WikiFactory, WikiVersionFactory
from api.providers.workflows import Workflows
from osf.migrations import update_provider_auth_groups
from osf.models.action import RegistrationAction
from osf_tests.management_commands.test_migration_registration_responses import (
    prereg_registration_responses,
    prereg_registration_metadata_built,
    veer_registration_responses,
    veer_condensed
)
from osf.utils.workflows import (
    RegistrationModerationStates,
    RegistrationModerationTriggers,
    ApprovalStates
)

        node.add_affiliated_institution(institution, user=user)
        node.save()

        registration = factories.RegistrationFactory(project=node)
        assert (
            set(registration.affiliated_institutions.values_list('id', flat=True)) ==
            set(node.affiliated_institutions.values_list('id', flat=True))
        )

    def test_registration_of_project_with_no_wiki_pages(self, registration):
        assert WikiPage.objects.get_wiki_pages_latest(registration).exists() is False
        assert registration.wikis.all().exists() is False
        assert registration.wiki_private_uuids == {}

    @mock.patch('website.project.signals.after_create_registration')
    def test_registration_clones_project_wiki_pages(self, mock_signal, project, user):
        project = factories.ProjectFactory(creator=user, is_public=True)
        wiki_page = WikiFactory(
            user=user,
            node=project,
        )
        wiki = WikiVersionFactory(
            wiki_page=wiki_page,
        )
        current_wiki = WikiVersionFactory(
            wiki_page=wiki_page,
            identifier=2
        )
        draft_reg = factories.DraftRegistrationFactory(branched_from=project)

# Path: osf_tests/factories.py
# def get_default_metaschema():
#     """This needs to be a method so it gets called after the test database is set up"""
#     return models.RegistrationSchema.objects.first()
# 
# class DraftRegistrationFactory(DjangoModelFactory):
#     class Meta:
#         model = models.DraftRegistration
# 
#     @classmethod
#     def _create(cls, *args, **kwargs):
#         title = kwargs.pop('title', None)
#         initiator = kwargs.get('initiator', None)
#         description = kwargs.pop('description', None)
#         branched_from = kwargs.get('branched_from', None)
#         registration_schema = kwargs.get('registration_schema')
#         registration_metadata = kwargs.get('registration_metadata')
#         provider = kwargs.get('provider')
#         branched_from_creator = branched_from.creator if branched_from else None
#         initiator = initiator or branched_from_creator or kwargs.get('user', None) or kwargs.get('creator', None) or UserFactory()
#         registration_schema = registration_schema or get_default_metaschema()
#         registration_metadata = registration_metadata or {}
#         provider = provider or models.RegistrationProvider.get_default()
#         provider.schemas.add(registration_schema)
#         draft = models.DraftRegistration.create_from_node(
#             node=branched_from,
#             user=initiator,
#             schema=registration_schema,
#             data=registration_metadata,
#             provider=provider,
#         )
#         if title:
#             draft.title = title
#         if description:
#             draft.description = description
#         draft.registration_responses = draft.flatten_registration_metadata()
#         draft.save()
#         return draft


# Path: osf_tests/test_registrations.py
import mock
import pytest
from addons.wiki.models import WikiVersion
from django.core.exceptions import ValidationError
from django.utils import timezone
from framework.auth.core import Auth
from framework.exceptions import PermissionsError
from nose.tools import assert_raises
from osf.models import Node, Registration, Sanction, RegistrationSchema, NodeLog
from addons.wiki.models import WikiPage
from osf.utils.permissions import ADMIN
from osf.registrations.utils import get_registration_provider_submissions_url
from website import settings
from . import factories
from .utils import assert_datetime_equal, mock_archive
from osf_tests.factories import get_default_metaschema, DraftRegistrationFactory
from addons.wiki.tests.factories import WikiFactory, WikiVersionFactory
from api.providers.workflows import Workflows
from osf.migrations import update_provider_auth_groups
from osf.models.action import RegistrationAction
from osf_tests.management_commands.test_migration_registration_responses import (
    prereg_registration_responses,
    prereg_registration_metadata_built,
    veer_registration_responses,
    veer_condensed
)
from osf.utils.workflows import (
    RegistrationModerationStates,
    RegistrationModerationTriggers,
    ApprovalStates
)


        node.add_affiliated_institution(institution, user=user)
        node.save()

        registration = factories.RegistrationFactory(project=node)
        assert (
            set(registration.affiliated_institutions.values_list('id', flat=True)) ==
            set(node.affiliated_institutions.values_list('id', flat=True))
        )

    def test_registration_of_project_with_no_wiki_pages(self, registration):
        assert WikiPage.objects.get_wiki_pages_latest(registration).exists() is False
        assert registration.wikis.all().exists() is False
        assert registration.wiki_private_uuids == {}

    @mock.patch('website.project.signals.after_create_registration')
    def test_registration_clones_project_wiki_pages(self, mock_signal, project, user):
        project = factories.ProjectFactory(creator=user, is_public=True)
        wiki_page = WikiFactory(
            user=user,
            node=project,
        )
        wiki = WikiVersionFactory(
            wiki_page=wiki_page,
        )
        current_wiki = WikiVersionFactory(
            wiki_page=wiki_page,
            identifier=2
        )
        draft_reg = factories.DraftRegistrationFactory(branched_from=project)

        registration = project.register_node(get_default_metaschema(), Auth(user), draft_reg, None)