Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
198452cd
Commit
198452cd
authored
Nov 01, 2013
by
Sarina Canelake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds Staff and Instructor factories
parent
eb0e09d6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
11 deletions
+32
-11
common/djangoapps/student/tests/factories.py
+5
-2
lms/djangoapps/bulk_email/tests/test_email.py
+6
-9
lms/djangoapps/courseware/tests/factories.py
+21
-0
No files found.
common/djangoapps/student/tests/factories.py
View file @
198452cd
"""Provides factories for student models."""
from
student.models
import
(
User
,
UserProfile
,
Registration
,
from
student.models
import
(
User
,
UserProfile
,
Registration
,
CourseEnrollmentAllowed
,
CourseEnrollment
,
CourseEnrollmentAllowed
,
CourseEnrollment
,
PendingEmailChange
,
UserStanding
,
PendingEmailChange
,
UserStanding
,
...
@@ -10,7 +11,7 @@ from uuid import uuid4
...
@@ -10,7 +11,7 @@ from uuid import uuid4
from
pytz
import
UTC
from
pytz
import
UTC
# Factories don't have __init__ methods, and are self documenting
# Factories don't have __init__ methods, and are self documenting
# pylint: disable=W0232
# pylint: disable=W0232
, C0111
class
GroupFactory
(
DjangoModelFactory
):
class
GroupFactory
(
DjangoModelFactory
):
...
@@ -18,6 +19,7 @@ class GroupFactory(DjangoModelFactory):
...
@@ -18,6 +19,7 @@ class GroupFactory(DjangoModelFactory):
name
=
u'staff_MITx/999/Robot_Super_Course'
name
=
u'staff_MITx/999/Robot_Super_Course'
class
UserStandingFactory
(
DjangoModelFactory
):
class
UserStandingFactory
(
DjangoModelFactory
):
FACTORY_FOR
=
UserStanding
FACTORY_FOR
=
UserStanding
...
@@ -47,6 +49,7 @@ class CourseModeFactory(DjangoModelFactory):
...
@@ -47,6 +49,7 @@ class CourseModeFactory(DjangoModelFactory):
suggested_prices
=
''
suggested_prices
=
''
currency
=
'usd'
currency
=
'usd'
class
RegistrationFactory
(
DjangoModelFactory
):
class
RegistrationFactory
(
DjangoModelFactory
):
FACTORY_FOR
=
Registration
FACTORY_FOR
=
Registration
...
@@ -70,7 +73,7 @@ class UserFactory(DjangoModelFactory):
...
@@ -70,7 +73,7 @@ class UserFactory(DjangoModelFactory):
date_joined
=
datetime
(
2011
,
1
,
1
,
tzinfo
=
UTC
)
date_joined
=
datetime
(
2011
,
1
,
1
,
tzinfo
=
UTC
)
@post_generation
@post_generation
def
profile
(
obj
,
create
,
extracted
,
**
kwargs
):
def
profile
(
obj
,
create
,
extracted
,
**
kwargs
):
# pylint: disable=unused-argument
if
create
:
if
create
:
obj
.
save
()
obj
.
save
()
return
UserProfileFactory
.
create
(
user
=
obj
,
**
kwargs
)
return
UserProfileFactory
.
create
(
user
=
obj
,
**
kwargs
)
...
...
lms/djangoapps/bulk_email/tests/test_email.py
View file @
198452cd
...
@@ -11,7 +11,9 @@ from django.core.management import call_command
...
@@ -11,7 +11,9 @@ from django.core.management import call_command
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
courseware.tests.tests
import
TEST_DATA_MONGO_MODULESTORE
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.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
bulk_email.models
import
Optout
from
bulk_email.models
import
Optout
...
@@ -47,16 +49,11 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -47,16 +49,11 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
@patch.dict
(
settings
.
MITX_FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
@patch.dict
(
settings
.
MITX_FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
self
.
instructor
=
UserFactory
.
create
(
username
=
"instructor"
,
email
=
"robot+instructor@edx.org"
)
# Create instructor group for course
self
.
instructor
=
InstructorFactory
(
self
.
course
)
instructor_group
=
GroupFactory
.
create
(
name
=
"instructor_MITx/999/Robot_Super_Course"
)
instructor_group
.
user_set
.
add
(
self
.
instructor
)
# Create staff
# Create staff
self
.
staff
=
[
UserFactory
()
for
_
in
xrange
(
STAFF_COUNT
)]
self
.
staff
=
[
StaffFactory
(
self
.
course
)
for
_
in
xrange
(
STAFF_COUNT
)]
staff_group
=
GroupFactory
()
for
staff
in
self
.
staff
:
staff_group
.
user_set
.
add
(
staff
)
# pylint: disable=E1101
# Create students
# Create students
self
.
students
=
[
UserFactory
()
for
_
in
xrange
(
STUDENT_COUNT
)]
self
.
students
=
[
UserFactory
()
for
_
in
xrange
(
STUDENT_COUNT
)]
...
...
lms/djangoapps/courseware/tests/factories.py
View file @
198452cd
...
@@ -10,6 +10,7 @@ from student.tests.factories import CourseEnrollmentAllowedFactory as StudentCou
...
@@ -10,6 +10,7 @@ from student.tests.factories import CourseEnrollmentAllowedFactory as StudentCou
from
student.tests.factories
import
RegistrationFactory
as
StudentRegistrationFactory
from
student.tests.factories
import
RegistrationFactory
as
StudentRegistrationFactory
from
courseware.models
import
StudentModule
,
XModuleUserStateSummaryField
from
courseware.models
import
StudentModule
,
XModuleUserStateSummaryField
from
courseware.models
import
XModuleStudentInfoField
,
XModuleStudentPrefsField
from
courseware.models
import
XModuleStudentInfoField
,
XModuleStudentPrefsField
from
instructor.access
import
allow_access
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
pytz
import
UTC
from
pytz
import
UTC
...
@@ -33,6 +34,26 @@ class UserFactory(StudentUserFactory):
...
@@ -33,6 +34,26 @@ class UserFactory(StudentUserFactory):
date_joined
=
datetime
.
now
(
UTC
)
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
):
class
GroupFactory
(
StudentGroupFactory
):
name
=
'test_group'
name
=
'test_group'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment