Skip to content

Commit

Permalink
Don't use published_date to figure out if xblock is published
Browse files Browse the repository at this point in the history
ask the modulestore if it's published
LMS-11184
  • Loading branch information
Don Mitchell committed Sep 4, 2014
1 parent 7ddfac0 commit bdcb9ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
5 changes: 4 additions & 1 deletion openassessment/xblock/openassessmentblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
27 changes: 13 additions & 14 deletions openassessment/xblock/test/test_openassessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -395,38 +395,37 @@ 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')
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):

Expand Down
19 changes: 13 additions & 6 deletions openassessment/xblock/test/test_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'))

Expand All @@ -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'])
Expand All @@ -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'])
Expand All @@ -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)
Expand All @@ -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())
Expand Down Expand Up @@ -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'])
Expand Down

0 comments on commit bdcb9ea

Please sign in to comment.