Merge pull request #15882 from edx/ret/improve-site-config-factory
Make SiteConfigurationFactory more useable
This commit is contained in:
@@ -3,10 +3,23 @@ Model factories for unit testing views or models.
|
||||
"""
|
||||
from django.contrib.sites.models import Site
|
||||
from factory.django import DjangoModelFactory
|
||||
from factory import SubFactory, Sequence, SelfAttribute
|
||||
|
||||
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
|
||||
|
||||
|
||||
class SiteFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory class for Site model
|
||||
"""
|
||||
class Meta(object):
|
||||
model = Site
|
||||
django_get_or_create = ('domain',)
|
||||
|
||||
domain = Sequence('testserver.fake.{}'.format)
|
||||
name = SelfAttribute('domain')
|
||||
|
||||
|
||||
class SiteConfigurationFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory class for SiteConfiguration model
|
||||
@@ -16,17 +29,4 @@ class SiteConfigurationFactory(DjangoModelFactory):
|
||||
|
||||
values = {}
|
||||
enabled = True
|
||||
|
||||
|
||||
class SiteFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory class for Site model
|
||||
"""
|
||||
class Meta(object):
|
||||
model = Site
|
||||
django_get_or_create = ('domain',)
|
||||
|
||||
# TODO These should be generated. Otherwise, code that creates multiple Site
|
||||
# objects will only end up with a single Site since domain has a unique constraint.
|
||||
domain = 'testserver.fake'
|
||||
name = 'testserver.fake'
|
||||
site = SubFactory(SiteFactory)
|
||||
|
||||
Reference in New Issue
Block a user