diff --git a/openassessment/xblock/openassessmentblock.py b/openassessment/xblock/openassessmentblock.py index b7c3c5ec1c..6345b1a0d5 100644 --- a/openassessment/xblock/openassessmentblock.py +++ b/openassessment/xblock/openassessmentblock.py @@ -639,7 +639,10 @@ def is_released(self, step=None): 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') diff --git a/openassessment/xblock/test/test_openassessment.py b/openassessment/xblock/test/test_openassessment.py index bde7a497fd..5391fe619d 100644 --- a/openassessment/xblock/test/test_openassessment.py +++ b/openassessment/xblock/test/test_openassessment.py @@ -4,7 +4,7 @@ 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 @@ def test_is_closed_uses_utc(self, xblock): @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 @@ def test_is_released_course_staff(self, xblock): # 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): diff --git a/openassessment/xblock/test/test_studio.py b/openassessment/xblock/test/test_studio.py index 0662fd741c..b1deb164b6 100644 --- a/openassessment/xblock/test/test_studio.py +++ b/openassessment/xblock/test/test_studio.py @@ -7,6 +7,7 @@ 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 @@ def test_render_studio_with_ai(self, xblock): @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 @@ def test_update_editor_context_saves_assessment_order(self, xblock): "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 @@ def test_update_editor_context_saves_assessment_order_with_ai(self, xblock): "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 @@ def test_update_editor_context_saves_assessment_order_with_ai(self, xblock): 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 @@ def test_update_context_invalid_request_data(self, xblock, data): 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 @@ def test_check_released(self, xblock): 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'])