Skip to content

Commit

Permalink
Fix personalinfo mask for gacco service openedx#848
Browse files Browse the repository at this point in the history
  • Loading branch information
hachiyanagi-ks committed Jun 28, 2016
1 parent 3179206 commit 2969c13
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
16 changes: 6 additions & 10 deletions biz/djangoapps/ga_contract_operation/personalinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ def _validate_and_get_arguments(task_id, task_input):
raise ValueError(_msg)

contract = task_history.contract

if not contract.is_spoc_available:
_msg = "Contract {contract_id} is not SPOC contract.".format(contract_id=contract.id)
log.warning("Task {task_id}: {msg}".format(task_id=task_id, msg=_msg))
raise ValueError(_msg)

targets = ContractTaskTarget.find_by_history_id(task_history.id)

return (contract, targets)
Expand Down Expand Up @@ -205,10 +199,12 @@ def perform_delegate_personalinfo_mask(entry_id, task_input, action_name):
# Mask of additional information will run for all users even if it does not mask an user
# information. Therefore, it might be run more than once, but this is not a problem.
executor.disable_additional_info(user)
if not executor.check_enrollment(user):
task_progress.skip()
continue
executor.disable_user_info(user)
# Try to mask user information if contract is SPOC.
if contract.is_spoc_available:
if not executor.check_enrollment(user):
task_progress.skip()
continue
executor.disable_user_info(user)
target.complete()
except:
# If an exception occur, logging it and to continue processing next target.
Expand Down
55 changes: 44 additions & 11 deletions biz/djangoapps/ga_contract_operation/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,6 @@ def test_conflict_contract(self):
self.assertEqual("Contract id conflict: submitted value {} does not match {}".format(history.contract_id, contract.id), cm.exception.message)
self._assert_task_failure(entry.id)

def test_not_spoc_contract(self):
contract = self._create_contract(contract_type=CONTRACT_TYPE_GACCO_SERVICE[0])
history = self._create_task_history(contract)
entry = self._create_input_entry(contract=contract, history=history)

with self.assertRaises(ValueError) as cm:
self._run_task_with_mock_celery(personalinfo_mask, entry.id, entry.task_id)

self.assertEqual("Contract {} is not SPOC contract.".format(contract.id), cm.exception.message)
self._assert_task_failure(entry.id)

def test_successful(self):
# ----------------------------------------------------------
# Setup test data
Expand Down Expand Up @@ -323,6 +312,50 @@ def test_successful(self):
# Assert all of target is completed
self.assertEqual(5, ContractTaskTarget.objects.filter(history=history, completed=True).count())

def test_successful_with_gacco_service(self):
# ----------------------------------------------------------
# Setup test data
# ----------------------------------------------------------
self._setup_courses()
display_names = ['settting1', 'setting2', ]
contract = self._create_contract(
contract_type=CONTRACT_TYPE_GACCO_SERVICE[0],
courses=self.mooc_courses,
display_names=display_names
)
history = self._create_task_history(contract)
# users: enrolled only target mooc courses
registers = [self._create_user_and_register(contract, display_names=display_names) for _ in range(5)]
# 3 target is not completed
self._create_targets(history, registers[:3])
# 2 target is completed
self._create_targets(history, registers[3:], completed=True)
self._create_enrollments(registers, self.mooc_courses)

entry = self._create_input_entry(contract=contract, history=history)

user_info = {register.user.id: self._create_user_info(register.user) for register in registers}

# ----------------------------------------------------------
# Execute task
# ----------------------------------------------------------
self._test_run_with_task(personalinfo_mask, 'personalinfo_mask', 3, 2, 0, 5, 5, entry)

# ----------------------------------------------------------
# Assertion
# ----------------------------------------------------------
for i, register in enumerate(registers):
masked = i < 3
if masked:
self._assert_additional_info(register.user, contract, display_names, masked=True)
else:
self._assert_additional_info(register.user, contract, display_names, masked=False)
self._assert_user_info(user_info, register.user, masked=False)
self._assert_cert_info(user_info, register.user, self.mooc_courses, masked=False)
self._assert_global_courses(user_info, register.user, self.global_courses, masked=False)
# Assert all of target is completed
self.assertEqual(5, ContractTaskTarget.objects.filter(history=history, completed=True).count())

def test_successful_with_completed_target(self):
# ----------------------------------------------------------
# Setup test data
Expand Down

0 comments on commit 2969c13

Please sign in to comment.