refactor: Move BetaTesterFactory helper to common/

This commit is contained in:
stvn
2021-04-13 19:35:02 -07:00
parent 22fb1ec124
commit ffcfc05a61
12 changed files with 25 additions and 29 deletions

View File

@@ -26,6 +26,7 @@ from common.djangoapps.student.models import (
UserStanding
)
from common.djangoapps.student.roles import GlobalStaff
from common.djangoapps.student.roles import CourseBetaTesterRole
from common.djangoapps.student.roles import CourseInstructorRole
from common.djangoapps.student.roles import CourseStaffRole
@@ -232,6 +233,20 @@ class AccountRecoveryFactory(DjangoModelFactory): # lint-amnesty, pylint: disab
# pylint: disable=unused-argument
class BetaTesterFactory(UserFactory):
"""
Given a course Location, returns a User object with beta-tester
permissions for `course`.
"""
last_name = 'Beta-Tester'
@factory.post_generation
def course_key(self, _create, extracted, **kwargs):
if extracted is None:
raise ValueError('Must specify a CourseKey for a beta-tester user')
CourseBetaTesterRole(extracted).add_users(self)
class GlobalStaffFactory(UserFactory):
"""
Returns a User object with global staff access