66import pytest
77
88from ccx_keys .locator import CCXLocator
9- from django .contrib .auth .models import AnonymousUser , User # lint-amnesty, pylint: disable=imported-auth-user
9+ from django .contrib .auth .models import AnonymousUser
1010from django .core .exceptions import PermissionDenied
1111from django .test import TestCase
1212from opaque_keys .edx .locator import CourseLocator
1313
1414from common .djangoapps .student .auth import add_users , has_studio_read_access , has_studio_write_access , remove_users , user_has_role # lint-amnesty, pylint: disable=line-too-long
1515from common .djangoapps .student .roles import CourseCreatorRole , CourseInstructorRole , CourseStaffRole
16- from common .djangoapps .student .tests .factories import AdminFactory
16+ from common .djangoapps .student .tests .factories import AdminFactory , UserFactory
1717
1818
1919class CreatorGroupTest (TestCase ):
@@ -24,8 +24,12 @@ class CreatorGroupTest(TestCase):
2424 def setUp (self ):
2525 """ Test case setup """
2626 super ().setUp ()
27- self .
user = User .
objects .
create_user (
'testuser' ,
'[email protected] ' ,
'foo' )
28- self .
admin = User .
objects .
create_user (
'Mark' ,
'[email protected] ' ,
'foo' )
27+ self .user = UserFactory .create (
28+ username = 'testuser' ,
email = '[email protected] ' ,
password = 'foo' ,
29+ )
30+ self .admin = UserFactory .create (
31+ username = 'Mark' ,
email = '[email protected] ' ,
password = 'foo' ,
32+ )
2933 self .admin .is_staff = True
3034
3135 def test_creator_group_not_enabled (self ):
@@ -51,7 +55,7 @@ def test_creator_group_enabled_nonempty(self):
5155 assert user_has_role (self .user , CourseCreatorRole ())
5256
5357 # check that a user who has not been added to the group still returns false
54- user_not_added = User . objects . create_user ( 'testuser2' ,
'[email protected] ' ,
'foo2' )
58+ user_not_added = UserFactory . create ( username = 'testuser2' ,
email = '[email protected] ' ,
password = 'foo2' )
5559 assert not user_has_role (user_not_added , CourseCreatorRole ())
5660
5761 # remove first user from the group and verify that CourseCreatorRole().has_user now returns false
@@ -153,7 +157,7 @@ def setUp(self):
153157 """
154158 super ().setUp ()
155159 self .global_admin = AdminFactory ()
156- self .
staff = User . objects . create_user ( 'teststaff' ,
'[email protected] ' ,
'foo' )
160+ self .
staff = UserFactory . create ( username = 'teststaff' ,
email = '[email protected] ' ,
password = 'foo' )
157161 self .ccx_course_key = CCXLocator .from_string ('ccx-v1:edX+DemoX+Demo_Course+ccx@1' )
158162 add_users (self .global_admin , CourseStaffRole (self .ccx_course_key ), self .staff )
159163
@@ -191,8 +195,12 @@ def setUp(self):
191195 """ Test case setup """
192196 super ().setUp ()
193197 self .global_admin = AdminFactory ()
194- self .
creator = User .
objects .
create_user (
'testcreator' ,
'[email protected] ' ,
'foo' )
195- self .
staff = User .
objects .
create_user (
'teststaff' ,
'[email protected] ' ,
'foo' )
198+ self .creator = UserFactory .create (
199+ username = 'testcreator' ,
email = '[email protected] ' ,
password = 'foo' ,
200+ )
201+ self .staff = UserFactory .create (
202+ username = 'teststaff' ,
email = '[email protected] ' ,
password = 'foo' ,
203+ )
196204 self .course_key = CourseLocator ('mitX' , '101' , 'test' )
197205
198206 def test_add_user_to_course_group (self ):
@@ -240,7 +248,9 @@ def test_remove_user_from_course_group_permission_denied(self):
240248 Verifies PermissionDenied if caller of remove_user_from_course_group is not instructor role.
241249 """
242250 add_users (self .global_admin , CourseInstructorRole (self .course_key ), self .creator )
243- another_staff = User .
objects .
create_user (
'another' ,
'[email protected] ' ,
'foo' )
251+ another_staff = UserFactory .create (
252+ username = 'another' ,
email = '[email protected] ' ,
password = 'foo' ,
253+ )
244254 add_users (self .global_admin , CourseStaffRole (self .course_key ), self .creator , self .staff , another_staff )
245255 with pytest .raises (PermissionDenied ):
246256 remove_users (self .staff , CourseStaffRole (self .course_key ), another_staff )
0 commit comments