示例#1
0
    def test_render(self, site):
        site.objects = mock.Mock()
        site.objects.get_current = mock.Mock(return_value=self.site)

        size = Size(width=100, height=100)
        size.save()

        slot1 = AdSlot(label='SLOT1', ad_unit='ADUNIT1', site=self.site)
        slot1.save()

        slot2 = AdSlot(label='SLOT2', ad_unit='ADUNIT2', site=self.site)
        slot2.save()

        pos1a = AdPosition(slot=slot1, breakpoint='A')
        pos1a.save()
        pos1a.sizes.add(size)

        pos2a = AdPosition(slot=slot2, breakpoint='A')
        pos2a.save()
        pos2a.sizes.add(size)

        pos2b = AdPosition(slot=slot2, breakpoint='B')
        pos2b.save()
        pos2b.sizes.add(size)

        result = self.block.render(self.context)
        self.assertIn('<script type="text/javascript">', result)
        self.assertIn('</script>', result)

        sizes = [[size.width, size.height]]
        positions = [
            { 'breakpoint': 'A', 'ad_unit_id': slot1.ad_unit_id(), 'sizes': sizes, 'div_id': tags.AdNode.div_id('SLOT1', 'A'), },
            { 'breakpoint': 'A', 'ad_unit_id': slot2.ad_unit_id(), 'sizes': sizes, 'div_id': tags.AdNode.div_id('SLOT2', 'A'), },
            { 'breakpoint': 'B', 'ad_unit_id': slot2.ad_unit_id(), 'sizes': sizes, 'div_id': tags.AdNode.div_id('SLOT2', 'B'), },
        ]

        for pos in positions:
            self.assertIn('Adgeletti.position(\'%s\');' % json.dumps(pos), result)