From aa16142659fd2c4b925bcc5c2d1992fbf6888a4e Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Sat, 2 Oct 2021 00:45:18 +0500 Subject: [PATCH 1/5] fix: Fixing test due to the change in django32. Objects assigned to class attributes in TestCase.setUpTestData() are now isolated for each test method. https://docs.djangoproject.com/en/3.2/releases/3.2/#tests BOM-2866 --- lms/djangoapps/teams/tests/test_views.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index 42d5d651ae..d67e86068b 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -373,15 +373,17 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): teams_configuration=teams_configuration_2 ) + cls.users = { + 'staff': AdminFactory.create(password=cls.test_password), + 'course_staff': StaffFactory.create(course_key=cls.test_course_1.id, password=cls.test_password), + 'admin': AdminFactory.create(password=cls.test_password) + } + + @classmethod def setUpTestData(cls): super().setUpTestData() cls.topics_count = 6 - cls.users = { - 'staff': AdminFactory.create(password=cls.test_password), - 'course_staff': StaffFactory.create(course_key=cls.test_course_1.id, password=cls.test_password), - 'admin': AdminFactory.create(password=cls.test_password) - } cls.create_and_enroll_student(username='student_enrolled') cls.create_and_enroll_student(username='student_on_team_1_private_set_1', mode=CourseMode.MASTERS) cls.create_and_enroll_student(username='student_on_team_2_private_set_1', mode=CourseMode.MASTERS) From 7eb00d63c55315050d551ec8914c0b8d31a07405 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Sat, 2 Oct 2021 00:45:38 +0500 Subject: [PATCH 2/5] fix: Fixing test due to the change in django32. Objects assigned to class attributes in TestCase.setUpTestData() are now isolated for each test method. https://docs.djangoproject.com/en/3.2/releases/3.2/#tests BOM-2866 --- lms/djangoapps/teams/tests/test_views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index d67e86068b..4e521a6a3e 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -379,7 +379,6 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): 'admin': AdminFactory.create(password=cls.test_password) } - @classmethod def setUpTestData(cls): super().setUpTestData() From c5f3d75c2bdb8c808609e90ffbf7ac2d193a0307 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Sat, 2 Oct 2021 16:15:32 +0500 Subject: [PATCH 3/5] fix: Fixing test due to the change in django32. Objects assigned to class attributes in TestCase.setUpTestData() are now isolated for each test method. https://docs.djangoproject.com/en/3.2/releases/3.2/#tests BOM-2866 --- lms/djangoapps/teams/tests/test_views.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index 4e521a6a3e..c9914d2979 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -13,6 +13,7 @@ import ddt import pytz from dateutil import parser from django.conf import settings +from django.contrib.auth.models import User from django.core.files.uploadedfile import SimpleUploadedFile from django.db.models.signals import post_save from django.urls import reverse @@ -373,16 +374,15 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): teams_configuration=teams_configuration_2 ) - cls.users = { - 'staff': AdminFactory.create(password=cls.test_password), - 'course_staff': StaffFactory.create(course_key=cls.test_course_1.id, password=cls.test_password), - 'admin': AdminFactory.create(password=cls.test_password) - } - @classmethod def setUpTestData(cls): super().setUpTestData() cls.topics_count = 6 + cls.users = { + 'staff': AdminFactory.create(password=cls.test_password), + 'course_staff': StaffFactory.create(course_key=cls.test_course_1.id, password=cls.test_password), + 'admin': AdminFactory.create(password=cls.test_password) + } cls.create_and_enroll_student(username='student_enrolled') cls.create_and_enroll_student(username='student_on_team_1_private_set_1', mode=CourseMode.MASTERS) cls.create_and_enroll_student(username='student_on_team_2_private_set_1', mode=CourseMode.MASTERS) @@ -598,6 +598,10 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): student_inactive.is_active = False student_inactive.save() else: + if user not in self.users: + missing_user = User.objects.get(username=user) + self.users[missing_user.username] = missing_user + self.client.login(username=self.users[user].username, password=self.test_password) def make_call(self, url, expected_status=200, method='get', data=None, content_type=None, **kwargs): From b3459b35893db7a558221894f58932375984d9da Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Sat, 2 Oct 2021 17:04:03 +0500 Subject: [PATCH 4/5] fix: Fixing test due to the change in django32. Objects assigned to class attributes in TestCase.setUpTestData() are now isolated for each test method. https://docs.djangoproject.com/en/3.2/releases/3.2/#tests BOM-2866 --- lms/djangoapps/teams/tests/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index c9914d2979..a8a706afca 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -13,7 +13,7 @@ import ddt import pytz from dateutil import parser from django.conf import settings -from django.contrib.auth.models import User +from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.files.uploadedfile import SimpleUploadedFile from django.db.models.signals import post_save from django.urls import reverse From 34a1cff1783b568921d42f048f392678b5da521c Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Sun, 3 Oct 2021 01:37:49 +0500 Subject: [PATCH 5/5] fix: django32 --- lms/djangoapps/teams/tests/test_views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index a8a706afca..85aa6db58c 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -1057,6 +1057,10 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase): yet_another_student_username = 'yet_another_student' self.create_and_enroll_student(username=another_student_username) self.create_and_enroll_student(username=yet_another_student_username) + + self._add_missing_user(another_student_username) + self._add_missing_user(yet_another_student_username) + self.solar_team.add_user(self.users[another_student_username]) self.solar_team.add_user(self.users[yet_another_student_username]) @@ -1070,6 +1074,15 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase): team_names.sort() assert team_names == [self.solar_team.name, self.masters_only_team.name] + def _add_missing_user(self, missing_user): + """ + django32 TestCase.setUpTestData() are now isolated for each test method. + In case of missing user adding this to list. + """ + if missing_user not in self.users: + missing_user = User.objects.get(username=missing_user) + self.users[missing_user.username] = missing_user + @ddt.ddt class TestCreateTeamAPI(EventTestMixin, TeamAPITestCase):