Example #1
0
    def setUp(self):
        """
        Set up tests.
        """
        super().setUp()

        self.user1 = UserFactory.create(username='******')
        self.user2 = UserFactory.create(username='******')
        self.user3 = UserFactory.create(username='******')

        for user in (self.user1, self.user2, self.user3):
            CourseEnrollmentFactory.create(user=user, course_id=COURSE_KEY1)
        CourseEnrollmentFactory.create(user=self.user1, course_id=COURSE_KEY2)

        self.team1 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            team_id='team1',
            topic_id=TEAMSET_1_ID,
        )
        self.team2 = CourseTeamFactory(
            course_id=COURSE_KEY2,
            team_id='team2',
            topic_id=TEAMSET_2_ID,
        )

        self.team_membership11 = self.team1.add_user(self.user1)
        self.team_membership12 = self.team1.add_user(self.user2)
        self.team_membership21 = self.team2.add_user(self.user1)
Example #2
0
    def test_team_removals_are_scoped_correctly(self):
        """ Team memberships should not search across topics in different courses """
        # Given a learner enrolled in similarly named teamsets across 2 courses
        audit_learner = UserFactory.create(username='******')

        CourseEnrollmentFactory.create(user=audit_learner, course_id=self.course.id, mode='audit')
        course_1_team = CourseTeamFactory(course_id=self.course.id, name='cross_course_test', topic_id='teamset_1')
        course_1_team.add_user(audit_learner)

        CourseEnrollmentFactory.create(user=audit_learner, course_id=self.second_course.id, mode='audit')
        course_2_team = CourseTeamFactory(
            course_id=self.second_course.id,
            name='cross_course_test',
            topic_id='teamset_1'
        )
        course_2_team.add_user(audit_learner)

        self.assertTrue(CourseTeamMembership.is_user_on_team(audit_learner, course_1_team))

        # When I try to remove them from the team
        row = {
            'mode': 'audit',
            'teamset_1': None,
            'user': audit_learner
        }
        self.import_manager.remove_user_from_team_for_reassignment(row)

        # They are successfully removed from the team
        self.assertFalse(CourseTeamMembership.is_user_on_team(audit_learner, course_1_team))
        self.assert_learner_removed_emitted(course_1_team.team_id, audit_learner.id)
Example #3
0
    def test_user_moved_to_another_team(self):
        """ We should be able to move a user from one team to another """
        # Create a learner, enroll in course
        audit_learner = UserFactory.create(username='******')
        CourseEnrollmentFactory.create(user=audit_learner,
                                       course_id=self.course.id,
                                       mode='audit')
        # Make two teams in the same teamset, enroll the user in one
        team_1 = CourseTeamFactory(course_id=self.course.id,
                                   name='test_team_1',
                                   topic_id='teamset_1')
        team_2 = CourseTeamFactory(course_id=self.course.id,
                                   name='test_team_2',
                                   topic_id='teamset_1')
        team_1.add_user(audit_learner)

        csv_row = _csv_dict_row(audit_learner,
                                '',
                                'audit',
                                teamset_1=team_2.name)
        csv_import(self.course, [csv_row])

        assert not CourseTeamMembership.is_user_on_team(audit_learner, team_1)
        assert CourseTeamMembership.is_user_on_team(audit_learner, team_2)

        self.assert_learner_removed_emitted(team_1.team_id, audit_learner.id)
        self.assert_learner_added_emitted(team_2.team_id, audit_learner.id)
Example #4
0
    def setUpClass(cls):
        super().setUpClass()
        cls.user_audit = UserFactory.create(username='******')
        cls.user_staff = UserFactory.create(username='******')
        cls.user_masters = UserFactory.create(username='******')
        cls.user_unenrolled = UserFactory.create(username='******')
        cls.users = {
            'user_audit': cls.user_audit,
            'user_staff': cls.user_staff,
            'user_masters': cls.user_masters,
            'user_unenrolled': cls.user_unenrolled,
        }

        cls.topic_id = 'RANDOM TOPIC'
        cls.course_1 = CourseFactory.create(
            teams_configuration=TeamsConfig({
                'team_sets': [{'id': cls.topic_id, 'name': cls.topic_id, 'description': cls.topic_id}]
            }),
            org=COURSE_KEY1.org,
            course=COURSE_KEY1.course,
            run=COURSE_KEY1.run
        )

        for user in (cls.user_audit, cls.user_staff):
            CourseEnrollmentFactory.create(user=user, course_id=COURSE_KEY1)
        CourseEnrollmentFactory.create(user=cls.user_masters, course_id=COURSE_KEY1, mode=CourseMode.MASTERS)

        CourseStaffRole(COURSE_KEY1).add_users(cls.user_staff)

        cls.team_unprotected_1 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            topic_id=cls.topic_id,
            team_id='team_unprotected_1'
        )
        cls.team_unprotected_2 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            topic_id=cls.topic_id,
            team_id='team_unprotected_2'
        )
        cls.team_unprotected_3 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            topic_id=cls.topic_id,
            team_id='team_unprotected_3'
        )
        cls.team_protected_1 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            team_id='team_protected_1',
            topic_id=cls.topic_id,
            organization_protected=True
        )
        cls.team_protected_2 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            team_id='team_protected_2',
            topic_id=cls.topic_id,
            organization_protected=True
        )
Example #5
0
 def setUp(self):  # pylint: disable=arguments-differ
     """Create a user with a team to test signals."""
     super(TeamSignalsTest, self).setUp('lms.djangoapps.teams.utils.tracker')  # lint-amnesty, pylint: disable=super-with-arguments
     self.user = UserFactory.create(username="******")
     self.moderator = UserFactory.create(username="******")
     self.team = CourseTeamFactory(discussion_topic_id=self.DISCUSSION_TOPIC_ID)
     self.team_membership = CourseTeamMembershipFactory(user=self.user, team=self.team)
Example #6
0
 def setUp(self):
     """Create a user with a team to test signals."""
     super(TeamSignalsTest, self).setUp('lms.djangoapps.teams.utils.tracker')
     self.user = UserFactory.create(username="******")
     self.moderator = UserFactory.create(username="******")
     self.team = CourseTeamFactory(discussion_topic_id=self.DISCUSSION_TOPIC_ID)
     self.team_membership = CourseTeamMembershipFactory(user=self.user, team=self.team)
Example #7
0
    def test_add_incompatible_mode_to_existing_protected_team_fails(self):
        # Given an existing protected team
        protected_team = CourseTeamFactory(
            course_id=self.course.id,
            name='protected_team',
            topic_id='teamset_1',
            organization_protected=True,
        )
        masters_learner = self._create_and_enroll_test_user('masters_learner',
                                                            mode='masters')
        protected_team.add_user(masters_learner)

        # When I attempt to add a student of an incompatible enrollment mode
        verified_learner = self._create_and_enroll_test_user(
            'verified_learner', mode='verified')
        csv_data = self._csv_reader_from_array(
            [['username', 'mode', 'teamset_1'],
             [verified_learner.username, 'verified', 'protected_team']])
        result = self.import_manager.set_team_memberships(csv_data)

        # The import fails with "mixed users" error and learner not added to team
        assert not result
        self.assert_no_events_were_emitted()
        assert self.import_manager.validation_errors[0] ==\
               'Team protected_team cannot have Master’s track users mixed with users in other tracks.'
        assert not CourseTeamMembership.is_user_on_team(
            verified_learner, protected_team)
Example #8
0
    def test_team_discussion_id_not_cohorted(self, mock_request):
        team = CourseTeamFactory(course_id=self.course.id)

        team.add_user(self.student)
        self.call_view(mock_request, team.discussion_topic_id, self.student, None)

        self._assert_comments_service_called_without_group_id(mock_request)
Example #9
0
    def setUpClass(cls):
        super(TeamAccessTests, cls).setUpClass()
        cls.user_audit = UserFactory.create(username='******')
        cls.user_staff = UserFactory.create(username='******')
        cls.user_masters = UserFactory.create(username='******')
        cls.user_unenrolled = UserFactory.create(username='******')
        cls.users = {
            'user_audit': cls.user_audit,
            'user_staff': cls.user_staff,
            'user_masters': cls.user_masters,
            'user_unenrolled': cls.user_unenrolled,
        }

        for user in (cls.user_audit, cls.user_staff):
            CourseEnrollmentFactory.create(user=user, course_id=COURSE_KEY1)
        CourseEnrollmentFactory.create(user=cls.user_masters, course_id=COURSE_KEY1, mode=CourseMode.MASTERS)

        CourseStaffRole(COURSE_KEY1).add_users(cls.user_staff)

        cls.topic_id = 'RANDOM TOPIC'
        cls.team_unprotected_1 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            topic_id=cls.topic_id,
            team_id='team_unprotected_1'
        )
        cls.team_unprotected_2 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            topic_id=cls.topic_id,
            team_id='team_unprotected_2'
        )
        cls.team_unprotected_3 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            topic_id=cls.topic_id,
            team_id='team_unprotected_3'
        )
        cls.team_protected_1 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            team_id='team_protected_1',
            topic_id=cls.topic_id,
            organization_protected=True
        )
        cls.team_protected_2 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            team_id='team_protected_2',
            topic_id=cls.topic_id,
            organization_protected=True
        )
Example #10
0
 def setUpClass(cls):
     super(TestModelStrings, cls).setUpClass()
     cls.user = UserFactory.create(username="******")
     CourseEnrollmentFactory.create(user=cls.user,
                                    course_id="edx/the-course/1")
     cls.team = CourseTeamFactory(course_id="edx/the-course/1",
                                  team_id="the-team",
                                  topic_id=TEAMSET_1_ID,
                                  name="The Team")
     cls.team_membership = cls.team.add_user(cls.user)
Example #11
0
    def setUpClass(cls):
        super(PythonAPITests, cls).setUpClass()
        cls.user1 = UserFactory.create(username='******')
        cls.user2 = UserFactory.create(username='******')
        cls.user3 = UserFactory.create(username='******')

        for user in (cls.user1, cls.user2, cls.user3):
            CourseEnrollmentFactory.create(user=user, course_id=COURSE_KEY1)

        CourseEnrollmentFactory.create(user=cls.user3, course_id=COURSE_KEY2)

        cls.team1 = CourseTeamFactory(course_id=COURSE_KEY1,
                                      discussion_topic_id=DISCUSSION_TOPIC_ID,
                                      team_id='team1')
        cls.team2 = CourseTeamFactory(course_id=COURSE_KEY2, team_id='team2')

        cls.team1.add_user(cls.user1)
        cls.team1.add_user(cls.user2)
        cls.team2.add_user(cls.user3)
Example #12
0
    def setUpClass(cls):
        super(CourseTeamTest, cls).setUpClass()

        cls.audit_learner = UserFactory.create(username="******")
        CourseEnrollmentFactory.create(user=cls.audit_learner,
                                       course_id="edx/the-course/1",
                                       mode=CourseMode.AUDIT)
        cls.audit_team = CourseTeamFactory(course_id="edx/the-course/1",
                                           team_id="audit-team",
                                           topic_id=TEAMSET_1_ID,
                                           name="The Team")

        cls.masters_learner = UserFactory.create(username="******")
        CourseEnrollmentFactory.create(user=cls.masters_learner,
                                       course_id="edx/the-course/1",
                                       mode=CourseMode.MASTERS)
        cls.masters_team = CourseTeamFactory(course_id="edx/the-course/1",
                                             team_id="masters-team",
                                             topic_id=TEAMSET_1_ID,
                                             name="The Team",
                                             organization_protected=True)
Example #13
0
 def setUpClass(cls):
     super().setUpClass()
     cls.course_id = "edx/the-course/1"
     cls.course1 = create_course(CourseKey.from_string(cls.course_id),
                                 TEAMS_CONFIG_1)
     cls.user = UserFactory.create(username="******")
     CourseEnrollmentFactory.create(user=cls.user, course_id=cls.course_id)
     cls.team = CourseTeamFactory(course_id=cls.course_id,
                                  team_id="the-team",
                                  topic_id=TEAMSET_1_ID,
                                  name="The Team")
     cls.team_membership = cls.team.add_user(cls.user)
Example #14
0
    def setUpClass(cls):
        # pylint: disable=no-member
        super(TeamMembershipCsvTests, cls).setUpClass()
        teams_config = TeamsConfig({
            'team_sets': [
                {
                    'id': 'teamset_{}'.format(i),
                    'name': 'teamset_{}_name'.format(i),
                    'description': 'teamset_{}_desc'.format(i),
                }
                for i in [1, 2, 3, 4]
            ]
        })
        cls.course = CourseFactory(teams_configuration=teams_config)
        cls.course_no_teamsets = CourseFactory()

        team1_1 = CourseTeamFactory(course_id=cls.course.id, name='team_1_1', topic_id='teamset_1')
        CourseTeamFactory(course_id=cls.course.id, name='team_1_2', topic_id='teamset_1')
        team2_1 = CourseTeamFactory(course_id=cls.course.id, name='team_2_1', topic_id='teamset_2')
        team2_2 = CourseTeamFactory(course_id=cls.course.id, name='team_2_2', topic_id='teamset_2')
        team3_1 = CourseTeamFactory(course_id=cls.course.id, name='team_3_1', topic_id='teamset_3')
        # protected team
        team3_2 = CourseTeamFactory(
            course_id=cls.course.id,
            name='team_3_2',
            topic_id='teamset_3',
            organization_protected=True
        )
        #  No teams in teamset 4

        user1 = UserFactory.create(username='******')
        user2 = UserFactory.create(username='******')
        user3 = UserFactory.create(username='******')
        user4 = UserFactory.create(username='******')
        user5 = UserFactory.create(username='******')

        CourseEnrollmentFactory.create(user=user1, course_id=cls.course.id, mode='audit')
        CourseEnrollmentFactory.create(user=user2, course_id=cls.course.id, mode='verified')
        CourseEnrollmentFactory.create(user=user3, course_id=cls.course.id, mode='honors')
        CourseEnrollmentFactory.create(user=user4, course_id=cls.course.id, mode='masters')
        CourseEnrollmentFactory.create(user=user5, course_id=cls.course.id, mode='masters')

        team1_1.add_user(user1)
        team2_2.add_user(user1)
        team3_1.add_user(user1)

        team1_1.add_user(user2)
        team2_2.add_user(user2)
        team3_1.add_user(user2)

        team2_1.add_user(user3)
        team3_1.add_user(user3)

        team3_2.add_user(user4)
Example #15
0
    def setUpClass(cls):
        super().setUpClass()
        cls.teamset_id = 'teamset_id'
        teams_config = TeamsConfig({
            'team_sets': [{
                'id': cls.teamset_id,
                'name': 'teamset_name',
                'description': 'teamset_desc',
            }]
        })
        cls.course = CourseFactory(teams_configuration=teams_config)
        # pylint: disable=protected-access
        cls.header_fields = csv._get_team_membership_csv_headers(cls.course)

        cls.team = CourseTeamFactory(course_id=cls.course.id,
                                     name='team_name',
                                     topic_id=cls.teamset_id)

        cls.user_no_program = UserFactory.create()
        cls.user_in_program = UserFactory.create()
        cls.user_in_program_no_external_id = UserFactory.create()
        cls.user_in_program_not_enrolled_through_program = UserFactory.create()

        # user_no_program is only enrolled in the course
        cls.add_user_to_course_program_team(cls.user_no_program,
                                            enroll_in_program=False)

        # user_in_program is enrolled in the course and the program, with an external_id
        cls.external_user_key = 'externalProgramUserId-123'
        cls.add_user_to_course_program_team(
            cls.user_in_program, external_user_key=cls.external_user_key)

        # user_in_program is enrolled in the course and the program, with no external_id
        cls.add_user_to_course_program_team(cls.user_in_program_no_external_id)

        # user_in_program_not_enrolled_through_program is enrolled in a program and the course, but they not connected
        cls.add_user_to_course_program_team(
            cls.user_in_program_not_enrolled_through_program,
            connect_enrollments=False)

        # initialize import manager
        cls.import_manager = csv.TeamMembershipImportManager(cls.course)
        cls.import_manager.teamset_ids = {
            ts.teamset_id
            for ts in cls.course.teamsets
        }
Example #16
0
    def test_remove_from_team(self):
        # Given a user already in a course and on a team
        user = UserFactory.create(username='******')
        mode = 'audit'
        CourseEnrollmentFactory.create(user=user, course_id=self.course.id, mode=mode)
        team = CourseTeamFactory(course_id=self.course.id, name='team_1', topic_id='teamset_1')
        team.add_user(user)
        self.assertTrue(CourseTeamMembership.is_user_on_team(user, team))

        # When I try to remove them from the team
        csv_data = self._csv_reader_from_array([
            ['user', 'mode', 'teamset_1'],
            [user.username, mode, ''],
        ])
        result = self.import_manager.set_team_memberships(csv_data)

        # Then they are removed from the team and the correct events are issued
        self.assertFalse(CourseTeamMembership.is_user_on_team(user, team))
        self.assert_learner_removed_emitted(team.team_id, user.id)
Example #17
0
    def setUpClass(cls):
        super().setUpClass()
        cls.user1 = UserFactory.create(username='******')
        cls.user2 = UserFactory.create(username='******')
        cls.user3 = UserFactory.create(username='******')
        cls.user4 = UserFactory.create(username='******')

        topic_data = [
            (TOPIC1, TeamsetType.private_managed.value),
            (TOPIC2, TeamsetType.open.value),
            (TOPIC3, TeamsetType.public_managed.value)
        ]
        topics = [
            {
                'id': topic_id,
                'name': 'name-' + topic_id,
                'description': 'desc-' + topic_id,
                'type': teamset_type
            } for topic_id, teamset_type in topic_data
        ]
        teams_config_1 = TeamsConfig({'topics': [topics[0]]})
        teams_config_2 = TeamsConfig({'topics': [topics[1], topics[2]]})
        cls.course1 = CourseFactory(
            org=COURSE_KEY1.org,
            course=COURSE_KEY1.course,
            run=COURSE_KEY1.run,
            teams_configuration=teams_config_1,
        )
        cls.course2 = CourseFactory(
            org=COURSE_KEY2.org,
            course=COURSE_KEY2.course,
            run=COURSE_KEY2.run,
            teams_configuration=teams_config_2,
        )

        for user in (cls.user1, cls.user2, cls.user3, cls.user4):
            CourseEnrollmentFactory.create(user=user, course_id=COURSE_KEY1)

        for user in (cls.user3, cls.user4):
            CourseEnrollmentFactory.create(user=user, course_id=COURSE_KEY2)

        cls.team1 = CourseTeamFactory(
            course_id=COURSE_KEY1,
            discussion_topic_id=DISCUSSION_TOPIC_ID,
            team_id='team1',
            topic_id=TOPIC1,
        )
        cls.team1a = CourseTeamFactory(  # Same topic / team set as team1
            course_id=COURSE_KEY1,
            team_id='team1a',
            topic_id=TOPIC1,
        )
        cls.team2 = CourseTeamFactory(course_id=COURSE_KEY2, team_id='team2', topic_id=TOPIC2)
        cls.team2a = CourseTeamFactory(  # Same topic / team set as team2
            course_id=COURSE_KEY2,
            team_id='team2a',
            topic_id=TOPIC2
        )
        cls.team3 = CourseTeamFactory(course_id=COURSE_KEY2, team_id='team3', topic_id=TOPIC3)

        cls.team1.add_user(cls.user1)
        cls.team1.add_user(cls.user2)
        cls.team2.add_user(cls.user3)

        cls.team1a.add_user(cls.user4)
        cls.team2a.add_user(cls.user4)