Added SiteMixin for tests that need to test Site specific functionality

This commit is contained in:
Douglas Hall
2016-09-22 17:08:48 -04:00
committed by Douglas Hall
parent 8f6182aabf
commit 1d1952c8d3
5 changed files with 106 additions and 21 deletions

View File

@@ -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'

View 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)