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)
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')
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 Site') microsite.clear() self.assertIsNone(microsite.get_value('platform_name'))
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()
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) return microsite.set_by_domain(domain)
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'))
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
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(['TestSiteX', 'LogistrationX'])) # if no config is set microsite.clear() with patch('django.conf.settings.MICROSITE_CONFIGURATION', False): self.assertEqual(microsite.get_all_orgs(), set())
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('TestSiteX', 'platform_name'), 'Test Site') # if no config is set microsite.clear() with patch('django.conf.settings.MICROSITE_CONFIGURATION', False): self.assertEqual( microsite.get_value_for_org('TestSiteX', 'platform_name', 'Default Value'), 'Default Value')
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() )
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' )
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')
def process_response(self, request, response): """ Middleware entry point for request completion. """ microsite.clear() return response
def tearDown(self): super(FilebasedMicrositeBackendTests, self).tearDown() microsite.clear()
def tearDown(self): super(DatabaseMicrositeTemplateBackendTests, self).tearDown() microsite.clear()
def tearDown(self): super(DatabaseMicrositeBackendTests, self).tearDown() microsite.clear()