Skip to content

Commit

Permalink
fix more weirdly broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Jul 16, 2024
1 parent 92d1d35 commit 426524d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions api_tests/nodes/views/test_node_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 13 additions & 7 deletions api_tests/reviews/mixins/filter_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions osf/utils/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions osf/utils/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def db_name(self):
'''
return self.value


class DefaultStates(ModerationEnum):
'''The states of a CollectionSubmission object.'''

Expand Down Expand Up @@ -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']
},

Expand Down

0 comments on commit 426524d

Please sign in to comment.