def test02_should_return_objects_given_as_argument(self): self._create_fixture() tag = Products(DummyParser(), DummyTokens()) arg_objects = Product.objects.filter(active=False) result = tag.get_context({}, arg_objects) self.assertTrue('products' in result) self.assertEqual(len(result['products']), 1)
def test_context_no_request(self): """ This is a weird and limited test to ensure that if request is not in context no exception is thrown. In this case MetaFromPage.render_tag does not need a full environment to work """ context = {} dummy_tokens = DummyTokens('myval', 'as', 'myname') tag = MetaFromPage.render_tag( MetaFromPage(Parser(dummy_tokens), dummy_tokens), context, None, 'meta') self.assertFalse(tag) self.assertTrue(context['meta'])
def test_render_plugin_no_context(self): placeholder = Placeholder.objects.create(slot='test') plugin = add_plugin(placeholder, TextPlugin, 'en', body='Test') parser = DummyParser() tokens = DummyTokens(plugin) tag = RenderPlugin(parser, tokens) superuser = self.get_superuser() request = RequestFactory().get('/') request.current_page = None request.user = superuser request.session = {} request.toolbar = CMSToolbar(request) request.toolbar.edit_mode = True context = SekizaiContext({'request': request}) output = tag.render(context) self.assertEqual( output, '<div class="cms_plugin cms_plugin-{0}">Test</div>'.format( plugin.pk))
def test03_should_return_empty_array_if_no_objects_found(self): self._create_fixture() tag = Products(DummyParser(), DummyTokens()) arg_objects = Product.objects.filter(slug='non-existant-slug') result = tag.get_context({}, arg_objects) self.assertEqual(len(result['products']), 0)
def test01_should_return_all_active_products(self): self._create_fixture() tag = Products(DummyParser(), DummyTokens()) result = tag.get_context({}, None) self.assertTrue('products' in result) self.assertEqual(len(result['products']), 2)
def test01_should_only_return_parent_categories(self): tag = RootCategoryTag(DummyParser(), DummyTokens()) result = tag.get_context({}) self.assertTrue(result.has_key('categories')) self.assertEqual(len(result['categories']), 2)