示例#1
0
 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())
示例#2
0
 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')
示例#3
0
 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'])
示例#4
0
 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'])
示例#5
0
 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)
示例#6
0
 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()))
示例#7
0
 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())
示例#8
0
    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)
示例#9
0
 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'))
示例#10
0
 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)
示例#11
0
 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)
示例#12
0
 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)
示例#13
0
 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')
示例#14
0
 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)
示例#15
0
 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()
示例#16
0
 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'])
示例#17
0
 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()
示例#18
0
 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']
     )
示例#19
0
 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())
     )
示例#20
0
 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'))
示例#21
0
    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())
示例#22
0
    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
示例#23
0
    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
示例#24
0
    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')
示例#25
0
    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")
示例#26
0
    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()
            )
示例#27
0
    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'
            )
示例#28
0
    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")
示例#29
0
    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')
示例#30
0
    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')
示例#31
0
 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'))
示例#32
0
 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())
示例#33
0
 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'])
示例#34
0
 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'])
示例#35
0
 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')