本文整理汇总了Python中microsite_configuration.microsite.set_by_domain函数的典型用法代码示例。如果您正苦于以下问题:Python set_by_domain函数的具体用法?Python set_by_domain怎么用?Python set_by_domain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_by_domain函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_all_configs
def test_get_all_configs(self):
"""
Tests microsite.get_all_config works as expected.
"""
microsite.set_by_domain(self.microsite_subdomain)
configs = microsite.get_all_config()
self.assertEqual(len(configs.keys()), 3)
示例2: test_microsite_get_template
def test_microsite_get_template(self):
"""
Test microsite.get_template return appropriate template.
"""
microsite.set_by_domain(self.microsite.site.domain)
template = microsite.get_template('about.html')
self.assertIn('About this microsite', template.render())
示例3: current
def current(cls, *args):
"""
Get the current config model for the provider according to the enabled slugs for this site.
The site configuration expects the value of THIRD_PARTY_AUTH_ENABLED_PROVIDERS to be a dict
of backend_name and the slug being used for the configuration object.
E.g.
"THIRD_PARTY_AUTH_ENABLED_PROVIDERS":{
"google-oauth2":"my-slug-for-this-provider"
}
"""
enabled_providers = microsite.get_value('THIRD_PARTY_AUTH_ENABLED_PROVIDERS', {})
# In a very specific case, azuread-oauth2 does not have a microsite context.
if not microsite.is_request_in_microsite():
try:
microsite.set_by_domain(get_current_request().site.domain)
enabled_providers = microsite.get_value('THIRD_PARTY_AUTH_ENABLED_PROVIDERS', {})
microsite.clear()
except Exception: # pylint: disable=broad-except
pass
if not enabled_providers:
return super(OAuth2ProviderConfig, cls).current(*args)
provider_slug = enabled_providers.get(args[0])
if provider_slug:
return super(OAuth2ProviderConfig, cls).current(provider_slug)
return super(OAuth2ProviderConfig, cls).current(None)
示例4: test_get_all_configs
def test_get_all_configs(self):
"""
Tests microsite.get_all_config works as expected.
"""
microsite.set_by_domain(self.microsite.site.domain)
configs = microsite.get_all_config()
self.assertEqual(len(list(configs.keys())), 1)
self.assertEqual(configs[self.microsite.key], self.microsite.values)
示例5: test_microsite_get_template_when_no_template_exists
def test_microsite_get_template_when_no_template_exists(self):
"""
Test microsite.get_template return None if there is not template in DB.
"""
MicrositeTemplate.objects.all().delete()
microsite.set_by_domain(self.microsite.site.domain)
template = microsite.get_template('about.html')
self.assertIsNone(template)
示例6: test_set_config_by_domain
def test_set_config_by_domain(self):
"""
Tests microsite.set_config_by_domain works as expected.
"""
microsite.clear()
# if microsite config does not exist default config should be used
microsite.set_by_domain('unknown')
self.assertEqual(microsite.get_value('university'), 'default_university')
示例7: test_get_all_orgs
def test_get_all_orgs(self):
"""
Tests microsite.get_all_orgs works as expected.
"""
microsite.set_by_domain(self.microsite.site.domain)
self.assertEqual(
microsite.get_all_orgs(),
set(self.microsite.get_organizations())
)
示例8: test_get_value_for_org
def test_get_value_for_org(self):
"""
Tests microsite.get_value_for_org works as expected.
"""
microsite.set_by_domain(self.microsite.site.domain)
self.assertEqual(
microsite.get_value_for_org(self.microsite.get_organizations()[0], 'platform_name'),
self.microsite.values['platform_name']
)
示例9: inner
def inner(request, *args, **kwargs):
"""
Execute the function after setting up the microsite.
"""
try:
microsite.set_by_domain(domain)
return func(request, *args, **kwargs)
finally:
microsite.clear()
示例10: test_clear
def test_clear(self):
"""
Tests microsite.clear works as expected.
"""
microsite.set_by_domain(self.microsite_subdomain)
self.assertEqual(
microsite.get_value('platform_name'),
'Test Microsite'
)
microsite.clear()
self.assertIsNone(microsite.get_value('platform_name'))
示例11: process_request
def process_request(self, request):
"""
Middleware entry point on every request processing. This will associate a request's domain name
with a 'University' and any corresponding microsite configuration information
"""
microsite.clear()
domain = request.META.get('HTTP_HOST', None)
microsite.set_by_domain(domain)
return None
示例12: test_get_value_for_org
def test_get_value_for_org(self):
"""
Tests microsite.get_value_for_org works as expected.
"""
microsite.set_by_domain(self.microsite_subdomain)
self.assertEqual(
microsite.get_value_for_org('TestMicrositeX', 'platform_name'),
'Test Microsite'
)
# if no config is set
microsite.clear()
with patch('django.conf.settings.MICROSITE_CONFIGURATION', False):
self.assertEqual(
microsite.get_value_for_org('TestMicrositeX', 'platform_name', 'Default Value'),
'Default Value'
)
示例13: test_get_all_orgs
def test_get_all_orgs(self):
"""
Tests microsite.get_all_orgs works as expected.
"""
microsite.set_by_domain(self.microsite_subdomain)
self.assertEqual(
microsite.get_all_orgs(),
set(['TestMicrositeX', 'LogistrationX'])
)
# if no config is set
microsite.clear()
with patch('django.conf.settings.MICROSITE_CONFIGURATION', False):
self.assertEqual(
microsite.get_all_orgs(),
set()
)
示例14: test_get_template_path
def test_get_template_path(self):
"""
Tests get template path works for both relative and absolute paths.
"""
microsite.set_by_domain(self.microsite_subdomain)
CourseEnrollmentFactory(
course_id=self.course.id,
user=self.user
)
response = self.client.get(
reverse('syllabus', args=[unicode(self.course.id)]),
HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME,
)
self.assertContains(response, "Microsite relative path template contents")
self.assertContains(response, "Microsite absolute path template contents")
示例15: test_set_config_by_domain
def test_set_config_by_domain(self):
"""
Tests microsite.set_config_by_domain works as expected.
"""
microsite.clear()
# if microsite config does not exist
microsite.set_by_domain('unknown')
self.assertIsNone(microsite.get_value('platform_name'))
# if no microsite exists
Microsite.objects.all().delete()
microsite.clear()
microsite.set_by_domain('unknown')
self.assertIsNone(microsite.get_value('platform_name'))
# if microsite site has no organization it should raise exception
new_microsite = MicrositeFactory.create(key="test_microsite2")
new_microsite.site = SiteFactory.create(domain='test.microsite2.com')
# This would update microsite so we test MicrositeHistory has old microsite
new_microsite.save()
self.assertEqual(MicrositeHistory.objects.all().count(), 2)
with self.assertRaises(Exception):
microsite.set_by_domain('test.microsite2.com')