From 426524d3a7e9d481f51ea6623f55c170a2308edb Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Tue, 16 Jul 2024 00:50:24 -0400 Subject: [PATCH] fix more weirdly broken tests --- api_tests/nodes/views/test_node_list.py | 2 ++ api_tests/reviews/mixins/filter_mixins.py | 20 +++++++++++++------- osf/utils/machines.py | 10 ++++++++++ osf/utils/workflows.py | 2 ++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/api_tests/nodes/views/test_node_list.py b/api_tests/nodes/views/test_node_list.py index 424721fa92c4..134f28159d99 100644 --- a/api_tests/nodes/views/test_node_list.py +++ b/api_tests/nodes/views/test_node_list.py @@ -1111,6 +1111,7 @@ def test_private_preprint_in_preprint_false_filter_results( assert res.status_code == 200 assert private.node._id not in [each['id'] for each in res.json['data']] + @pytest.mark.skip('No more abanddon preprints') def test_abandonded_preprint_in_preprint_true_filter_results( self, app, user_one, user_two): abandoned = PreprintFactory( @@ -1143,6 +1144,7 @@ def test_abandonded_preprint_in_preprint_true_filter_results( assert res.status_code == 200 assert abandoned.node._id in [each['id'] for each in res.json['data']] + @pytest.mark.skip('No More abandoned preprints') def test_abandonded_preprint_in_preprint_false_filter_results( self, app, user_one, user_two): abandoned = PreprintFactory( diff --git a/api_tests/reviews/mixins/filter_mixins.py b/api_tests/reviews/mixins/filter_mixins.py index 14e848242cb4..77e8e7069499 100644 --- a/api_tests/reviews/mixins/filter_mixins.py +++ b/api_tests/reviews/mixins/filter_mixins.py @@ -64,7 +64,13 @@ def all_actions(self, providers): project=ProjectFactory(is_public=True) ) for _ in range(5): - actions.append(ReviewActionFactory(target=preprint)) + review_action = ReviewActionFactory(target=preprint) + # FuzzyChoice getter is broken + review_action.trigger = review_action.trigger[0] + review_action.from_state = review_action.from_state[0] + review_action.to_state = review_action.to_state[0] + review_action.save() + actions.append(review_action) return actions @pytest.fixture() @@ -101,22 +107,22 @@ def test_filter_actions(self, app, url, user, expected_actions): # filter by trigger expected = set( - [l._id for l in expected_actions if l.trigger[0] == action.trigger[0]]) + [l._id for l in expected_actions if l.trigger == action.trigger]) - actual = get_actual(app, url, user, trigger=action.trigger[0]) + actual = get_actual(app, url, user, trigger=action.trigger) assert expected == actual # filter by from_state expected = set( - [l._id for l in expected_actions if l.from_state == action.from_state[0]]) + [l._id for l in expected_actions if l.from_state == action.from_state]) - actual = get_actual(app, url, user, from_state=action.from_state[0]) + actual = get_actual(app, url, user, from_state=action.from_state) assert expected == actual # filter by to_state expected = set( - [l._id for l in expected_actions if l.to_state == action.to_state[0]]) - actual = get_actual(app, url, user, to_state=action.to_state[0]) + [l._id for l in expected_actions if l.to_state == action.to_state]) + actual = get_actual(app, url, user, to_state=action.to_state) assert expected == actual # filter by date_created diff --git a/osf/utils/machines.py b/osf/utils/machines.py index 8cdb5fb18657..2cde9e4510d1 100644 --- a/osf/utils/machines.py +++ b/osf/utils/machines.py @@ -125,6 +125,13 @@ def save_changes(self, ev): def resubmission_allowed(self, ev): return self.machineable.provider.reviews_workflow == Workflows.PRE_MODERATION.value + def pre_moderation(self, ev): + return self.machineable.provider.reviews_workflow == Workflows.PRE_MODERATION.value + + def post_moderation(self, ev): + return self.machineable.provider.reviews_workflow == Workflows.POST_MODERATION.value + + def perform_withdraw(self, ev): self.machineable.date_withdrawn = self.action.created if self.action is not None else timezone.now() self.machineable.withdrawal_justification = ev.kwargs.get('comment', '') @@ -164,6 +171,9 @@ def notify_withdraw(self, ev): # If there is no preprint request action, it means the withdrawal is directly initiated by admin/moderator context['force_withdrawal'] = True + if not context.get('requester'): + context['requester'] = ev.kwargs.get('user') + for contributor in self.machineable.contributors.all(): context['contributor'] = contributor if context.get('requester', None): diff --git a/osf/utils/workflows.py b/osf/utils/workflows.py index 512ba396de10..1058bdc54d8d 100644 --- a/osf/utils/workflows.py +++ b/osf/utils/workflows.py @@ -207,6 +207,7 @@ def db_name(self): ''' return self.value + class DefaultStates(ModerationEnum): '''The states of a CollectionSubmission object.''' @@ -347,6 +348,7 @@ class DefaultTriggers(ModerationEnum): 'trigger': 'withdraw', 'source': [PreprintStates.INITIAL.db_name, PreprintStates.PENDING.db_name, PreprintStates.ACCEPTED.db_name], 'dest': PreprintStates.WITHDRAWN.db_name, + 'unless': ['post_moderation', 'pre_moderation'], 'after': ['save_action', 'update_last_transitioned', 'perform_withdraw', 'save_changes', 'notify_withdraw'] },