class RegistrationWithChildNodesEmbargoModelTestCase(OsfTestCase): def setUp(self): super(RegistrationWithChildNodesEmbargoModelTestCase, self).setUp() self.user = AuthUserFactory() self.auth = self.user.auth self.valid_embargo_end_date = datetime.datetime.utcnow() + datetime.timedelta(days=3) self.project = ProjectFactory(title="Root", is_public=False, creator=self.user) self.component = NodeFactory(creator=self.user, parent=self.project, title="Component") self.subproject = ProjectFactory(creator=self.user, parent=self.project, title="Subproject") self.subproject_component = NodeFactory(creator=self.user, parent=self.subproject, title="Subcomponent") self.registration = RegistrationFactory(project=self.project) # Reload the registration; else tests won't catch failures to save self.registration.reload() def test_approval_embargoes_descendant_nodes(self): # Initiate embargo for parent registration self.registration.embargo_registration(self.user, self.valid_embargo_end_date) self.registration.save() assert_true(self.registration.is_pending_embargo) # Ensure descendant nodes are pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_pending_embargo) # Approve parent registration's embargo approval_token = self.registration.embargo.approval_state[self.user._id]["approval_token"] self.registration.embargo.approve_embargo(self.user, approval_token) assert_true(self.registration.embargo.embargo_end_date) # Ensure descendant nodes are in embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.embargo_end_date) def test_disapproval_cancels_embargo_on_descendant_nodes(self): # Initiate embargo on parent registration self.registration.embargo_registration(self.user, self.valid_embargo_end_date) self.registration.save() assert_true(self.registration.is_pending_embargo) # Ensure descendant nodes are pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_pending_embargo) # Disapprove parent registration's embargo rejection_token = self.registration.embargo.approval_state[self.user._id]["rejection_token"] self.registration.embargo.disapprove_embargo(self.user, rejection_token) assert_false(self.registration.is_pending_embargo) assert_equal(self.registration.embargo.state, Embargo.REJECTED) # Ensure descendant nodes' embargoes are cancelled descendants = self.registration.get_descendants_recursive() for node in descendants: assert_false(node.is_pending_embargo) assert_false(node.embargo_end_date)
class RegistrationWithChildNodesRetractionModelTestCase(OsfTestCase): def setUp(self): super(RegistrationWithChildNodesRetractionModelTestCase, self).setUp() self.user = AuthUserFactory() self.auth = self.user.auth self.project = ProjectFactory(is_public=True, creator=self.user) self.component = NodeFactory( creator=self.user, parent=self.project, title='Component' ) self.subproject = ProjectFactory( creator=self.user, parent=self.project, title='Subproject' ) self.subproject_component = NodeFactory( creator=self.user, parent=self.subproject, title='Subcomponent' ) self.registration = RegistrationFactory(project=self.project, is_public=True) # Reload the registration; else tests won't catch failures to svae self.registration.reload() def test_approval_retracts_descendant_nodes(self): # Initiate retraction for parent registration self.registration.retract_registration(self.user) self.registration.save() assert_true(self.registration.is_pending_retraction) # Ensure descendant nodes are pending registration descendants = self.registration.get_descendants_recursive() for node in descendants: node.save() assert_true(node.is_pending_retraction) # Approve parent registration's retraction approval_token = self.registration.retraction.approval_state[self.user._id]['approval_token'] self.registration.retraction.approve_retraction(self.user, approval_token) assert_true(self.registration.is_retracted) # Ensure descendant nodes are retracted descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_retracted) def test_disapproval_cancels_retraction_on_descendant_nodes(self): # Initiate retraction for parent registration self.registration.retract_registration(self.user) self.registration.save() assert_true(self.registration.is_pending_retraction) # Ensure descendant nodes are pending registration descendants = self.registration.get_descendants_recursive() for node in descendants: node.save() assert_true(node.is_pending_retraction) # Disapprove parent registration's retraction rejection_token = self.registration.retraction.approval_state[self.user._id]['rejection_token'] self.registration.retraction.disapprove_retraction(self.user, rejection_token) assert_false(self.registration.is_pending_retraction) assert_false(self.registration.is_retracted) assert_true(self.registration.retraction.is_rejected) # Ensure descendant nodes' retractions are cancelled descendants = self.registration.get_descendants_recursive() for node in descendants: assert_false(node.is_pending_retraction) assert_false(node.is_retracted) def test_approval_cancels_pending_embargoes_on_descendant_nodes(self): # Initiate embargo for registration self.registration.embargo_registration( self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10), for_existing_registration=True ) self.registration.save() assert_true(self.registration.is_pending_embargo) # Initiate retraction for parent registration self.registration.retract_registration(self.user) self.registration.save() assert_true(self.registration.is_pending_retraction) # Ensure descendant nodes are pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_pending_retraction) assert_true(node.is_pending_embargo) # Approve parent registration's retraction approval_token = self.registration.retraction.approval_state[self.user._id]['approval_token'] self.registration.retraction.approve_retraction(self.user, approval_token) assert_true(self.registration.is_retracted) assert_false(self.registration.is_pending_embargo) # Ensure descendant nodes are not pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_retracted) assert_false(node.is_pending_embargo) def test_approval_cancels_active_embargoes_on_descendant_nodes(self): # Initiate embargo for registration self.registration.embargo_registration( self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10), for_existing_registration=True ) self.registration.save() assert_true(self.registration.is_pending_embargo) # Approve embargo for registration embargo_approval_token = self.registration.embargo.approval_state[self.user._id]['approval_token'] self.registration.embargo.approve_embargo(self.user, embargo_approval_token) assert_false(self.registration.is_pending_embargo) assert_true(self.registration.embargo_end_date) # Initiate retraction for parent registration self.registration.retract_registration(self.user) self.registration.save() assert_true(self.registration.is_pending_retraction) # Ensure descendant nodes are not pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_pending_retraction) assert_true(node.embargo_end_date) # Approve parent registration's retraction approval_token = self.registration.retraction.approval_state[self.user._id]['approval_token'] self.registration.retraction.approve_retraction(self.user, approval_token) assert_true(self.registration.is_retracted) # Ensure descendant nodes are not pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_retracted)
class RegistrationWithChildNodesEmbargoModelTestCase(OsfTestCase): def setUp(self): super(RegistrationWithChildNodesEmbargoModelTestCase, self).setUp() self.user = AuthUserFactory() self.auth = self.user.auth self.valid_embargo_end_date = datetime.datetime.utcnow( ) + datetime.timedelta(days=3) self.project = ProjectFactory(title='Root', is_public=False, creator=self.user) self.component = NodeFactory(creator=self.user, parent=self.project, title='Component') self.subproject = ProjectFactory(creator=self.user, parent=self.project, title='Subproject') self.subproject_component = NodeFactory(creator=self.user, parent=self.subproject, title='Subcomponent') self.registration = RegistrationFactory(project=self.project) # Reload the registration; else tests won't catch failures to save self.registration.reload() def test_approval_embargoes_descendant_nodes(self): # Initiate embargo for parent registration self.registration.embargo_registration(self.user, self.valid_embargo_end_date) self.registration.save() assert_true(self.registration.is_pending_embargo) # Ensure descendant nodes are pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_pending_embargo) # Approve parent registration's embargo approval_token = self.registration.embargo.approval_state[ self.user._id]['approval_token'] self.registration.embargo.approve_embargo(self.user, approval_token) assert_true(self.registration.embargo.embargo_end_date) # Ensure descendant nodes are in embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.embargo_end_date) def test_disapproval_cancels_embargo_on_descendant_nodes(self): # Initiate embargo on parent registration self.registration.embargo_registration(self.user, self.valid_embargo_end_date) self.registration.save() assert_true(self.registration.is_pending_embargo) # Ensure descendant nodes are pending embargo descendants = self.registration.get_descendants_recursive() for node in descendants: assert_true(node.is_pending_embargo) # Disapprove parent registration's embargo rejection_token = self.registration.embargo.approval_state[ self.user._id]['rejection_token'] self.registration.embargo.disapprove_embargo(self.user, rejection_token) assert_false(self.registration.is_pending_embargo) assert_equal(self.registration.embargo.state, Embargo.REJECTED) # Ensure descendant nodes' embargoes are cancelled descendants = self.registration.get_descendants_recursive() for node in descendants: assert_false(node.is_pending_embargo) assert_false(node.embargo_end_date)