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