Commit edf88962 by Muhammad Ammar

Merge pull request #9534 from edx/ammar/update-factory-boy

Update factory_boy
parents 56fd445f 6a5ce5d5
......@@ -6,7 +6,8 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
# Factories are self documenting
# pylint: disable=missing-docstring
class CourseModeFactory(DjangoModelFactory):
FACTORY_FOR = CourseMode
class Meta(object):
model = CourseMode
course_id = SlashSeparatedCourseKey('MITx', '999', 'Robot_Super_Course')
mode_slug = 'audit'
......
......@@ -17,14 +17,16 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
class GroupFactory(DjangoModelFactory):
FACTORY_FOR = Group
FACTORY_DJANGO_GET_OR_CREATE = ('name', )
class Meta(object):
model = Group
django_get_or_create = ('name', )
name = factory.Sequence(u'group{0}'.format)
class UserStandingFactory(DjangoModelFactory):
FACTORY_FOR = UserStanding
class Meta(object):
model = UserStanding
user = None
account_status = None
......@@ -32,8 +34,9 @@ class UserStandingFactory(DjangoModelFactory):
class UserProfileFactory(DjangoModelFactory):
FACTORY_FOR = UserProfile
FACTORY_DJANGO_GET_OR_CREATE = ('user', )
class Meta(object):
model = UserProfile
django_get_or_create = ('user', )
user = None
name = factory.LazyAttribute(u'{0.user.first_name} {0.user.last_name}'.format)
......@@ -45,7 +48,8 @@ class UserProfileFactory(DjangoModelFactory):
class CourseModeFactory(DjangoModelFactory):
FACTORY_FOR = CourseMode
class Meta(object):
model = CourseMode
course_id = None
mode_display_name = u'Honor Code',
......@@ -57,15 +61,17 @@ class CourseModeFactory(DjangoModelFactory):
class RegistrationFactory(DjangoModelFactory):
FACTORY_FOR = Registration
class Meta(object):
model = Registration
user = None
activation_key = uuid4().hex.decode('ascii')
class UserFactory(DjangoModelFactory):
FACTORY_FOR = User
FACTORY_DJANGO_GET_OR_CREATE = ('email', 'username')
class Meta(object):
model = User
django_get_or_create = ('email', 'username')
username = factory.Sequence(u'robot{0}'.format)
email = factory.Sequence(u'robot+test+{0}@edx.org'.format)
......@@ -101,7 +107,8 @@ class UserFactory(DjangoModelFactory):
class AnonymousUserFactory(factory.Factory):
FACTORY_FOR = AnonymousUser
class Meta(object):
model = AnonymousUser
class AdminFactory(UserFactory):
......@@ -109,14 +116,16 @@ class AdminFactory(UserFactory):
class CourseEnrollmentFactory(DjangoModelFactory):
FACTORY_FOR = CourseEnrollment
class Meta(object):
model = CourseEnrollment
user = factory.SubFactory(UserFactory)
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
class CourseAccessRoleFactory(DjangoModelFactory):
FACTORY_FOR = CourseAccessRole
class Meta(object):
model = CourseAccessRole
user = factory.SubFactory(UserFactory)
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
......@@ -124,7 +133,8 @@ class CourseAccessRoleFactory(DjangoModelFactory):
class CourseEnrollmentAllowedFactory(DjangoModelFactory):
FACTORY_FOR = CourseEnrollmentAllowed
class Meta(object):
model = CourseEnrollmentAllowed
email = 'test@edx.org'
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
......@@ -137,7 +147,8 @@ class PendingEmailChangeFactory(DjangoModelFactory):
new_email: sequence of new+email+{}@edx.org
activation_key: sequence of integers, padded to 30 characters
"""
FACTORY_FOR = PendingEmailChange
class Meta(object):
model = PendingEmailChange
user = factory.SubFactory(UserFactory)
new_email = factory.Sequence(u'new+email+{0}@edx.org'.format)
......
......@@ -8,6 +8,7 @@ from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.conf import settings
from django.contrib.auth.models import User
from django.core.cache import cache
from django.core.urlresolvers import reverse, NoReverseMatch
from django.http import HttpResponseBadRequest, HttpResponse
......@@ -252,7 +253,7 @@ class LoginTest(TestCase):
self._assert_response(response, success=True)
# Reload the user from the database
self.user = UserFactory.FACTORY_FOR.objects.get(pk=self.user.pk)
self.user = User.objects.get(pk=self.user.pk)
self.assertEqual(self.user.profile.get_meta()['session_id'], client1.session.session_key)
......
......@@ -71,10 +71,11 @@ class XModuleFactory(Factory):
Factory for XModules
"""
# We have to give a Factory a FACTORY_FOR.
# We have to give a model for Factory.
# However, the class that we create is actually determined by the category
# specified in the factory
FACTORY_FOR = Dummy
class Meta(object): # pylint: disable=missing-docstring
model = Dummy
@lazy_attribute
def modulestore(self):
......
......@@ -104,7 +104,8 @@ class ModuleSystemFactory(Factory):
performed by :func:`xmodule.tests.get_test_system`, so
arguments for that function are valid factory attributes.
"""
FACTORY_FOR = ModuleSystem
class Meta(object): # pylint: disable=missing-docstring
model = ModuleSystem
@classmethod
def _build(cls, target_class, *args, **kwargs): # pylint: disable=unused-argument
......@@ -119,7 +120,8 @@ class DescriptorSystemFactory(Factory):
performed by :func:`xmodule.tests.get_test_descriptor_system`, so
arguments for that function are valid factory attributes.
"""
FACTORY_FOR = DescriptorSystem
class Meta(object): # pylint: disable=missing-docstring
model = DescriptorSystem
@classmethod
def _build(cls, target_class, *args, **kwargs): # pylint: disable=unused-argument
......@@ -190,7 +192,8 @@ class LeafDescriptorFactory(Factory):
"""
# pylint: disable=missing-docstring
FACTORY_FOR = XModuleDescriptor
class Meta(object):
model = XModuleDescriptor
runtime = SubFactory(DescriptorSystemFactory)
url_name = LazyAttributeSequence('{.block_type}_{}'.format)
......
......@@ -64,7 +64,8 @@ class XmlImportFactory(Factory):
Factory for generating XmlImportData's, which can hold all the data needed
to run an XModule XML import
"""
FACTORY_FOR = XmlImportData
class Meta(object): # pylint: disable=missing-docstring
model = XmlImportData
filesystem = MemoryFS()
xblock_mixins = (InheritanceMixin, XModuleMixin)
......
......@@ -12,7 +12,8 @@ from . import COMMENTS_STUB_URL
class ContentFactory(factory.Factory):
FACTORY_FOR = dict
class Meta(object): # pylint: disable=missing-docstring
model = dict
id = None
user_id = "1234"
username = "dummy-username"
......@@ -63,7 +64,8 @@ class Response(Comment):
class SearchResult(factory.Factory):
FACTORY_FOR = dict
class Meta(object): # pylint: disable=missing-docstring
model = dict
discussion_data = []
annotated_content_info = {}
num_pages = 1
......
......@@ -10,7 +10,8 @@ from . import EDXNOTES_STUB_URL
class Range(factory.Factory):
FACTORY_FOR = dict
class Meta(object): # pylint: disable=missing-docstring
model = dict
start = "/div[1]/p[1]"
end = "/div[1]/p[1]"
startOffset = 0
......@@ -18,7 +19,8 @@ class Range(factory.Factory):
class Note(factory.Factory):
FACTORY_FOR = dict
class Meta(object): # pylint: disable=missing-docstring
model = dict
user = "dummy-user"
usage_id = "dummy-usage-id"
course_id = "dummy-course-id"
......
......@@ -8,7 +8,8 @@ from ccx.models import CustomCourseForEdX # pylint: disable=import-error
class CcxFactory(DjangoModelFactory): # pylint: disable=missing-docstring
FACTORY_FOR = CustomCourseForEdX
class Meta(object): # pylint: disable=missing-docstring
model = CustomCourseForEdX
display_name = "Test CCX"
id = None # pylint: disable=redefined-builtin, invalid-name
coach = SubFactory(UserFactory)
# Factories are self documenting
# pylint: disable=missing-docstring
import factory
from django.core.files.base import ContentFile
from factory.django import DjangoModelFactory, ImageField
from student.models import LinkedInAddToProfileConfiguration
......@@ -12,7 +14,8 @@ from certificates.models import (
class GeneratedCertificateFactory(DjangoModelFactory):
FACTORY_FOR = GeneratedCertificate
class Meta(object):
model = GeneratedCertificate
course_id = None
status = CertificateStatuses.unavailable
......@@ -22,29 +25,39 @@ class GeneratedCertificateFactory(DjangoModelFactory):
class CertificateWhitelistFactory(DjangoModelFactory):
FACTORY_FOR = CertificateWhitelist
class Meta(object):
model = CertificateWhitelist
course_id = None
whitelist = True
class BadgeAssertionFactory(DjangoModelFactory):
FACTORY_FOR = BadgeAssertion
class Meta(object):
model = BadgeAssertion
mode = 'honor'
class BadgeImageConfigurationFactory(DjangoModelFactory):
FACTORY_FOR = BadgeImageConfiguration
class Meta(object):
model = BadgeImageConfiguration
mode = 'honor'
icon = ImageField(color='blue', height=50, width=50, filename='test.png', format='PNG')
icon = factory.LazyAttribute(
lambda _: ContentFile(
ImageField()._make_data( # pylint: disable=protected-access
{'color': 'blue', 'width': 50, 'height': 50, 'format': 'PNG'}
), 'test.png'
)
)
class CertificateHtmlViewConfigurationFactory(DjangoModelFactory):
FACTORY_FOR = CertificateHtmlViewConfiguration
class Meta(object):
model = CertificateHtmlViewConfiguration
enabled = True
configuration = """{
......@@ -76,7 +89,8 @@ class CertificateHtmlViewConfigurationFactory(DjangoModelFactory):
class LinkedInAddToProfileConfigurationFactory(DjangoModelFactory):
FACTORY_FOR = LinkedInAddToProfileConfiguration
class Meta(object):
model = LinkedInAddToProfileConfiguration
enabled = True
company_identifier = "0_0dPSPyS070e0HsE9HNz_13_d11_"
......
......@@ -123,7 +123,8 @@ class GlobalStaffFactory(UserFactory):
class StudentModuleFactory(DjangoModelFactory):
FACTORY_FOR = StudentModule
class Meta(object):
model = StudentModule
module_type = "problem"
student = factory.SubFactory(UserFactory)
......@@ -135,7 +136,8 @@ class StudentModuleFactory(DjangoModelFactory):
class UserStateSummaryFactory(DjangoModelFactory):
FACTORY_FOR = XModuleUserStateSummaryField
class Meta(object):
model = XModuleUserStateSummaryField
field_name = 'existing_field'
value = json.dumps('old_value')
......@@ -143,7 +145,8 @@ class UserStateSummaryFactory(DjangoModelFactory):
class StudentPrefsFactory(DjangoModelFactory):
FACTORY_FOR = XModuleStudentPrefsField
class Meta(object):
model = XModuleStudentPrefsField
field_name = 'existing_field'
value = json.dumps('old_value')
......@@ -152,7 +155,8 @@ class StudentPrefsFactory(DjangoModelFactory):
class StudentInfoFactory(DjangoModelFactory):
FACTORY_FOR = XModuleStudentInfoField
class Meta(object):
model = XModuleStudentInfoField
field_name = 'existing_field'
value = json.dumps('old_value')
......
......@@ -7,7 +7,7 @@ from nose.plugins.attrib import attr
from functools import partial
from courseware.model_data import DjangoKeyValueStore, FieldDataCache, InvalidScopeError
from courseware.models import StudentModule
from courseware.models import StudentModule, XModuleUserStateSummaryField
from courseware.models import XModuleStudentInfoField, XModuleStudentPrefsField
from student.tests.factories import UserFactory
......@@ -394,7 +394,7 @@ class TestUserStateSummaryStorage(StorageTestBase, TestCase):
factory = UserStateSummaryFactory
scope = Scope.user_state_summary
key_factory = user_state_summary_key
storage_class = factory.FACTORY_FOR
storage_class = XModuleUserStateSummaryField
class TestStudentPrefsStorage(OtherUserFailureTestMixin, StorageTestBase, TestCase):
......
......@@ -3,11 +3,13 @@ from django_comment_common.models import Role, Permission
class RoleFactory(DjangoModelFactory):
FACTORY_FOR = Role
class Meta(object): # pylint: disable=missing-docstring
model = Role
name = 'Student'
course_id = 'edX/toy/2012_Fall'
class PermissionFactory(DjangoModelFactory):
FACTORY_FOR = Permission
class Meta(object): # pylint: disable=missing-docstring
model = Permission
name = 'create_comment'
......@@ -9,7 +9,8 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
class InstructorTaskFactory(DjangoModelFactory):
FACTORY_FOR = InstructorTask
class Meta(object): # pylint: disable=missing-docstring
model = InstructorTask
task_type = 'rescore_problem'
course_id = SlashSeparatedCourseKey("MITx", "999", "Robot_Super_Course")
......
......@@ -32,7 +32,8 @@ log = logging.getLogger(__name__)
class CourseSoftwareFactory(DjangoModelFactory):
'''Factory for generating CourseSoftware objects in database'''
FACTORY_FOR = CourseSoftware
class Meta(object): # pylint: disable=missing-docstring
model = CourseSoftware
name = SOFTWARE_1
full_name = SOFTWARE_1
......@@ -47,7 +48,8 @@ class UserLicenseFactory(DjangoModelFactory):
By default, the user assigned is null, indicating that the
serial number has not yet been assigned.
'''
FACTORY_FOR = UserLicense
class Meta(object): # pylint: disable=missing-docstring
model = UserLicense
user = None
software = factory.SubFactory(CourseSoftwareFactory)
......
......@@ -18,8 +18,9 @@ class CourseTeamFactory(DjangoModelFactory):
Note that team_id is not auto-generated from name when using the factory.
"""
FACTORY_FOR = CourseTeam
FACTORY_DJANGO_GET_OR_CREATE = ('team_id',)
class Meta(object): # pylint: disable=missing-docstring
model = CourseTeam
django_get_or_create = ('team_id',)
team_id = factory.Sequence('team-{0}'.format)
discussion_topic_id = factory.LazyAttribute(lambda a: uuid4().hex)
......@@ -30,5 +31,6 @@ class CourseTeamFactory(DjangoModelFactory):
class CourseTeamMembershipFactory(DjangoModelFactory):
"""Factory for CourseTeamMemberships."""
FACTORY_FOR = CourseTeamMembership
class Meta(object): # pylint: disable=missing-docstring
model = CourseTeamMembership
last_activity_at = LAST_ACTIVITY_AT
......@@ -10,6 +10,7 @@ class SoftwareSecurePhotoVerificationFactory(DjangoModelFactory):
"""
Factory for SoftwareSecurePhotoVerification
"""
FACTORY_FOR = SoftwareSecurePhotoVerification
class Meta(object): # pylint: disable=missing-docstring
model = SoftwareSecurePhotoVerification
status = 'approved'
......@@ -18,7 +18,8 @@ class CohortFactory(DjangoModelFactory):
"""
Factory for constructing mock cohorts.
"""
FACTORY_FOR = CourseUserGroup
class Meta(object): # pylint: disable=missing-docstring
model = CourseUserGroup
name = Sequence("cohort{}".format)
course_id = SlashSeparatedCourseKey("dummy", "dummy", "dummy")
......@@ -37,7 +38,8 @@ class CourseCohortFactory(DjangoModelFactory):
"""
Factory for constructing mock course cohort.
"""
FACTORY_FOR = CourseCohort
class Meta(object): # pylint: disable=missing-docstring
model = CourseCohort
course_user_group = factory.SubFactory(CohortFactory)
assignment_type = 'manual'
......@@ -47,7 +49,8 @@ class CourseCohortSettingsFactory(DjangoModelFactory):
"""
Factory for constructing mock course cohort settings.
"""
FACTORY_FOR = CourseCohortsSettings
class Meta(object): # pylint: disable=missing-docstring
model = CourseCohortsSettings
is_cohorted = False
course_id = SlashSeparatedCourseKey("dummy", "dummy", "dummy")
......
......@@ -10,7 +10,8 @@ from ..models import UserPreference, UserCourseTag, UserOrgTag
# Factories are self documenting
# pylint: disable=missing-docstring
class UserPreferenceFactory(DjangoModelFactory):
FACTORY_FOR = UserPreference
class Meta(object):
model = UserPreference
user = None
key = None
......@@ -18,7 +19,8 @@ class UserPreferenceFactory(DjangoModelFactory):
class UserCourseTagFactory(DjangoModelFactory):
FACTORY_FOR = UserCourseTag
class Meta(object):
model = UserCourseTag
user = SubFactory(UserFactory)
course_id = SlashSeparatedCourseKey('org', 'course', 'run')
......@@ -28,7 +30,8 @@ class UserCourseTagFactory(DjangoModelFactory):
class UserOrgTagFactory(DjangoModelFactory):
""" Simple factory class for generating UserOrgTags """
FACTORY_FOR = UserOrgTag
class Meta(object):
model = UserOrgTag
user = SubFactory(UserFactory)
org = 'org'
......
......@@ -126,7 +126,7 @@ ddt==0.8.0
diff-cover==0.8.0
django-crum==0.5
django_nose==1.4.1
factory_boy==2.2.1
factory_boy==2.5.1
flaky==2.0.3
freezegun==0.1.11
mock-django==0.6.9
......
......@@ -45,7 +45,7 @@ git+https://github.com/edx/rfc6266.git@v0.0.5-edx#egg=rfc6266==0.0.5-edx
-e git+https://github.com/edx/opaque-keys.git@27dc382ea587483b1e3889a3d19cbd90b9023a06#egg=opaque-keys
git+https://github.com/edx/ease.git@release-2015-07-14#egg=ease==0.1.3
git+https://github.com/edx/i18n-tools.git@v0.1.3#egg=i18n-tools==v0.1.3
git+https://github.com/edx/edx-oauth2-provider.git@0.5.6#egg=oauth2-provider==0.5.6
git+https://github.com/edx/edx-oauth2-provider.git@0.5.7#egg=oauth2-provider==0.5.7
-e git+https://github.com/edx/edx-val.git@v0.0.5#egg=edx-val
-e git+https://github.com/pmitros/RecommenderXBlock.git@518234bc354edbfc2651b9e534ddb54f96080779#egg=recommender-xblock
-e git+https://github.com/edx/edx-search.git@release-2015-09-11a#egg=edx-search
......@@ -63,3 +63,4 @@ git+https://github.com/edx/edx-proctoring.git@0.9.6b#egg=edx-proctoring==0.9.6b
# Third Party XBlocks
-e git+https://github.com/mitodl/edx-sga@172a90fd2738f8142c10478356b2d9ed3e55334a#egg=edx-sga
-e git+https://github.com/open-craft/xblock-poll@e7a6c95c300e95c51e42bfd1eba70489c05a6527#egg=xblock-poll
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment