-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
factories.py
87 lines (68 loc) · 2.11 KB
/
factories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Build courseware-centric test factories
Generic, LMS-agnostic factories can be found in:
`common.djangoapps.student.tests.factories.py`
"""
import json
from functools import partial
import factory
from factory.django import DjangoModelFactory
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import CourseLocator
from common.djangoapps.student.tests.factories import UserFactory
from lms.djangoapps.courseware.models import (
StudentModule,
XModuleStudentInfoField,
XModuleStudentPrefsField,
XModuleUserStateSummaryField,
FinancialAssistanceConfiguration
)
COURSE_KEY = CourseKey.from_string('edX/test_course/test')
LOCATION = partial(COURSE_KEY.make_usage_key, 'problem')
class StudentModuleFactory(DjangoModelFactory):
"""
Build StudentModule models
"""
class Meta:
model = StudentModule
module_type = "problem"
student = factory.SubFactory(UserFactory)
course_id = CourseLocator("MITx", "999", "Robot_Super_Course")
state = None
grade = None
max_grade = None
done = 'na'
class UserStateSummaryFactory(DjangoModelFactory):
"""
Build XModuleUserStateSummaryField models
"""
class Meta:
model = XModuleUserStateSummaryField
field_name = 'existing_field'
value = json.dumps('old_value')
usage_id = LOCATION('usage_id')
class StudentPrefsFactory(DjangoModelFactory):
"""
Build XModuleStudentPrefsField models
"""
class Meta:
model = XModuleStudentPrefsField
field_name = 'existing_field'
value = json.dumps('old_value')
student = factory.SubFactory(UserFactory)
module_type = 'mock_problem'
class StudentInfoFactory(DjangoModelFactory):
"""
Build XModuleStudentInfoField models
"""
class Meta:
model = XModuleStudentInfoField
field_name = 'existing_field'
value = json.dumps('old_value')
student = factory.SubFactory(UserFactory)
class FinancialAssistanceConfigurationFactory(DjangoModelFactory):
"""
Factory for FinancialAssistanceConfiguration model.
"""
class Meta:
model = FinancialAssistanceConfiguration