def test_render_one_chunk(self): iframe = Iframe(region='test', content_id=1, content_type=self.ct, url='https://news.bbc.co.uk/', position=1) iframe.full_clean() iframe.pk = 1 request = RequestFactory().get('/') ctx = RequestContext(request) iterdata = chunk_iteration_context( index=0, value=iframe, iterable=[iframe]) ctx.update(iterdata) output = render_one_chunk(context=ctx, chunk=iframe, extra=iterdata['chunkloop'], renderer=None).strip() self.assertIn('<iframe ', output) self.assertIn('src="https://news.bbc.co.uk/"', output) self.assertIn('data-position="1"', output) self.assertIn('data-pk="1"', output) self.assertIn('data-region="test"', output) self.assertIn('</iframe>', output)
def test_render_all_chunks(self): objs = [] for x in range(0, 10): iframe = Iframe(region='test', content_id=1, content_type=self.ct, url='https://news.bbc.co.uk/{0!s}'.format(x), position=x) iframe.full_clean() iframe.pk = x objs.append(iframe) ctx = Context() chunks = render_all_chunks(context=ctx, found_chunks=objs) converted_chunks = list(chunks) self.assertEqual(10, len(converted_chunks)) for num, rendered_chunk in enumerate(converted_chunks): testable = rendered_chunk.output.strip() pos = num + 1 self.assertIn('src="https://news.bbc.co.uk/{0}"'.format(num), testable) self.assertIn('data-position="{0}"'.format(pos), testable) self.assertIn('data-region="test"', testable)