Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions lms/djangoapps/teams/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,49 @@ def test_bad_course_id(self):
response = self.client.get(bad_team_url)
assert 404 == response.status_code

def test_team_dashboard_user_course_specific_team_list(self):
"""Verifies team dashboard is accurate after user is added to a specific course team."""

# Create a course two
course_two = CourseFactory.create(
teams_configuration=TeamsConfig({
"max_team_size": 1,
"topics": [
{
"name": "Test topic for course two",
"id": 1,
"description": "Description for test topic for course two."
}
]
})
)

# Login and enroll user in both courses
self.client.login(username=self.user.username, password=self.test_password)
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
CourseEnrollmentFactory.create(user=self.user, course_id=course_two.id)

# Create teams in both courses
course_one_team = CourseTeamFactory.create(name="Course one team", course_id=self.course.id, topic_id=1)
course_two_team = CourseTeamFactory.create( # pylint: disable=unused-variable
name="Course two team", course_id=course_two.id, topic_id=1,
)

# Check that initially list of user teams in course one is empty
course_one_teams_url = reverse('teams_dashboard', args=[self.course.id])
response = self.client.get(course_one_teams_url)
self.assertContains(response, '"teams": {"next": null, "previous": null, "count": 0')
# Add user to a course one team
course_one_team.add_user(self.user)

# Check that list of user teams in course one is not empty, it is one now
response = self.client.get(course_one_teams_url)
self.assertContains(response, '"teams": {"next": null, "previous": null, "count": 1')
# Check that list of user teams in course two is still empty
course_two_teams_url = reverse('teams_dashboard', args=[course_two.id])
response = self.client.get(course_two_teams_url)
self.assertContains(response, '"teams": {"next": null, "previous": null, "count": 0')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are doing substring-matching on JSON, right? It would be more robust to parse the JSON and query it, but up to you. (More important to restore these than to make them totally robust.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving this for the next person who wants to improve. Agree it would be nice.


@ddt.unpack
@ddt.data(
(True, False, False),
Expand Down Expand Up @@ -1046,6 +1089,32 @@ def test_duplicates_and_nontopic_private_teamsets(self):
team_names.sort()
assert team_names == [self.solar_team.name, self.masters_only_team.name]

def test_teams_list_for_user_for_specific_course(self):
"""Verifies teams list for user for specific course."""

# Create and enroll user in both courses
user = self.create_and_enroll_student(
courses=[self.test_course_1, self.test_course_2],
username='test_user_enrolled_both_courses'
)
course_one_data = {'course_id': str(self.test_course_1.id), 'username': user}
course_two_data = {'course_id': str(self.test_course_2.id), 'username': user}

# Check that initially list of user teams in course one is empty
team_list = self.get_teams_list(user=user, expected_status=200, data=course_one_data)
assert team_list['count'] == 0

# Add user to a course one team
self.solar_team.add_user(self.users[user])

# Check that list of user teams in course one is not empty now
team_list = self.get_teams_list(user=user, expected_status=200, data=course_one_data)
assert team_list['count'] == 1

# Check that list of user teams in course two is still empty
team_list = self.get_teams_list(user=user, expected_status=200, data=course_two_data)
assert team_list['count'] == 0

def _add_missing_user(self, missing_user):
"""
django32 TestCase.setUpTestData() are now isolated for each test method.
Expand Down