class ScreenSubscriptionsTestCase(FakePluginTestCase):
    n_elements = 5  # must be >= 3
    plugin_channel_name = "test_channel"
    bundle_channel_name = "test_bundle"
    plugin_name = "test_plugin"
    user_nothing_email = "*****@*****.**"
    user_screen_owner_email = "*****@*****.**"
    user_other_screen_owner_email = "*****@*****.**"
    user_contributor_email = "*****@*****.**"
    user_contributor_of_other_channel_email = "*****@*****.**"
    user_administrator_of_other_channel_email = "*****@*****.**"
    user_channel_admin_email = "*****@*****.**"
    user_administrator_email = "*****@*****.**"
    user_super_administrator_email = "*****@*****.**"

    def run_as(self, users, f):
        """ Runs f as each user in the users list """
        for user in users:
            self.ictv_app.test_user = {"email": user}
            f()

    def setUp(self, fake_plugin_middleware=lambda: None, ictv_middleware=lambda: None):
        super().setUp(fake_plugin_middleware, ictv_middleware)
        building = Building(name="mytestbuilding")
        self.screen = Screen(name="mytestscreen", building=building, secret="secret")
        self.other_screen = Screen(name="myothertestscreen", building=building, secret="secret")
        self.plugins = [Plugin(name="%s%d" % (self.plugin_name, i), activated="yes") for i in
                        range(self.n_elements - 1)]
        self.plugins.append(Plugin.selectBy(name="fake_plugin").getOne())

        self.plugin_channels = [PluginChannel(name="%s%d" % (self.plugin_channel_name, i), plugin=self.plugins[i],
                                              subscription_right="public") for i in range(self.n_elements)]
        self.bundle_channels = [ChannelBundle(name="%s%d" % (self.bundle_channel_name, i), subscription_right="public")
                                for i in range(self.n_elements)]
        other_channel = PluginChannel(name="other_channel", plugin=self.plugins[0], subscription_right="public")
        User(email=self.user_nothing_email, disabled=False)
        User(email=self.user_administrator_email, disabled=False, admin=True)
        User(email=self.user_super_administrator_email, disabled=False, admin=True, super_admin=True)
        screen_owner = User(email=self.user_screen_owner_email, disabled=False)
        self.screen.safe_add_user(screen_owner)
        other_screen_owner = User(email=self.user_other_screen_owner_email, disabled=False)
        self.other_screen.safe_add_user(other_screen_owner)
        contributor = User(email=self.user_contributor_email, disabled=False)
        [plugin_channel.give_permission_to_user(contributor) for plugin_channel in self.plugin_channels]
        contributor_other_channel = User(email=self.user_contributor_of_other_channel_email, disabled=False)
        other_channel.give_permission_to_user(contributor_other_channel)
        administrator_other_channel = User(email=self.user_administrator_of_other_channel_email, disabled=False)
        other_channel.give_permission_to_user(administrator_other_channel, UserPermissions.channel_administrator)
        channel_admin = User(email=self.user_channel_admin_email, disabled=False)
        [plugin_channel.give_permission_to_user(channel_admin, UserPermissions.channel_administrator) for plugin_channel
         in self.plugin_channels]

    def tearDown(self):
        [plugin_channel.destroySelf() for plugin_channel in self.plugin_channels]
        [bundle_channel.destroySelf() for bundle_channel in self.bundle_channels]
        for email in [self.user_nothing_email, self.user_contributor_email, self.user_channel_admin_email,
                      self.user_administrator_email, self.user_super_administrator_email]:
            User.deleteBy(email=email)
        Plugin.deleteBy(name=self.plugin_name)
        super().tearDown()
示例#2
0
    def setUp(self,
              fake_plugin_middleware=lambda: None,
              ictv_middleware=lambda: None):
        super().setUp(fake_plugin_middleware, ictv_middleware)
        building = Building(name="mytestbuilding")
        screen = Screen(name="mytestscreen",
                        building=building,
                        secret="secret")
        self.plugins = [
            Plugin(name="%s%d" % (self.plugin_name, i), activated="yes")
            for i in range(self.n_elements - 1)
        ]
        self.plugins.append(Plugin.selectBy(name="fake_plugin").getOne())

        self.plugin_channels = [
            PluginChannel(name="%s%d" % (self.plugin_channel_name, i),
                          plugin=self.plugins[i],
                          subscription_right="public")
            for i in range(self.n_elements)
        ]
        self.bundle_channels = [
            ChannelBundle(name="%s%d" % (self.bundle_channel_name, i),
                          subscription_right="public")
            for i in range(self.n_elements)
        ]
        other_channel = PluginChannel(name="other_channel",
                                      plugin=self.plugins[0],
                                      subscription_right="public")
        User(email=self.user_nothing_email, disabled=False)
        User(email=self.user_administrator_email, disabled=False, admin=True)
        User(email=self.user_super_administrator_email,
             disabled=False,
             admin=True,
             super_admin=True)
        screen_owner = User(email=self.user_screen_owner_email, disabled=False)
        screen.safe_add_user(screen_owner)
        contributor = User(email=self.user_contributor_email, disabled=False)
        [
            plugin_channel.give_permission_to_user(contributor)
            for plugin_channel in self.plugin_channels
        ]
        contributor_other_channel = User(
            email=self.user_contributor_of_other_channel_email, disabled=False)
        other_channel.give_permission_to_user(contributor_other_channel)
        administrator_other_channel = User(
            email=self.user_administrator_of_other_channel_email,
            disabled=False)
        other_channel.give_permission_to_user(
            administrator_other_channel, UserPermissions.channel_administrator)
        channel_admin = User(email=self.user_channel_admin_email,
                             disabled=False)
        [
            plugin_channel.give_permission_to_user(
                channel_admin, UserPermissions.channel_administrator)
            for plugin_channel in self.plugin_channels
        ]
示例#3
0
class ChannelsPageTestCase(FakePluginTestCase):
    def setUp(self):
        super(ChannelsPageTestCase, self).setUp()
        Channel.deleteMany(None)
        self.fake_plugin = Plugin.byName('fake_plugin')
        self.pc1 = PluginChannel(plugin=self.fake_plugin,
                                 name='PC 1',
                                 subscription_right='public')
        self.pc2 = PluginChannel(plugin=self.fake_plugin,
                                 name='PC 2',
                                 subscription_right='public')
        self.pc3 = PluginChannel(plugin=self.fake_plugin,
                                 name='PC 3',
                                 subscription_right='public')
        self.bundle = ChannelBundle(name='Bundle', subscription_right='public')
        self.building = Building(name='Building')
        self.screen = Screen(name='Screen', building=self.building)
        self.user_nothing = User(email='nothing@localhost', disabled=False)
        self.user_contrib = User(email='contrib@localhost', disabled=False)
        self.pc1.give_permission_to_user(self.user_contrib,
                                         UserPermissions.channel_contributor)
        self.user_chan_admin = User(email='chan_admin@localhost',
                                    disabled=False)
        self.user_chan_admin2 = User(email='chan_admin2@localhost',
                                     disabled=False)
        self.pc1.give_permission_to_user(self.user_chan_admin,
                                         UserPermissions.channel_administrator)
        self.pc2.give_permission_to_user(self.user_chan_admin2,
                                         UserPermissions.channel_administrator)
        self.user_screen_admin = User(email='screen_admin@locahost',
                                      disabled=False)
        self.screen.safe_add_user(self.user_screen_admin)
        self.user_admin = User(email='admin@localhost',
                               disabled=False,
                               admin=True)
        self.user_super_admin = User(email='super_admin@localhost',
                                     disabled=False,
                                     admin=True,
                                     super_admin=True)
        self.users = [
            self.user_nothing, self.user_contrib, self.user_chan_admin,
            self.user_chan_admin2, self.user_screen_admin, self.user_admin,
            self.user_super_admin
        ]
示例#4
0
    def runTest(self):
        """ Tests the User SQLObject """
        user = User(username='******', fullname='fullname', email='email')
        fake_plugin = Plugin(name='fake_plugin', activated='notfound')
        plugin_channel = PluginChannel(plugin=fake_plugin,
                                       name='Channel',
                                       subscription_right='public')
        building = Building(name='building')
        screen = Screen(name='Screen', building=building)
        screen.subscribe_to(user, plugin_channel)

        # Miscellaneous test
        assert user.log_name == 'fullname (%d)' % user.id
        user.fullname = None
        assert user.log_name == 'email (%d)' % user.id
        user.fullname = 'fullname'
        assert user.log_name == 'fullname (%d)' % user.id
        assert user.readable_name == 'fullname'
        user.fullname = None
        assert user.readable_name == 'username'
        user.username = None
        assert user.readable_name == 'email'

        # Test permissions
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_contributor)) == []
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_administrator)) == []

        plugin_channel.give_permission_to_user(
            user, UserPermissions.channel_contributor)
        assert user.highest_permission_level == UserPermissions.channel_contributor
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_contributor)) == [plugin_channel]
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_administrator)) == []

        plugin_channel.give_permission_to_user(
            user, UserPermissions.channel_administrator)
        assert user.highest_permission_level == UserPermissions.channel_administrator
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_contributor)) == []
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_administrator)) == [plugin_channel]

        plugin_channel.remove_permission_to_user(user)
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []

        user.admin = True
        assert user.highest_permission_level == UserPermissions.administrator
        assert list(user.get_subscriptions_of_owned_screens()) == list(
            screen.subscriptions)
        user.admin = False
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []
        user.super_admin = True
        assert user.highest_permission_level == UserPermissions.super_administrator
        assert list(user.get_subscriptions_of_owned_screens()) == list(
            screen.subscriptions)
        user.super_admin = False
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []

        screen.safe_add_user(user)
        assert user.highest_permission_level == UserPermissions.screen_administrator
        assert list(user.get_subscriptions_of_owned_screens()) == list(
            screen.subscriptions)
        screen.removeUser(user)
        assert list(user.get_subscriptions_of_owned_screens()) == []
        assert user.highest_permission_level == UserPermissions.no_permission
示例#5
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