def test_cohort_change_filter_prevent_move(self): """ Test prevent the user's cohort change through a pipeline step. Expected result: - CohortChangeRequested is triggered and executes TestStopCohortChangeStep. - The user can't change cohorts. """ CohortMembership.assign(cohort=self.first_cohort, user=self.user) with self.assertRaises(CohortChangeNotAllowed): CohortMembership.assign(cohort=self.second_cohort, user=self.user)
def test_cohort_change_without_filter_configuration(self): """ Test usual cohort change process, without filter's intervention. Expected result: - CohortChangeRequested does not have any effect on the cohort change process. - The cohort assignment process ends successfully. """ CohortMembership.assign(cohort=self.first_cohort, user=self.user) cohort_membership, _ = CohortMembership.assign( cohort=self.second_cohort, user=self.user) self.assertEqual({}, cohort_membership.user.profile.get_meta())
def test_cohort_change_filter_executed(self): """ Test whether the student cohort change filter is triggered before the user's changes cohort. Expected result: - CohortChangeRequested is triggered and executes TestCohortChangeStep. - The user's profile meta contains cohort_info. """ CohortMembership.assign(cohort=self.first_cohort, user=self.user) cohort_membership, _ = CohortMembership.assign( cohort=self.second_cohort, user=self.user) self.assertEqual( { "cohort_info": "Changed from Cohort FirstCohort to Cohort SecondCohort" }, cohort_membership.user.profile.get_meta(), )
def test_send_cohort_membership_changed_event(self): """ Test whether the COHORT_MEMBERSHIP_CHANGED event is sent when a cohort membership update ends. Expected result: - COHORT_MEMBERSHIP_CHANGED is sent and received by the mocked receiver. - The arguments that the receiver gets are the arguments sent by the event except the metadata generated on the fly. """ event_receiver = Mock(side_effect=self._event_receiver_side_effect) COHORT_MEMBERSHIP_CHANGED.connect(event_receiver) cohort_membership, _ = CohortMembership.assign( cohort=self.cohort, user=self.user, ) self.assertTrue(self.receiver_called) self.assertDictContainsSubset( { "signal": COHORT_MEMBERSHIP_CHANGED, "sender": None, "cohort": CohortData( user=UserData( pii=UserPersonalData( username=cohort_membership.user.username, email=cohort_membership.user.email, name=cohort_membership.user.profile.name, ), id=cohort_membership.user.id, is_active=cohort_membership.user.is_active, ), course=CourseData( course_key=cohort_membership.course_id, ), name=cohort_membership.course_user_group.name, ), }, event_receiver.call_args.kwargs )