def test_get_backend_raise_error_when_module_has_no_class(self): """ Test get_backend raises ValueError when module does not have a class. """ # module does not have a class with self.assertRaises(ValueError): microsite.get_backend('microsite_configuration.microsite.invalid_method', BaseMicrositeBackend)
def test_get_backend_raise_error_when_module_has_no_class(self): """ Test get_backend raises ValueError when module does not have a class. """ # module does not have a class with self.assertRaises(ValueError): microsite.get_backend( 'microsite_configuration.microsite.invalid_method', BaseMicrositeBackend)
def test_get_backend_raise_error_for_invalid_class(self): """ Test get_backend returns None for invalid paths and raises TypeError when invalid class or class name is a method. """ # invalid backend path self.assertEqual(microsite.get_backend(None, BaseMicrositeBackend), None) # invalid class or class name is a method with self.assertRaises(TypeError): microsite.get_backend('microsite_configuration.microsite.get_backend', BaseMicrositeBackend)
def test_get_backend_raise_error_for_invalid_class(self): """ Test get_backend returns None for invalid paths and raises TypeError when invalid class or class name is a method. """ # invalid backend path self.assertEqual(microsite.get_backend(None, BaseMicrositeBackend), None) # invalid class or class name is a method with self.assertRaises(TypeError): microsite.get_backend( 'microsite_configuration.microsite.get_backend', BaseMicrositeBackend)
def test_get_value_for_org_when_microsite_has_no_org(self, site_backend): """ Make sure default value is returned if there's no Microsite ORG match """ with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): value = get_value_for_org("BogusX", "university", "default_value") self.assertEquals(value, "default_value")
def test_get_value_for_org(self, site_backend): """ Make sure get_value_for_org return value of org if it present. """ with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): value = get_value_for_org("TestSiteX", "university", "default_value") self.assertEquals(value, "test_site")
def test_session_cookie_domain_with_microsite_override(self, site_backend): """ Makes sure that the cookie being set in a Microsite is the one specially overridden in configuration """ with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): response = self.client.get('/', HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME) self.assertIn('test_site.localhost', str(response.cookies['sessionid']))
def test_session_cookie_domain_no_override(self, site_backend): """ Test sessionid cookie when no override is set """ with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): response = self.client.get('/') self.assertNotIn('test_site.localhost', str(response.cookies['sessionid'])) self.assertNotIn('Domain', str(response.cookies['sessionid']))
def test_get_backend_for_valid_class(self): """ Test get_backend loads class if class exists. """ # load a valid class self.assertIsInstance( microsite.get_backend( 'microsite_configuration.backends.database.DatabaseMicrositeBackend', BaseMicrositeBackend), DatabaseMicrositeBackend)
def test_session_cookie_domain(self, site_backend): """ Makes sure that the cookie being set in a Microsite is the one specially overridden in configuration """ with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): response = self.client.get('/', HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME) self.assertIn('test_microsite.localhost', str(response.cookies['sessionid']))
def test_session_cookie_domain_no_microsite(self, site_backend): """ Tests that non-microsite behaves according to default behavior """ with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): response = self.client.get('/') self.assertNotIn('test_site.localhost', str(response.cookies['sessionid'])) self.assertNotIn('Domain', str(response.cookies['sessionid']))
def test_session_cookie_domain_no_microsite(self, site_backend): """ Tests that non-microsite behaves according to default behavior """ with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): response = self.client.get('/') self.assertNotIn('test_microsite.localhost', str(response.cookies['sessionid'])) self.assertNotIn('Domain', str(response.cookies['sessionid']))
def test_get_backend_for_valid_class(self): """ Test get_backend loads class if class exists. """ # load a valid class self.assertIsInstance( microsite.get_backend( 'microsite_configuration.backends.database.DatabaseMicrositeBackend', BaseMicrositeBackend ), DatabaseMicrositeBackend )
def test_microsite_none_cookie_domain(self, site_backend): """ Tests to make sure that a Microsite that specifies None for 'SESSION_COOKIE_DOMAIN' does not set a domain on the session cookie """ with patch('microsite_configuration.microsite.get_value') as mock_get_value: mock_get_value.side_effect = side_effect_for_get_value('SESSION_COOKIE_DOMAIN', None) with patch('microsite_configuration.microsite.BACKEND', get_backend(site_backend, BaseMicrositeBackend)): response = self.client.get('/', HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME) self.assertNotIn('test_site.localhost', str(response.cookies['sessionid'])) self.assertNotIn('Domain', str(response.cookies['sessionid']))
from microsite_configuration.tests.tests import ( DatabaseMicrositeTestCase, ) from microsite_configuration.tests.factories import ( SiteFactory, MicrositeFactory, MicrositeTemplateFactory, ) log = logging.getLogger(__name__) @patch( 'microsite_configuration.microsite.BACKEND', microsite.get_backend( 'microsite_configuration.backends.database.DatabaseMicrositeBackend', BaseMicrositeBackend ) ) class DatabaseMicrositeBackendTests(DatabaseMicrositeTestCase): """ Go through and test the DatabaseMicrositeBackend class """ def setUp(self): super(DatabaseMicrositeBackendTests, self).setUp() def tearDown(self): super(DatabaseMicrositeBackendTests, self).tearDown() microsite.clear() def test_get_value(self): """
from django.core.urlresolvers import reverse from microsite_configuration.backends.base import ( BaseMicrositeBackend, BaseMicrositeTemplateBackend, ) from microsite_configuration import microsite from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @patch( 'microsite_configuration.microsite.BACKEND', microsite.get_backend( 'microsite_configuration.backends.filebased.FilebasedMicrositeBackend', BaseMicrositeBackend ) ) class FilebasedMicrositeBackendTests(TestCase): """ Go through and test the FilebasedMicrositeBackend class """ def setUp(self): super(FilebasedMicrositeBackendTests, self).setUp() self.microsite_subdomain = 'testmicrosite' def tearDown(self): super(FilebasedMicrositeBackendTests, self).tearDown() microsite.clear() def test_get_value(self):
) from microsite_configuration.tests.tests import ( DatabaseMicrositeTestCase, ) from microsite_configuration.tests.factories import ( SiteFactory, MicrositeFactory, MicrositeTemplateFactory, ) log = logging.getLogger(__name__) @patch( 'microsite_configuration.microsite.BACKEND', microsite.get_backend( 'microsite_configuration.backends.database.DatabaseMicrositeBackend', BaseMicrositeBackend)) class DatabaseMicrositeBackendTests(DatabaseMicrositeTestCase): """ Go through and test the DatabaseMicrositeBackend class """ def setUp(self): super(DatabaseMicrositeBackendTests, self).setUp() self.addCleanup(microsite.clear) 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'),
backend.get_all_config() with self.assertRaises(NotImplementedError): backend.clear() with self.assertRaises(NotImplementedError): backend.get_value_for_org(None, None, None) with self.assertRaises(NotImplementedError): backend.get_all_orgs() @patch( 'microsite_configuration.microsite.BACKEND', microsite.get_backend( 'microsite_configuration.backends.base.BaseMicrositeBackend', BaseMicrositeBackend ) ) class BaseMicrositeBackendTests(TestCase): """ Go through and test the BaseMicrositeBackend class for behavior which is not overriden in subclasses """ def test_enable_microsites_pre_startup(self): """ Tests microsite.test_enable_microsites_pre_startup works as expected. """ # remove microsite root directory paths first settings.DEFAULT_TEMPLATE_ENGINE['DIRS'] = [ path for path in settings.DEFAULT_TEMPLATE_ENGINE['DIRS'] if path != settings.MICROSITE_ROOT_DIR