Esempio n. 1
0
 def test_healing_no_actions(self):
     context = Context()
     length = len(context.dicts)
     with healed_context(context) as ctx:
         pass
     new_length = len(context.dicts)
     self.assertEqual(length, new_length)
     if is_django_15plus():
         self.assertIn('True', context)
         self.assertIn('False', context)
         self.assertIn('None', context)
Esempio n. 2
0
 def test_healing_via_dict(self):
     context = {'1': 2}
     with healed_context(context) as ctx:
         ctx.update({'3': 4})
         if is_django_15plus():
             self.assertEqual(len(ctx.dicts), 3)
             self.assertEqual(ctx.dicts, [
                 {'True': True, 'False': False, 'None': None},
                 {'1': 2},
                 {'3': 4},
             ])
     self.assertEqual(len(context), 1)
     self.assertEqual(context, {'1': 2})
Esempio n. 3
0
 def test_healing_prefilled(self):
     context = Context({'b': 2})
     length = len(context.dicts)
     with healed_context(context) as ctx:
         ctx.update({'a': 1})
     new_length = len(context.dicts)
     self.assertEqual(length, new_length)
     if is_django_15plus():
         self.assertIn('True', context)
         self.assertIn('False', context)
         self.assertIn('None', context)
     self.assertIn('b', context)
     self.assertNotIn('a', context)
Esempio n. 4
0
def render_all_chunks(context, found_chunks, iter_func=chunk_iteration_context,
                      render_func=render_one_chunk):
    logger.info('Rendering {0} chunks'.format(len(found_chunks)))
    for index, chunk in enumerate(found_chunks):
        # new_context = convert_context_to_dict(context)
        with healed_context(context) as new_ctx:
            iteration = iter_func(index=index, value=chunk,
                                  iterable=found_chunks)
            new_ctx.update(iteration)
            output = render_func(context=new_ctx, chunk=chunk, extra=iteration)
        # a chunk may return None if the ModelAdmin responsible for
        # rendering it doesn't implement the correct methods (instead
        # raising a warning to stderr), so we screen it all here.
        if output is not None:
            yield RenderedChunk(index=index, chunk=chunk, output=output)
Esempio n. 5
0
 def test_healing(self):
     context = Context()
     length = len(context.dicts)
     with healed_context(context) as ctx:
         ctx.update({'a': 1})
         ctx.update({'b': 2})
         ctx.update({'c': 3})
     new_length = len(context.dicts)
     self.assertEqual(length, new_length)
     # 1.4 didn't hardcode an initial dict for special values.
     if is_django_15plus():
         self.assertIn('True', context)
         self.assertIn('False', context)
         self.assertIn('None', context)
     self.assertNotIn('b', context)
     is_same = Context()
     # comparing Context() to Context() doesn't work ;|
     self.assertEqual(is_same.dicts, context.dicts)