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 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_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 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