예제 #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)
예제 #2
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>']
     })
예제 #3
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>'])
예제 #4
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']
        })