Beispiel #1
0
    def runTest(self):
        fake_plugin = Plugin.byName('fake_plugin')
        user = User(fullname='User', email='test@localhost')

        assert fake_plugin.channels_number == 0
        pc1 = PluginChannel(plugin=fake_plugin,
                            name='Plugin Channel 1',
                            subscription_right='public')
        assert fake_plugin.channels_number == 1
        pc2 = PluginChannel(plugin=fake_plugin,
                            name='Plugin Channel 2',
                            subscription_right='public')
        assert fake_plugin.channels_number == 2
        pc2.destroySelf()
        assert fake_plugin.channels_number == 1

        pc2 = PluginChannel(plugin=fake_plugin,
                            name='Plugin Channel 2',
                            subscription_right='public')
        pc3 = PluginChannel(plugin=fake_plugin,
                            name='Plugin Channel 3',
                            subscription_right='public')
        bundle_channel = ChannelBundle(name='Bundle',
                                       subscription_right='public')
        bundle_channel.add_channel(pc3)
        building = Building(name='building')
        screen1 = Screen(name='Screen1', building=building)
        screen2 = Screen(name='Screen2', building=building)
        screen3 = Screen(name='Screen3', building=building)

        assert fake_plugin.screens_number == 0
        screen1.subscribe_to(user, pc1)
        assert fake_plugin.screens_number == 1
        screen1.subscribe_to(user, pc2)
        assert fake_plugin.screens_number == 1
        screen2.subscribe_to(user, pc3)
        assert fake_plugin.screens_number == 2
        screen2.subscribe_to(user, bundle_channel)
        assert fake_plugin.screens_number == 2
        screen3.subscribe_to(user, bundle_channel)
        assert fake_plugin.screens_number == 3
Beispiel #2
0
    def runTest(self):
        """ Tests the Screen SQLObject """
        Channel.deleteMany(None)
        Screen.deleteMany(None)
        channel = Channel(name='Channel',
                          subscription_right='public',
                          secret='abcdef')
        plugin_channel = PluginChannel(name='Channel2',
                                       plugin=Plugin.byName('fake_plugin'),
                                       subscription_right='public')
        plugin_channel2 = PluginChannel(name='Channel3',
                                        plugin=Plugin.byName('fake_plugin'),
                                        subscription_right='public')
        bundle_channel = ChannelBundle(name='Channel4',
                                       subscription_right='public')
        bundle_channel.add_channel(plugin_channel2)
        building = Building(name='building')
        screen = Screen(name='Screen', building=building, secret='abcdef')
        screen2 = Screen(name='Screen2', building=building)
        user = User(fullname='User', email='test@localhost')
        user2 = User(fullname='User2', email='test2@localhost')

        # Miscellaneous test
        assert screen.get_view_link() == '/screens/%d/view/abcdef' % screen.id
        assert screen.get_client_link(
        ) == '/screens/%d/client/abcdef' % screen.id
        assert screen.get_macs_string() == ''
        assert screen not in user.screens
        screen.safe_add_user(user)
        assert screen in user.screens
        assert screen not in user2.screens
        screen.removeUser(user)
        assert screen not in user2.screens

        # Test subscription
        assert not screen.is_subscribed_to(channel)
        screen.subscribe_to(user, channel)
        assert screen.is_subscribed_to(channel)
        sub = screen.subscriptions[0]
        screen.subscribe_to(user2, channel, weight=42)
        assert sub.created_by == user2
        assert sub.weight == 42
        assert screen.is_subscribed_to(channel)
        assert list(screen.subscribed_channels) == [channel]
        screen.unsubscribe_from(user2, channel)
        assert not screen.is_subscribed_to(channel)

        # Test macs
        ScreenMac(screen=screen, mac='00b16b00b500')
        ScreenMac(screen=screen, mac='00b16b00b501')
        assert screen.get_macs_string(
        ) == '00:b1:6b:00:b5:00;00:b1:6b:00:b5:01'

        # Test get_visible_screens_of()
        assert list(Screen.get_visible_screens_of(user)) == list(
            Screen.get_visible_screens_of(user2)) == []
        user.admin = True
        assert list(Screen.get_visible_screens_of(user)) == [screen, screen2]
        assert list(Screen.get_visible_screens_of(user2)) == []
        user.admin = False
        user2.super_admin = True
        assert list(Screen.get_visible_screens_of(user2)) == [screen, screen2]
        assert list(Screen.get_visible_screens_of(user)) == []
        user2.super_admin = False
        screen.safe_add_user(user)
        screen2.safe_add_user(user2)
        assert list(Screen.get_visible_screens_of(user)) == [screen]
        assert list(Screen.get_visible_screens_of(user2)) == [screen2]

        # Test channel content
        screen.subscribe_to(user, plugin_channel)
        screen.subscribe_to(user, bundle_channel)
        screen_content = screen.get_channels_content(self.ictv_app)
        assert len(screen_content) == 2
        assert len(screen_content[0].get_slides()) == 1
        assert screen_content[0].get_slides()[0].get_content() == {
            'background-1': {
                'size': 'contain',
                'src': ''
            },
            'title-1': {
                'text': 'Channel2'
            },
            'text-1': {
                'text': ''
            }
        }
        assert len(screen_content[1].get_slides()) == 1
        assert screen_content[1].get_slides()[0].get_content() == {
            'background-1': {
                'size': 'contain',
                'src': ''
            },
            'title-1': {
                'text': 'Channel3'
            },
            'text-1': {
                'text': ''
            }
        }
        screen.shuffle = True
        assert len(screen.get_channels_content(self.ictv_app)) == 2
Beispiel #3
0
    def runTest(self):
        """ Tests the ChannelBundle SQLObject """
        fake_plugin = Plugin.byName('fake_plugin')
        fake_plugin.cache_activated_default = False
        pc1 = PluginChannel(name='Channel1',
                            plugin=fake_plugin,
                            subscription_right='public')
        pc2 = PluginChannel(name='Channel2',
                            plugin=fake_plugin,
                            subscription_right='public')
        pc3 = PluginChannel(name='Channel3',
                            plugin=fake_plugin,
                            subscription_right='public')
        channel_bundle = ChannelBundle(name='Channel Bundle',
                                       subscription_right='public')
        channel_bundle2 = ChannelBundle(name='Channel Bundle 2',
                                        subscription_right='public')
        channel_bundle3 = ChannelBundle(name='Channel Bundle 3',
                                        subscription_right='public')

        # Test basic functionality
        channel_bundle.add_channel(pc1)
        channel_bundle.add_channel(pc1)
        channel_bundle.add_channel(pc2)
        channel_bundle.add_channel(pc2)
        channel_bundle.add_channel(pc3)
        channel_bundle.add_channel(pc3)
        assert list(channel_bundle.flatten()) == [pc1, pc2, pc3]

        channel_bundle.remove_channel(pc2)
        assert list(channel_bundle.flatten()) == [pc1, pc3]

        bundle_content = [
            self.ictv_app.plugin_manager.get_plugin_content(pc)
            for pc in channel_bundle.flatten()
        ]
        channels_content = [
            self.ictv_app.plugin_manager.get_plugin_content(pc1),
            self.ictv_app.plugin_manager.get_plugin_content(pc3)
        ]
        for content1, content2 in zip(bundle_content, channels_content):
            capsule1 = content1[0]
            capsule2 = content2[0]
            assert capsule1 == capsule2

        channel_bundle.remove_channel(pc2)
        channel_bundle.remove_channel(pc3)
        channel_bundle.remove_channel(pc1)
        assert list(channel_bundle.flatten()) == []

        assert channel_bundle.get_type_name() == 'Bundle'

        # Test cycle detection
        channel_bundle.add_channel(channel_bundle2)
        channel_bundle2.add_channel(channel_bundle3)
        with pytest.raises(ValueError):
            channel_bundle3.add_channel(channel_bundle)
        with pytest.raises(ValueError):
            channel_bundle.add_channel(channel_bundle)