def _certificate_html_view_configuration(self, configuration_string, enabled=True): """ This will create a certificate html configuration """ config = CertificateHtmlViewConfiguration(enabled=enabled, configuration=configuration_string) config.save() return config
def _certificate_html_view_configuration(self, configuration_string, enabled=True): """ This will create a certificate html configuration """ config = CertificateHtmlViewConfiguration(enabled=enabled, configuration=configuration_string) config.save() return config
class CertificateHtmlViewConfigurationTest(TestCase): """ Test the CertificateHtmlViewConfiguration model. """ def setUp(self): super(CertificateHtmlViewConfigurationTest, self).setUp() self.configuration_string = """{ "default": { "url": "http://www.edx.org", "logo_src": "http://www.edx.org/static/images/logo.png" }, "honor": { "logo_src": "http://www.edx.org/static/images/honor-logo.png" } }""" self.config = CertificateHtmlViewConfiguration(configuration=self.configuration_string) def test_create(self): """ Tests creation of configuration. """ self.config.save() self.assertEquals(self.config.configuration, self.configuration_string) def test_clean_bad_json(self): """ Tests if bad JSON string was given. """ self.config = CertificateHtmlViewConfiguration(configuration='{"bad":"test"') self.assertRaises(ValidationError, self.config.clean) def test_get(self): """ Tests get configuration from saved string. """ self.config.enabled = True self.config.save() expected_config = { "default": {"url": "http://www.edx.org", "logo_src": "http://www.edx.org/static/images/logo.png"}, "honor": {"logo_src": "http://www.edx.org/static/images/honor-logo.png"}, } self.assertEquals(self.config.get_config(), expected_config) def test_get_not_enabled_returns_blank(self): """ Tests get configuration that is not enabled. """ self.config.enabled = False self.config.save() self.assertEquals(len(self.config.get_config()), 0) @override_settings(FEATURES=FEATURES_INVALID_FILE_PATH) def test_get_no_database_no_file(self): """ Tests get configuration that is not enabled. """ self.config.configuration = "" self.config.save() self.assertEquals(self.config.get_config(), {})
class CertificateHtmlViewConfigurationTest(TestCase): """ Test the CertificateHtmlViewConfiguration model. """ def setUp(self): super(CertificateHtmlViewConfigurationTest, self).setUp() self.configuration_string = """{ "default": { "url": "http://www.edx.org", "logo_src": "http://www.edx.org/static/images/logo.png" }, "honor": { "logo_src": "http://www.edx.org/static/images/honor-logo.png" } }""" self.config = CertificateHtmlViewConfiguration( configuration=self.configuration_string) def test_create(self): """ Tests creation of configuration. """ self.config.save() self.assertEquals(self.config.configuration, self.configuration_string) def test_clean_bad_json(self): """ Tests if bad JSON string was given. """ self.config = CertificateHtmlViewConfiguration( configuration='{"bad":"test"') self.assertRaises(ValidationError, self.config.clean) def test_get(self): """ Tests get configuration from saved string. """ self.config.enabled = True self.config.save() expected_config = { "default": { "url": "http://www.edx.org", "logo_src": "http://www.edx.org/static/images/logo.png" }, "honor": { "logo_src": "http://www.edx.org/static/images/honor-logo.png" } } self.assertEquals(self.config.get_config(), expected_config) def test_get_not_enabled_returns_blank(self): """ Tests get configuration that is not enabled. """ self.config.enabled = False self.config.save() self.assertEquals(len(self.config.get_config()), 0) @override_settings(FEATURES=FEATURES_INVALID_FILE_PATH) def test_get_no_database_no_file(self): """ Tests get configuration that is not enabled. """ self.config.configuration = '' self.config.save() self.assertEquals(self.config.get_config(), {})