# Path: osf/models/registration_bulk_upload_job.py
# class JobState(IntEnum):
#     """Defines the six states of registration bulk upload jobs.
#     """
# 
#     PENDING = 0  # Database preparation is in progress
#     INITIALIZED = 1  # Database preparation has been finished and is ready to be picked up
#     PICKED_UP = 2  # Registration creation is in progress
#     DONE_FULL = 3  # All (draft) registrations have been successfully created
#     DONE_PARTIAL = 4  # Some (draft) registrations have failed the creation creation process
#     DONE_ERROR = 5  # All (draft) registrations have failed
# 
# Path: osf_tests/factories.py
# class UserFactory(DjangoModelFactory):
#     # TODO: Change this to only generate long names and see what breaks
#     fullname = factory.Sequence(lambda n: 'Freddie Mercury{0}'.format(n))
# 
#     username = factory.LazyFunction(fake_email)
#     password = factory.PostGenerationMethodCall('set_password',
#                                                 'queenfan86')
#     is_registered = True
#     date_confirmed = factory.Faker('date_time_this_decade', tzinfo=pytz.utc)
#     merged_by = None
#     verification_key = None
# 
#     class Meta:
#         model = models.OSFUser
# 
#     @classmethod
#     def _build(cls, target_class, *args, **kwargs):
#         emails = kwargs.pop('emails', [])
#         instance = super(DjangoModelFactory, cls)._build(target_class, *args, **kwargs)
#         if emails:
#             # Save for M2M population
#             instance.set_unusable_password()
#             instance.save()
#         for email in emails:
#             instance.emails.create(address=email)
#         return instance
# 
#     @classmethod
#     def _create(cls, target_class, *args, **kwargs):
#         emails = kwargs.pop('emails', [])
#         instance = super(DjangoModelFactory, cls)._create(target_class, *args, **kwargs)
#         if emails and not instance.pk:
#             # Save for M2M population
#             instance.set_unusable_password()
#             instance.save()
#         for email in emails:
#             instance.emails.create(address=email)
#         return instance
# 
#     @factory.post_generation
#     def set_names(self, create, extracted):
#         parsed = impute_names_model(self.fullname)
#         for key, value in parsed.items():
#             setattr(self, key, value)
# 
#     @factory.post_generation
#     def set_emails(self, create, extracted):
#         if not self.emails.filter(address=self.username).exists():
#             if not self.id:
#                 if create:
#                     # Perform implicit save to populate M2M
#                     self.save(clean=False)
#                 else:
#                     # This might lead to strange behavior
#                     return
#             self.emails.create(address=str(self.username).lower())
# 
# class RegistrationProviderFactory(DjangoModelFactory):
#     name = factory.Faker('company')
#     description = factory.Faker('bs')
#     external_url = factory.Faker('url')
#     access_token = factory.Faker('bs')
#     share_source = factory.Sequence(lambda n: 'share source #{0}'.format(n))
# 
#     class Meta:
#         model = models.RegistrationProvider
# 
#     @classmethod
#     def _create(cls, *args, **kwargs):
#         user = kwargs.pop('creator', None)
#         _id = kwargs.pop('_id', None)
#         try:
#             obj = cls._build(*args, **kwargs)
#         except IntegrityError as e:
#             # This is to ensure legacy tests don't fail when their _ids aren't unique
#             if _id == models.RegistrationProvider.default__id:
#                 pass
#             else:
#                 raise e
#         if _id and _id != 'osf':
#             obj._id = _id
# 
#         obj._creator = user or models.OSFUser.objects.first() or UserFactory()  # Generates primary_collection
#         obj.save()
#         return obj
# 
# 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()


import uuid
import pytest
from django.db.utils import IntegrityError
from osf.models import RegistrationBulkUploadJob
from osf.models.registration_bulk_upload_job import JobState
from osf_tests.factories import UserFactory, RegistrationProviderFactory, get_default_metaschema




@pytest.mark.django_db
class TestRegistrationBulkUploadJob:

    @pytest.fixture()
    def payload_hash(self):
        return str(uuid.uuid4()).replace('-', '')

    @pytest.fixture()
    def initiator(self):

# Path: osf/models/registration_bulk_upload_job.py
# class JobState(IntEnum):
#     """Defines the six states of registration bulk upload jobs.
#     """
# 
#     PENDING = 0  # Database preparation is in progress
#     INITIALIZED = 1  # Database preparation has been finished and is ready to be picked up
#     PICKED_UP = 2  # Registration creation is in progress
#     DONE_FULL = 3  # All (draft) registrations have been successfully created
#     DONE_PARTIAL = 4  # Some (draft) registrations have failed the creation creation process
#     DONE_ERROR = 5  # All (draft) registrations have failed
# 
# Path: osf_tests/factories.py
# class UserFactory(DjangoModelFactory):
#     # TODO: Change this to only generate long names and see what breaks
#     fullname = factory.Sequence(lambda n: 'Freddie Mercury{0}'.format(n))
# 
#     username = factory.LazyFunction(fake_email)
#     password = factory.PostGenerationMethodCall('set_password',
#                                                 'queenfan86')
#     is_registered = True
#     date_confirmed = factory.Faker('date_time_this_decade', tzinfo=pytz.utc)
#     merged_by = None
#     verification_key = None
# 
#     class Meta:
#         model = models.OSFUser
# 
#     @classmethod
#     def _build(cls, target_class, *args, **kwargs):
#         emails = kwargs.pop('emails', [])
#         instance = super(DjangoModelFactory, cls)._build(target_class, *args, **kwargs)
#         if emails:
#             # Save for M2M population
#             instance.set_unusable_password()
#             instance.save()
#         for email in emails:
#             instance.emails.create(address=email)
#         return instance
# 
#     @classmethod
#     def _create(cls, target_class, *args, **kwargs):
#         emails = kwargs.pop('emails', [])
#         instance = super(DjangoModelFactory, cls)._create(target_class, *args, **kwargs)
#         if emails and not instance.pk:
#             # Save for M2M population
#             instance.set_unusable_password()
#             instance.save()
#         for email in emails:
#             instance.emails.create(address=email)
#         return instance
# 
#     @factory.post_generation
#     def set_names(self, create, extracted):
#         parsed = impute_names_model(self.fullname)
#         for key, value in parsed.items():
#             setattr(self, key, value)
# 
#     @factory.post_generation
#     def set_emails(self, create, extracted):
#         if not self.emails.filter(address=self.username).exists():
#             if not self.id:
#                 if create:
#                     # Perform implicit save to populate M2M
#                     self.save(clean=False)
#                 else:
#                     # This might lead to strange behavior
#                     return
#             self.emails.create(address=str(self.username).lower())
# 
# class RegistrationProviderFactory(DjangoModelFactory):
#     name = factory.Faker('company')
#     description = factory.Faker('bs')
#     external_url = factory.Faker('url')
#     access_token = factory.Faker('bs')
#     share_source = factory.Sequence(lambda n: 'share source #{0}'.format(n))
# 
#     class Meta:
#         model = models.RegistrationProvider
# 
#     @classmethod
#     def _create(cls, *args, **kwargs):
#         user = kwargs.pop('creator', None)
#         _id = kwargs.pop('_id', None)
#         try:
#             obj = cls._build(*args, **kwargs)
#         except IntegrityError as e:
#             # This is to ensure legacy tests don't fail when their _ids aren't unique
#             if _id == models.RegistrationProvider.default__id:
#                 pass
#             else:
#                 raise e
#         if _id and _id != 'osf':
#             obj._id = _id
# 
#         obj._creator = user or models.OSFUser.objects.first() or UserFactory()  # Generates primary_collection
#         obj.save()
#         return obj
# 
# 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()


# Path: osf_tests/test_registration_bulk_upload_job.py
import uuid
import pytest
from django.db.utils import IntegrityError
from osf.models import RegistrationBulkUploadJob
from osf.models.registration_bulk_upload_job import JobState
from osf_tests.factories import UserFactory, RegistrationProviderFactory, get_default_metaschema





@pytest.mark.django_db
class TestRegistrationBulkUploadJob:

    @pytest.fixture()
    def payload_hash(self):
        return str(uuid.uuid4()).replace('-', '')

    @pytest.fixture()
    def initiator(self):

        return UserFactory()