def test_register_plugin(self): css_plugin = CMSPluginBase() css_plugin.css_template = "fake.css" manager.register(css_plugin) self.assertIn(css_plugin, manager.registered_plugins)
def test_generate_css(self): # Mock up a plugin mock_plugin = CMSPluginBase() mock_plugin.model = ColorDiv mock_plugin.css_template = os.path.basename(self.tf.name) # Clear registered plugins and register manager.registered_plugins = [] manager.register(mock_plugin) # Mock up models model1 = ColorDiv(color="Color1") model1.save() model2 = ColorDiv(color="Color2") model2.save() # Generate CSS manager.generate_css() # Compare with auto.css output filepath = os.path.join(settings.BASE_DIR, "assets", "css", "auto.css") with open(filepath, 'r') as css: result = css.read() expected = "Test: Color1\nTest: Color2\n" self.assertEqual(result, expected)
def test_get_css_template(self): """Test the get_css_template function returns the CSS template""" # Mock up plugin mock_plugin = CMSPluginBase() mock_plugin.css_template = os.path.basename(self.tf.name) template = manager.get_css_template(mock_plugin) self.assertIsInstance(template, Template) # Render returned template and compare with expected rendered = template.render(Context({})) self.assertEqual("Test: ", rendered)
def render(self, context, instance, placeholder): context = CMSPluginBase.render(self, context, instance, placeholder) print(context["instance"].type_filters.all()) return context
def render(self, context, instance, placeholder): context = CMSPluginBase.render(self, context, instance, placeholder) return context