Commit 7ba87555 by Don Mitchell

Merge pull request #623 from edx/split/edit_info

Don't use published_date to figure out if xblock is published
parents 7ddfac0b bdcb9eae
......@@ -639,7 +639,10 @@ class OpenAssessmentBlock(
bool
"""
# By default, assume that we're published, in case the runtime doesn't support publish date.
is_published = getattr(self, 'published_date', True) is not None
if hasattr(self.runtime, 'modulestore'):
is_published = self.runtime.modulestore.has_published_version(self)
else:
is_published = True
is_closed, reason, __, __ = self.is_closed(step=step)
return is_published and (not is_closed or reason == 'due')
......
......@@ -4,7 +4,7 @@ Tests the Open Assessment XBlock functionality.
from collections import namedtuple
import datetime as dt
import pytz
from mock import Mock, patch
from mock import Mock, patch, MagicMock
from openassessment.xblock import openassessmentblock
from openassessment.xblock.resolve_dates import DISTANT_PAST, DISTANT_FUTURE
......@@ -395,23 +395,22 @@ class TestDates(XBlockHandlerTestCase):
@scenario('data/basic_scenario.xml')
def test_is_released_unpublished(self, xblock):
# Simulate the runtime published_date mixin field
# The scenario doesn't provide a start date, so `is_released()`
# should be controlled only by the published date.
xblock.published_date = None
# should be controlled only by the published state.
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
self.assertFalse(xblock.is_released())
@scenario('data/basic_scenario.xml')
def test_is_released_published(self, xblock):
# Simulate the runtime published_date mixin field
# The scenario doesn't provide a start date, so `is_released()`
# should be controlled only by the published date.
xblock.published_date = dt.datetime(2013, 1, 1).replace(tzinfo=pytz.utc)
# should be controlled only by the published state which defaults to True
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = True
self.assertTrue(xblock.is_released())
@scenario('data/basic_scenario.xml')
def test_is_released_no_published_date_field(self, xblock):
# If the runtime doesn't provide a published_date field, assume we've been published
def test_is_released_no_ms(self, xblock):
self.assertTrue(xblock.is_released())
@scenario('data/basic_scenario.xml')
......@@ -419,14 +418,14 @@ class TestDates(XBlockHandlerTestCase):
# Simulate being course staff
xblock.xmodule_runtime = Mock(user_is_staff=True)
# Not published, should be not released
xblock.published_date = None
self.assertFalse(xblock.is_released())
# Published, should be released
xblock.published_date = dt.datetime(2013, 1, 1).replace(tzinfo=pytz.utc)
self.assertTrue(xblock.is_released())
# Not published, should be not released
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
self.assertFalse(xblock.is_released())
@scenario('data/staff_dates_scenario.xml')
def test_course_staff_dates(self, xblock):
......
......@@ -7,6 +7,7 @@ import json
import datetime as dt
import pytz
from ddt import ddt, file_data
from mock import MagicMock
from .base import scenario, XBlockHandlerTestCase
......@@ -125,7 +126,8 @@ class StudioViewTest(XBlockHandlerTestCase):
@file_data('data/update_xblock.json')
@scenario('data/basic_scenario.xml')
def test_update_editor_context(self, xblock, data):
xblock.published_date = None
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
resp = self.request(xblock, 'update_editor_context', json.dumps(data), response_format='json')
self.assertTrue(resp['success'], msg=resp.get('msg'))
......@@ -143,7 +145,8 @@ class StudioViewTest(XBlockHandlerTestCase):
"peer-assessment",
"self-assessment",
]
xblock.published_date = None
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
resp = self.request(xblock, 'update_editor_context', json.dumps(data), response_format='json')
self.assertTrue(resp['success'], msg=resp.get('msg'))
self.assertEqual(xblock.editor_assessments_order, data['editor_assessments_order'])
......@@ -163,7 +166,8 @@ class StudioViewTest(XBlockHandlerTestCase):
"peer-assessment",
"self-assessment",
]
xblock.published_date = None
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
resp = self.request(xblock, 'update_editor_context', json.dumps(data), response_format='json')
self.assertTrue(resp['success'], msg=resp.get('msg'))
self.assertEqual(xblock.editor_assessments_order, data['editor_assessments_order'])
......@@ -172,7 +176,8 @@ class StudioViewTest(XBlockHandlerTestCase):
def test_update_editor_context_saves_leaderboard(self, xblock):
data = copy.deepcopy(self.UPDATE_EDITOR_DATA)
data['leaderboard_show'] = 42
xblock.published_date = None
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
resp = self.request(xblock, 'update_editor_context', json.dumps(data), response_format='json')
self.assertTrue(resp['success'], msg=resp.get('msg'))
self.assertEqual(xblock.leaderboard_show, 42)
......@@ -187,7 +192,8 @@ class StudioViewTest(XBlockHandlerTestCase):
else:
expected_error = 'error updating xblock configuration'
xblock.published_date = None
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
resp = self.request(xblock, 'update_editor_context', json.dumps(data), response_format='json')
self.assertFalse(resp['success'])
self.assertIn(expected_error, resp['msg'].lower())
......@@ -225,7 +231,8 @@ class StudioViewTest(XBlockHandlerTestCase):
self.assertIn('msg', resp)
# Set the problem to unpublished with a start date in the future
xblock.published_date = None
xblock.runtime.modulestore = MagicMock()
xblock.runtime.modulestore.has_published_version.return_value = False
xblock.start = dt.datetime(3000, 1, 1).replace(tzinfo=pytz.utc)
resp = self.request(xblock, 'check_released', json.dumps(""), response_format='json')
self.assertTrue(resp['success'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment