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())
def test_get_value(self): """ Tests microsite.get_value works as expected. """ microsite.set_by_domain(self.microsite_subdomain) self.assertEqual(microsite.get_value('platform_name'), 'Test Microsite')
def test_get_dict(self): """ Tests microsite.get_dict works as expected. """ microsite.set_by_domain(self.microsite.site.domain) self.assertEqual(microsite.get_dict('nested_dict'), self.microsite.values['nested_dict'])
def test_get_value(self): """ Tests microsite.get_value works as expected. """ microsite.set_by_domain(self.microsite.site.domain) self.assertEqual(microsite.get_value('email_from_address'), self.microsite.values['email_from_address'])
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)
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()))
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_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 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)
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)
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 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 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'])
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'] )
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()) )
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 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 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_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_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")
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_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")
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 test_has_override_value(self): """ Tests microsite.has_override_value works as expected. """ microsite.set_by_domain(self.microsite_subdomain) self.assertTrue(microsite.has_override_value('platform_name'))
def test_is_request_in_microsite(self): """ Tests microsite.is_request_in_microsite works as expected. """ microsite.set_by_domain(self.microsite_subdomain) self.assertTrue(microsite.is_request_in_microsite())
def test_get_value(self): """ Tests microsite.get_value works as expected. """ microsite.set_by_domain(self.microsite_subdomain) self.assertEqual(microsite.get_value('platform_name'), 'Test Site')