Commit 96f85915 by Waheed Ahmed

Merge pull request #684 from edx/waheed/tnl1736-add-beta-tester-functionality

Added beta tester functionality.
parents fa3e83b0 bf037f47
......@@ -330,6 +330,19 @@ class OpenAssessmentBlock(
return False
@property
def is_beta_tester(self):
"""
Check whether the user is a beta tester.
Returns:
bool
"""
if hasattr(self, 'xmodule_runtime'):
return getattr(self.xmodule_runtime, 'user_is_beta_tester', False)
else:
return False
@property
def in_studio_preview(self):
"""
Check whether we are in Studio preview mode.
......@@ -634,6 +647,10 @@ class OpenAssessmentBlock(
if course_staff:
return False, None, DISTANT_PAST, DISTANT_FUTURE
if self.is_beta_tester:
beta_start = self._adjust_start_date_for_beta_testers(open_range[0])
open_range = (beta_start, open_range[1])
# Check if we are in the open date range
now = dt.datetime.utcnow().replace(tzinfo=pytz.utc)
......@@ -809,3 +826,12 @@ class OpenAssessmentBlock(
def get_username(self, anonymous_user_id):
if hasattr(self, "xmodule_runtime"):
return self.xmodule_runtime.get_real_user(anonymous_user_id).username
def _adjust_start_date_for_beta_testers(self, start):
if hasattr(self, "xmodule_runtime"):
delta = dt.timedelta(getattr(self.xmodule_runtime, 'days_early_for_beta', 0))
effective = start - delta
return effective
return start
......@@ -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, MagicMock
from mock import Mock, patch, MagicMock, PropertyMock
from openassessment.xblock import openassessmentblock
from openassessment.xblock.resolve_dates import DISTANT_PAST, DISTANT_FUTURE
......@@ -119,6 +119,44 @@ class TestOpenAssessment(XBlockHandlerTestCase):
self.assertTrue(resp.body.find('Tuesday, April 01, 2014'))
self.assertTrue(resp.body.find('Thursday, May 01, 2014'))
@patch.object(openassessmentblock.OpenAssessmentBlock, 'is_beta_tester', new_callable=PropertyMock)
@scenario('data/basic_scenario.xml')
def test_formatted_dates_for_beta_tester_with_days_early(self, xblock, mock_is_beta_tester):
"""Test dates for beta tester with days early"""
mock_is_beta_tester.return_value = True
# Set start/due dates
xblock.start = dt.datetime(2014, 4, 6, 1, 1, 1)
xblock.due = dt.datetime(2014, 5, 1)
xblock.xmodule_runtime = Mock(
course_id='test_course',
anonymous_student_id='test_student',
days_early_for_beta=5
)
self.assertEqual(xblock.xmodule_runtime.days_early_for_beta, 5)
request = namedtuple('Request', 'params')
request.params = {}
resp = xblock.render_peer_assessment(request)
self.assertTrue(resp.body.find('Tuesday, April 01, 2014'))
self.assertTrue(resp.body.find('Thursday, May 01, 2014'))
@patch.object(openassessmentblock.OpenAssessmentBlock, 'is_beta_tester', new_callable=PropertyMock)
@scenario('data/basic_scenario.xml')
def test_formatted_dates_for_beta_tester_without_days_early(self, xblock, mock_is_beta_tester):
"""Test dates for beta tester without days early"""
mock_is_beta_tester.return_value = True
# Set start/due dates
xblock.start = dt.datetime(2014, 4, 6, 1, 1, 1)
xblock.due = dt.datetime(2014, 5, 1)
request = namedtuple('Request', 'params')
request.params = {}
resp = xblock.render_peer_assessment(request)
self.assertTrue(resp.body.find('Tuesday, April 06, 2014'))
self.assertTrue(resp.body.find('Thursday, May 01, 2014'))
@scenario('data/basic_scenario.xml', user_id='Bob')
def test_default_fields(self, xblock):
......
......@@ -626,13 +626,23 @@ class TestCourseStaff(XBlockHandlerTestCase):
self.assertIn("The student submission has been removed from peer", resp['msg'])
self.assertEqual(True, resp['success'])
def _create_mock_runtime(self, item_id, is_staff, is_admin, anonymous_user_id):
def _create_mock_runtime(
self,
item_id,
is_staff,
is_admin,
anonymous_user_id,
user_is_beta=False,
days_early_for_beta=0
):
mock_runtime = Mock(
course_id='test_course',
item_id=item_id,
anonymous_student_id='Bob',
user_is_staff=is_staff,
user_is_admin=is_admin,
user_is_beta=user_is_beta,
days_early_for_beta=days_early_for_beta,
service=lambda self, service: Mock(
get_anonymous_student_id=lambda user_id, course_id: anonymous_user_id
)
......
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