Added SiteMixin for tests that need to test Site specific functionality
This commit is contained in:
committed by
Douglas Hall
parent
8f6182aabf
commit
1d1952c8d3
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Model factories for unit testing views or models.
|
||||
"""
|
||||
from django.contrib.sites.models import Site
|
||||
from factory.django import DjangoModelFactory
|
||||
|
||||
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
|
||||
@@ -15,3 +16,14 @@ class SiteConfigurationFactory(DjangoModelFactory):
|
||||
|
||||
values = {}
|
||||
enabled = True
|
||||
|
||||
|
||||
class SiteFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory class for Site model
|
||||
"""
|
||||
class Meta(object):
|
||||
model = Site
|
||||
|
||||
domain = 'testserver.fake'
|
||||
name = 'testserver.fake'
|
||||
|
||||
47
openedx/core/djangoapps/site_configuration/tests/mixins.py
Normal file
47
openedx/core/djangoapps/site_configuration/tests/mixins.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
Mixins for TestCase classes that need to account for multiple sites
|
||||
"""
|
||||
from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory
|
||||
|
||||
|
||||
class SiteMixin(object):
|
||||
"""
|
||||
Mixin for setting up Site framework models
|
||||
"""
|
||||
def setUp(self):
|
||||
super(SiteMixin, self).setUp()
|
||||
|
||||
self.site = SiteFactory.create()
|
||||
self.site_configuration = SiteConfigurationFactory.create(
|
||||
site=self.site,
|
||||
values={
|
||||
"SITE_NAME": self.site.domain,
|
||||
"course_org_filter": "fakeX",
|
||||
}
|
||||
)
|
||||
|
||||
self.site_other = SiteFactory.create(
|
||||
domain='testserver.fakeother',
|
||||
name='testserver.fakeother'
|
||||
)
|
||||
self.site_configuration_other = SiteConfigurationFactory.create(
|
||||
site=self.site_other,
|
||||
values={
|
||||
"SITE_NAME": self.site_other.domain,
|
||||
"course_org_filter": "fakeOtherX",
|
||||
"ENABLE_MKTG_SITE": True,
|
||||
"MKTG_URLS": {
|
||||
"ROOT": "https://marketing.fakeother",
|
||||
"ABOUT": "/fake-about"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
# Initialize client with default site domain
|
||||
self.use_site(self.site)
|
||||
|
||||
def use_site(self, site):
|
||||
"""
|
||||
# Initializes the test client with the domain of the given site
|
||||
"""
|
||||
self.client = self.client_class(SERVER_NAME=site.domain)
|
||||
Reference in New Issue
Block a user