Adds Staff and Instructor factories
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
"""Provides factories for student models."""
|
||||
from student.models import (User, UserProfile, Registration,
|
||||
CourseEnrollmentAllowed, CourseEnrollment,
|
||||
PendingEmailChange, UserStanding,
|
||||
@@ -10,7 +11,7 @@ from uuid import uuid4
|
||||
from pytz import UTC
|
||||
|
||||
# Factories don't have __init__ methods, and are self documenting
|
||||
# pylint: disable=W0232
|
||||
# pylint: disable=W0232, C0111
|
||||
|
||||
|
||||
class GroupFactory(DjangoModelFactory):
|
||||
@@ -18,6 +19,7 @@ class GroupFactory(DjangoModelFactory):
|
||||
|
||||
name = u'staff_MITx/999/Robot_Super_Course'
|
||||
|
||||
|
||||
class UserStandingFactory(DjangoModelFactory):
|
||||
FACTORY_FOR = UserStanding
|
||||
|
||||
@@ -47,6 +49,7 @@ class CourseModeFactory(DjangoModelFactory):
|
||||
suggested_prices = ''
|
||||
currency = 'usd'
|
||||
|
||||
|
||||
class RegistrationFactory(DjangoModelFactory):
|
||||
FACTORY_FOR = Registration
|
||||
|
||||
@@ -70,7 +73,7 @@ class UserFactory(DjangoModelFactory):
|
||||
date_joined = datetime(2011, 1, 1, tzinfo=UTC)
|
||||
|
||||
@post_generation
|
||||
def profile(obj, create, extracted, **kwargs):
|
||||
def profile(obj, create, extracted, **kwargs): # pylint: disable=unused-argument
|
||||
if create:
|
||||
obj.save()
|
||||
return UserProfileFactory.create(user=obj, **kwargs)
|
||||
|
||||
@@ -11,7 +11,9 @@ from django.core.management import call_command
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
|
||||
from student.tests.factories import UserFactory, GroupFactory, CourseEnrollmentFactory
|
||||
from student.tests.factories import CourseEnrollmentFactory, UserFactory
|
||||
from courseware.tests.factories import StaffFactory, InstructorFactory
|
||||
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from bulk_email.models import Optout
|
||||
@@ -47,16 +49,11 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
|
||||
@patch.dict(settings.MITX_FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
|
||||
def setUp(self):
|
||||
self.course = CourseFactory.create()
|
||||
self.instructor = UserFactory.create(username="instructor", email="robot+instructor@edx.org")
|
||||
# Create instructor group for course
|
||||
instructor_group = GroupFactory.create(name="instructor_MITx/999/Robot_Super_Course")
|
||||
instructor_group.user_set.add(self.instructor)
|
||||
|
||||
self.instructor = InstructorFactory(self.course)
|
||||
|
||||
# Create staff
|
||||
self.staff = [UserFactory() for _ in xrange(STAFF_COUNT)]
|
||||
staff_group = GroupFactory()
|
||||
for staff in self.staff:
|
||||
staff_group.user_set.add(staff) # pylint: disable=E1101
|
||||
self.staff = [StaffFactory(self.course) for _ in xrange(STAFF_COUNT)]
|
||||
|
||||
# Create students
|
||||
self.students = [UserFactory() for _ in xrange(STUDENT_COUNT)]
|
||||
|
||||
@@ -10,6 +10,7 @@ from student.tests.factories import CourseEnrollmentAllowedFactory as StudentCou
|
||||
from student.tests.factories import RegistrationFactory as StudentRegistrationFactory
|
||||
from courseware.models import StudentModule, XModuleUserStateSummaryField
|
||||
from courseware.models import XModuleStudentInfoField, XModuleStudentPrefsField
|
||||
from instructor.access import allow_access
|
||||
|
||||
from xmodule.modulestore import Location
|
||||
from pytz import UTC
|
||||
@@ -33,6 +34,26 @@ class UserFactory(StudentUserFactory):
|
||||
date_joined = datetime.now(UTC)
|
||||
|
||||
|
||||
def InstructorFactory(course): # pylint: disable=invalid-name
|
||||
"""
|
||||
Given a course object, returns a User object with instructor
|
||||
permissions for `course`.
|
||||
"""
|
||||
user = StudentUserFactory.create(last_name="Instructor")
|
||||
allow_access(course, user, "instructor")
|
||||
return user
|
||||
|
||||
|
||||
def StaffFactory(course): # pylint: disable=invalid-name
|
||||
"""
|
||||
Given a course object, returns a User object with staff
|
||||
permissions for `course`.
|
||||
"""
|
||||
user = StudentUserFactory.create(last_name="Staff")
|
||||
allow_access(course, user, "staff")
|
||||
return user
|
||||
|
||||
|
||||
class GroupFactory(StudentGroupFactory):
|
||||
name = 'test_group'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user