Пример #1
0
def retraction(provider=None):
    if provider is None:
        return RetractionFactory()
    sanction = RetractionFactory()
    registration = sanction.target_registration
    registration.provider = provider
    registration.update_moderation_state()
    registration.save()
    return sanction
Пример #2
0
 def test_valid_project_as_factory_allow_retractions_is_retracted(self):
     registration = RegistrationFactory(project=self.project)
     registration.retraction = RetractionFactory()
     registration.retraction.state = Sanction.UNAPPROVED
     registration.retraction.save()
     res = as_factory_allow_retractions(pid=registration._id)
     assert_equal(res['node'], registration)
Пример #3
0
 def retract_registration(self, provider, reg_creator):
     retract = RetractionFactory(user=reg_creator)
     registration = retract.target_registration
     registration.provider = provider
     registration.update_moderation_state()
     registration.save()
     return registration
Пример #4
0
 def retraction_fixture(self, provider):
     sanction = RetractionFactory(justification='bird')
     registration = sanction.target_registration
     registration.provider = provider
     registration.update_moderation_state()
     registration.save()
     return sanction
Пример #5
0
 def retraction(self, provider):
     sanction = RetractionFactory()
     registration = sanction.target_registration
     registration.provider = provider
     registration.update_moderation_state()
     registration.save()
     return sanction
 def registration_with_retraction(self, admin, contrib):
     sanction = RetractionFactory(user=admin)
     registration = sanction.target_registration
     registration.update_moderation_state()
     registration.add_contributor(admin, 'admin')
     registration.add_contributor(contrib, 'write')
     registration.save()
     return registration
    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()
Пример #8
0
 def draft_approved_but_withdrawn(self, user, project):
     draft = DraftRegistrationFactory(
         initiator=user, registration_schema=get_prereg_schema())
     draft.registered_node = RegistrationFactory(
         creator=user,
         project=project,
         is_public=True,
         retraction=RetractionFactory())
     draft.save()
     return draft
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
Пример #10
0
 def retraction(self):
     return RetractionFactory()