Skip to content

Commit

Permalink
test: refactor mocking to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nsprenkle committed Jan 16, 2024
1 parent 1cc7a93 commit 969ae6e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
20 changes: 14 additions & 6 deletions openassessment/xblock/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"""


from contextlib import contextmanager
import copy
from functools import wraps
import json
import os.path

from unittest import mock
from mock import PropertyMock, patch
from workbench.runtime import WorkbenchRuntime

import webob
Expand Down Expand Up @@ -503,12 +505,18 @@ def set_staff_access(xblock):
xblock.xmodule_runtime.anonymous_student_id = 'Bob'

@staticmethod
def set_mock_workflow_info(xblock, workflow_status, status_details, submission_uuid):
xblock.get_workflow_info = mock.Mock(return_value={
'status': workflow_status,
'status_details': status_details,
'submission_uuid': submission_uuid
})
@contextmanager
def mock_workflow_status(workflow_status, status_details, submission_uuid):
with patch(
"openassessment.xblock.apis.workflow_api.WorkflowAPI.workflow",
new_callable=PropertyMock,
) as mock_workflow:
mock_workflow.return_value = {
"status": workflow_status,
"status_details": status_details,
"submission_uuid": submission_uuid,
}
yield

def submit_staff_assessment(self, xblock, submission, assessment):
"""
Expand Down
48 changes: 22 additions & 26 deletions openassessment/xblock/test/test_staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,30 @@ def _verify_grade_templates_workflow(self, xblock):

# Verify that once the required step (self assessment) is done, the staff grade is shown as complete.
status_details = {'peer': {'complete': True}}
self.set_mock_workflow_info(
xblock, workflow_status='done', status_details=status_details, submission_uuid=submission['uuid']
)
self._assert_path_and_context(
xblock,
{
'status_value': 'Complete',
'icon_class': 'fa-check',
'step_classes': 'is--showing',
'button_active': 'aria-expanded="true"',
'xblock_id': xblock.scope_ids.usage_id
}
)
with self.mock_workflow_status('done', status_details, submission["uuid"]):
self._assert_path_and_context(
xblock,
{
'status_value': 'Complete',
'icon_class': 'fa-check',
'step_classes': 'is--showing',
'button_active': 'aria-expanded="true"',
'xblock_id': xblock.scope_ids.usage_id
}
)

# Verify that if the problem is cancelled, the staff grade reflects this.
self.set_mock_workflow_info(
xblock, workflow_status='cancelled', status_details=status_details, submission_uuid=submission['uuid']
)
self._assert_path_and_context(
xblock,
{
'status_value': 'Cancelled',
'icon_class': 'fa-exclamation-triangle',
'button_active': 'disabled="disabled" aria-expanded="false"',
'step_classes': 'is--unavailable',
'xblock_id': xblock.scope_ids.usage_id
}
)
with self.mock_workflow_status('cancelled', status_details, submission['uuid']):
self._assert_path_and_context(
xblock,
{
'status_value': 'Cancelled',
'icon_class': 'fa-exclamation-triangle',
'button_active': 'disabled="disabled" aria-expanded="false"',
'step_classes': 'is--unavailable',
'xblock_id': xblock.scope_ids.usage_id
}
)

@scenario('data/grade_waiting_scenario.xml', user_id='Omar')
def test_staff_grade_templates_no_peer(self, xblock):
Expand Down

0 comments on commit 969ae6e

Please sign in to comment.