refactor: replace some create_user with UserFactory to avoid non-existent profile errors

This commit is contained in:
Maria Grimaldi
2021-08-23 17:55:03 -04:00
parent b7dfaa9b17
commit 2ee52ea96c
24 changed files with 142 additions and 86 deletions

View File

@@ -3,13 +3,12 @@ Tests access.py
"""
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.test import TestCase
from opaque_keys.edx.locator import CourseLocator
from common.djangoapps.student.auth import add_users
from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole
from common.djangoapps.student.tests.factories import AdminFactory
from common.djangoapps.student.tests.factories import AdminFactory, UserFactory
from ..access import get_user_role
@@ -23,8 +22,16 @@ class RolesTest(TestCase):
super().setUp()
self.global_admin = AdminFactory()
self.instructor = User.objects.create_user('testinstructor', 'testinstructor+courses@edx.org', 'foo')
self.staff = User.objects.create_user('teststaff', 'teststaff+courses@edx.org', 'foo')
self.instructor = UserFactory.create(
username='testinstructor',
email='testinstructor+courses@edx.org',
password='foo',
)
self.staff = UserFactory.create(
username='teststaff',
email='teststaff+courses@edx.org',
password='foo',
)
self.course_key = CourseLocator('mitX', '101', 'test')
def test_get_user_role_instructor(self):

View File

@@ -12,18 +12,21 @@ from cms.djangoapps.contentstore.utils import reverse_course_url
from common.djangoapps.student import auth
from common.djangoapps.student.models import CourseEnrollment
from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole
from common.djangoapps.student.tests.factories import UserFactory
class UsersTestCase(CourseTestCase): # lint-amnesty, pylint: disable=missing-class-docstring
def setUp(self):
super().setUp()
self.ext_user = User.objects.create_user(
"joe", "joe@comedycentral.com", "haha")
self.ext_user = UserFactory.create(
username="joe", email="joe@comedycentral.com", password="haha",
)
self.ext_user.is_active = True
self.ext_user.is_staff = False
self.ext_user.save()
self.inactive_user = User.objects.create_user(
"carl", "carl@comedycentral.com", "haha")
self.inactive_user = UserFactory.create(
username="carl", email="carl@comedycentral.com", password="haha",
)
self.inactive_user.is_active = False
self.inactive_user.is_staff = False
self.inactive_user.save()