def provider(self): provider = RegistrationProviderFactory() asset_file = ProviderAssetFileFactory( name='square_color_no_transparent') provider.asset_files.add(asset_file) provider.access_token = None provider.save() return provider
def provider_with_reg(self, osf_reg_schema, egap_schema, schema, out_dated_schema): provider = RegistrationProviderFactory() update_provider_auth_groups() provider.schemas.add( *[osf_reg_schema, schema, out_dated_schema, egap_schema]) provider.save() return provider
def provider(self, schema, out_dated_schema, invisible_schema, inactive_schema): provider = RegistrationProviderFactory() update_provider_auth_groups() provider.schemas.add( *[schema, out_dated_schema, invisible_schema, inactive_schema]) provider.save() return provider
def provider(self, moderator, provider_admin): provider = RegistrationProviderFactory() update_provider_auth_groups() provider.get_group('moderator').user_set.add(moderator) provider.get_group('admin').user_set.add(provider_admin) provider.reviews_workflow = Workflows.PRE_MODERATION.value provider.save() return provider
def provider(self): provider = RegistrationProviderFactory() NotificationSubscription.objects.get_or_create( _id=f'{provider._id}_new_pending_submissions', event_name='new_pending_submissions', provider=provider) update_provider_auth_groups() return provider
def setUp(self): super().setUp() self.embargo = EmbargoFactory() self.registration_approval = RegistrationApprovalFactory() self.retraction = RetractionFactory() self.embargo_termination = EmbargoTerminationApprovalFactory() self.provider = RegistrationProviderFactory() for sanction in [self.embargo, self.registration_approval, self.retraction, self.embargo_termination]: registration = sanction.target_registration registration.provider = self.provider registration.save() # EmbargoTerminationFactory actually calls terminate_embargo, # which updates state in the new world self.embargo_termination.target_registration.moderation_state = RegistrationModerationStates.INITIAL.db_name self.embargo_termination.target_registration.save()
def provider(self): provider = RegistrationProviderFactory() provider.update_group_permissions() _ensure_subscriptions(provider) provider.reviews_workflow = Workflows.PRE_MODERATION.value provider.save() return provider
def configure_test_preconditions( registration_status='public', reviews_workflow=DEFAULT_REVIEWS_WORKFLOW, schema_response_state=DEFAULT_SCHEMA_RESPONSE_STATE, role='admin'): '''Create and Configure a RegistrationProvider, Registration, SchemaResponse, and User.''' provider = RegistrationProviderFactory() provider.update_group_permissions() provider.reviews_workflow = reviews_workflow provider.save() registration = RegistrationFactory(provider=provider, schema=get_default_test_schema()) if registration_status == 'public': registration.is_public = True elif registration_status == 'private': registration.is_public = False # set moderation state to a realistic value for a private # registration with an approved response registration.moderation_state = 'embargo' elif registration_status == 'withdrawn': registration.moderation_state = 'withdrawn' elif registration_status == 'deleted': registration.deleted = timezone.now() registration.save() schema_response = registration.schema_responses.last() schema_response.actions.create(creator=schema_response.initiator, from_state=schema_response.reviews_state, to_state=schema_response_state.db_name, trigger=DEFAULT_TRIGGER.db_name) schema_response.approvals_state_machine.set_state(schema_response_state) schema_response.save() auth = configure_user_auth(registration, role) return auth, schema_response, registration, provider
def configure_permissions_test_preconditions( registration_status='public', schema_response_state=ApprovalStates.APPROVED, reviews_workflow=DEFAULT_REVIEWS_WORKFLOW, role='admin'): '''Create and configure a RegistrationProvider, Registration, SchemaResponse and User.''' provider = RegistrationProviderFactory() provider.update_group_permissions() provider.reviews_workflow = reviews_workflow provider.save() registration = RegistrationFactory(schema=get_default_test_schema(), provider=provider) registration.provider = provider if registration_status == 'public': registration.is_public = True elif registration_status == 'private': registration.is_public = False elif registration_status == 'withdrawn': registration.moderation_state = 'withdrawn' elif registration_status == 'deleted': registration.deleted = timezone.now() registration.save() schema_response = registration.schema_responses.last() schema_response.approvals_state_machine.set_state(schema_response_state) schema_response.save() auth = _configure_permissions_test_auth(registration, role) return auth, schema_response, registration, provider
def provider(self, moderator): provider = RegistrationProviderFactory() update_provider_auth_groups() provider.schemas.add(get_default_metaschema()) provider.get_group('moderator').user_set.add(moderator) provider.reviews_workflow = Workflows.PRE_MODERATION.value provider.save() return provider
def provider(self, moderator): provider = RegistrationProviderFactory() update_provider_auth_groups() provider.schemas.add(get_default_metaschema()) provider.get_group('moderator').user_set.add(moderator) provider.save() return provider
def moderator_wrong_provider(self): user = AuthUserFactory() provider = RegistrationProviderFactory() update_provider_auth_groups() provider.schemas.add(get_default_metaschema()) provider.get_group('moderator').user_set.add(user) provider.save() return user
def configure_test_preconditions( registration_status='public', reviews_workflow=DEFAULT_REVIEWS_WORKFLOW, schema_response_state=DEFAULT_SCHEMA_RESPONSE_STATE, role='admin'): '''Create and Configure a RegistrationProvider, Registration, SchemaResponse, and User.''' provider = RegistrationProviderFactory() provider.update_group_permissions() provider.reviews_workflow = reviews_workflow provider.save() registration = RegistrationFactory(provider=provider, schema=get_default_test_schema()) if registration_status == 'public': registration.is_public = True elif registration_status == 'private': registration.is_public = False # set moderation state to a realistic value for a private # registration with an approved response registration.moderation_state = 'embargo' elif registration_status == 'withdrawn': registration.moderation_state = 'withdrawn' elif registration_status == 'deleted': registration.deleted = timezone.now() registration.save() schema_response = registration.schema_responses.last() schema_response.approvals_state_machine.set_state(schema_response_state) schema_response.save() # Set the required fields on the schema response for block in schema_response.response_blocks.all(): block.set_response(DEFAULT_SCHEMA_RESPONSES.get(block.schema_key)) auth = configure_user_auth(registration, role) # Do this step after configuring auth to ensure any new admin user, gets added if schema_response_state is ApprovalStates.UNAPPROVED: schema_response.pending_approvers.add(*[ user for user, _ in registration.get_admin_contributors_recursive() ]) if schema_response_state is ApprovalStates.IN_PROGRESS: # need valid changes for submission validations schema_response.update_responses({'q1': 'update for submission'}) schema_response.revision_justification = 'has for valid revision_justification for submission' schema_response.save() return auth, schema_response, registration, provider
def setUp(self): super().setUp() embargo = EmbargoFactory() registration = embargo.target_registration moderator = AuthUserFactory() provider = RegistrationProviderFactory() embargo.to_APPROVED() embargo.save() update_provider_auth_groups() provider.get_group('moderator').user_set.add(moderator) provider.reviews_workflow = Workflows.PRE_MODERATION.value provider.save() registration.provider = provider registration.update_moderation_state() registration.save() self.embargo = embargo self.registration = registration self.user = self.registration.creator self.moderator = moderator self.provider = provider
def configure_test_preconditions(registration_status='public', moderator_workflow=DEFAULT_REVIEWS_WORKFLOW, updated_response_state=None, role='admin'): '''Create and Configure a RegistrationProvider, Registration, SchemaResponse, and User.''' provider = RegistrationProviderFactory() provider.update_group_permissions() provider.reviews_workflow = moderator_workflow provider.save() registration = RegistrationFactory(provider=provider) if registration_status == 'public': registration.is_public = True elif registration_status == 'private': registration.is_public = False # set moderation state to a realistic value for a private # registration with an approved response registration.moderation_state = 'embargo' elif registration_status == 'withdrawn': registration.moderation_state = 'withdrawn' elif registration_status == 'deleted': registration.deleted = timezone.now() registration.save() initial_response = registration.schema_responses.last() initial_response.approvals_state_machine.set_state(ApprovalStates.APPROVED) initial_response.save() updated_response = None if updated_response_state is not None: updated_response = SchemaResponse.create_from_previous_response( previous_response=initial_response, initiator=initial_response.initiator) updated_response.approvals_state_machine.set_state( updated_response_state) updated_response.save() auth = configure_auth(registration, role) return auth, updated_response, registration, provider
def registration_collection(self, user): return CollectionFactory(creator=user, provider=RegistrationProviderFactory(), is_public=True)
def provider_with_egap_only(self, egap_schema): provider = RegistrationProviderFactory() update_provider_auth_groups() provider.schemas.add(egap_schema) provider.save() return provider
def provider_with_brand(self, brand): registration_provider = RegistrationProviderFactory() registration_provider.brand = brand registration_provider.save() return registration_provider
def provider_with_v2_prereg_only(self, schema): provider = RegistrationProviderFactory() update_provider_auth_groups() provider.schemas.add(schema) provider.save() return provider
def non_egap_provider(self): return RegistrationProviderFactory()
def provider(self): return RegistrationProviderFactory(_id='osf')
def registration_provider(self): return RegistrationProviderFactory()
def provider(self): pp = RegistrationProviderFactory(name='EGAP') pp.update_group_permissions() return pp
def registration_collection(self, user): return CollectionFactory(creator=user, provider=RegistrationProviderFactory(), is_public=True, status_choices=['', 'asdf', 'lkjh'], collected_type_choices=['', 'asdf', 'lkjh'])
def provider_not_allow_bulk(self, user): provider = RegistrationProviderFactory() provider.allow_bulk_uploads = False provider.add_to_group(user, 'admin') provider.save() return provider
def egap(self): return RegistrationProviderFactory(_id='egap')
def moderated_provider(self): provider = RegistrationProviderFactory() provider.reviews_workflow = Workflows.PRE_MODERATION.value provider.save() return provider
def non_default_provider(self, metaschema_open_ended): non_default_provider = RegistrationProviderFactory() non_default_provider.schemas.add(metaschema_open_ended) non_default_provider.save() return non_default_provider
class TestCorrectRegistrationModerationState(OsfTestCase): def setUp(self): super().setUp() self.embargo = EmbargoFactory() self.registration_approval = RegistrationApprovalFactory() self.retraction = RetractionFactory() self.embargo_termination = EmbargoTerminationApprovalFactory() self.provider = RegistrationProviderFactory() for sanction in [self.embargo, self.registration_approval, self.retraction, self.embargo_termination]: registration = sanction.target_registration registration.provider = self.provider registration.save() # EmbargoTerminationFactory actually calls terminate_embargo, # which updates state in the new world self.embargo_termination.target_registration.moderation_state = RegistrationModerationStates.INITIAL.db_name self.embargo_termination.target_registration.save() def test_correct_registration_moderation_states(self): self.embargo.approval_stage = ApprovalStates.MODERATOR_REJECTED self.embargo.save() self.registration_approval.approval_stage = ApprovalStates.APPROVED self.registration_approval.save() self.retraction.approval_stage = ApprovalStates.PENDING_MODERATION self.retraction.save() self.embargo_termination.approval_stage = ApprovalStates.REJECTED self.embargo_termination.save() empty_state_counts = {state.db_name: 0 for state in RegistrationModerationStates} expected_initial_states = dict(empty_state_counts) expected_initial_states.update({'initial': 4}) assert self.provider.get_reviewable_state_counts() == expected_initial_states corrected_count = correct_registration_moderation_states() assert corrected_count == 4 expected_end_states = dict(empty_state_counts) expected_end_states.update( {'accepted': 1, 'rejected': 1, 'pending_withdraw': 1, 'embargo': 1} ) assert self.provider.get_reviewable_state_counts() == expected_end_states def test_correct_registration_moderation_states_only_collects_initial_registrations(self): # Implicitly invoke update_moderation_state. # We should not attempt to update state on these Registrations. # Also should not attempt to update self.registration_approval, which should be in initial self.embargo.to_COMPLETED() self.retraction.to_APPROVED() with mock.patch.object(Registration, 'update_moderation_state') as mock_update: correct_registration_moderation_states() assert mock_update.call_count == 1 def test_correct_registration_moderation_states_ignores_deleted_registrations(self): deleted_registration = self.registration_approval.target_registration deleted_registration.deleted = timezone.now() deleted_registration.save() with mock.patch.object(Registration, 'update_moderation_state') as mock_update: correct_registration_moderation_states() # Shouldn't attempt to update self.registration_approval (deleted) # or self.embargo (correctly in 'initial') assert mock_update.call_count == 2 def test_correct_registration_moderation_states_only_reports_updated_registrations(self): # INITIAL is the correct state for a Registration with an # Embargo or a RegistrationApproval in UNAPPROVED state corrected_count = correct_registration_moderation_states() assert corrected_count == 2