Exemplo n.º 1
0
 def test_length(self):
     media = RegionMedia()
     media.add_to_top('<style type="text/css"></style>')
     media.add_to_bottom('<script></script>')
     self.assertEqual(len(media), 2)
     self.assertEqual(len(media['top']), 1)
     self.assertEqual(len(media['bottom']), 1)
Exemplo n.º 2
0
    def test_deduplicate_on_add(self):
        media = RegionMedia()
        for x in range(0, 5):
            media.add_to_top('<style></style>')
        self.assertEqual(len(media.top), 1)
        self.assertEqual(media.top, ['<style></style>'])

        for x in range(0, 5):
            media.add_to_bottom('<script></script>')
        self.assertEqual(len(media.bottom), 1)
        self.assertEqual(media.bottom, ['<script></script>'])
Exemplo n.º 3
0
 def do_render(self, context, results):
     the_media = RegionMedia()
     for datadict in render_all_chunks(context=context,
                                       found_chunks=results,
                                       render_func=render_one_mediagroup):
         if datadict is not None:
             for position, values in datadict.items():
                 for value in values:
                     the_media.add(position, value)
     namespace, sep, attr = self.name.partition('_')
     return getattr(the_media, attr)
Exemplo n.º 4
0
 def test_make(self):
     media = RegionMedia._make([
         ['<style type="text/css"></style>'],  # offset 0 is top
         ['<script></script>']  # offset 1 is bottom
     ])
     self.assertEqual(media.top, ['<style type="text/css"></style>'])
     self.assertEqual(media.bottom, ['<script></script>'])
Exemplo n.º 5
0
 def test_asdict(self):
     media = RegionMedia()
     media.add_to_top('<style></style>')
     media.add_to_bottom('<script></script>')
     self.assertEqual(media._asdict(), {
         'top': ['<style></style>'],
         'bottom': ['<script></script>']
     })
Exemplo n.º 6
0
    def test_getitem(self):
        media = RegionMedia()
        media.add_to_top('<style></style>')
        media.add_to_top('<style type="text/css"></style>')
        media.add_to_top('   <style type="text/css"></style>       ')
        only_top = media['top']
        self.assertEqual(only_top.top, ['<style></style>',
                                        '<style type="text/css"></style>'])

        self.assertEqual(only_top.bottom, [])
        only_bottom = media['bottom']
        self.assertEqual(only_bottom.top, [])
        self.assertEqual(only_bottom.bottom, [])
Exemplo n.º 7
0
 def test_truthiness(self):
     media = RegionMedia()
     media.add_to_top('<style type="text/css"></style>')
     self.assertTrue(media)
     self.assertFalse(RegionMedia())
Exemplo n.º 8
0
 def test_inequality(self):
     media = RegionMedia()
     media.add_to_top('<style type="text/css"></style>')
     media2 = RegionMedia()
     media2.add_to_top(2)
     self.assertNotEqual(media, media2)
Exemplo n.º 9
0
 def test_contains(self):
     media = RegionMedia()
     media.add_to_top('<style type="text/css"></style>')
     self.assertIn('<style type="text/css"></style>', media)
Exemplo n.º 10
0
    def test_magicadd(self):
        media = RegionMedia()
        media.add_to_top('<style type="text/css"></style>')
        media.add_to_top(2)
        media.add_to_bottom(4)
        media.add_to_bottom(3)

        other_media = RegionMedia()
        other_media.add_to_top(6)
        other_media.add_to_bottom(7)

        and_another_media = RegionMedia()
        and_another_media.add_to_top('x')
        and_another_media.add_to_top('x')

        new_media = media + other_media + and_another_media
        self.assertEqual(new_media.top, ['<style type="text/css"></style>',
                                         '2', '6', 'x'])
        self.assertEqual(new_media.bottom, ['4', '3', '7'])
        self.assertEqual(new_media._asdict(), {
            'top': ['<style type="text/css"></style>', '2', '6', 'x'],
            'bottom': ['4', '3', '7']
        })
Exemplo n.º 11
0
 def test_remove(self):
     media = RegionMedia()
     for x in range(0, 5):
         media.add_to_top('<style></style>')
     media.remove_from_top('<style></style>')
     self.assertEqual(len(media.top), 0)